assertNotNull("Failed to create certificate", cert);
String fp = CertTools.getFingerprintAsString(cert);
X509Certificate ce = (X509Certificate) certificateStoreSession.findCertificateByFingerprint(admin, fp);
assertNotNull("Cannot find certificate with fp=" + fp, ce);
CertificateInfo info = certificateStoreSession.getCertificateInfo(admin, fp);
// log.info("Got certificate info for cert with fp="+fp);
assertEquals("fingerprint does not match.", fp, info.getFingerprint());
assertEquals("serialnumber does not match.", cert.getSerialNumber(), info.getSerialNumber());
assertEquals("issuerdn does not match.", CertTools.getIssuerDN(cert), info.getIssuerDN());
assertEquals("subjectdn does not match.", CertTools.getSubjectDN(cert), info.getSubjectDN());
// The cert was just stored above with status INACTIVE
assertEquals("status does not match.", SecConst.CERT_ACTIVE, info.getStatus());
long seconds = (cert.getNotAfter().getTime() - new Date().getTime()) / 1000l;
log.debug("ceritificate OK in store, expires in " + seconds + " seconds");
// Create a new UserPasswordExpireService
ServiceConfiguration config = new ServiceConfiguration();
config.setActive(true);
config.setDescription("This is a description");
// No mailsending for this Junit test service
config.setActionClassPath(NoAction.class.getName());
config.setActionProperties(null);
config.setIntervalClassPath(PeriodicalInterval.class.getName());
Properties intervalprop = new Properties();
// Run the service every 3:rd second
intervalprop.setProperty(PeriodicalInterval.PROP_VALUE, "3");
intervalprop.setProperty(PeriodicalInterval.PROP_UNIT, PeriodicalInterval.UNIT_SECONDS);
config.setIntervalProperties(intervalprop);
config.setWorkerClassPath(CertificateExpirationNotifierWorker.class.getName());
Properties workerprop = new Properties();
workerprop.setProperty(EmailSendingWorkerConstants.PROP_SENDTOADMINS, "FALSE");
workerprop.setProperty(EmailSendingWorkerConstants.PROP_SENDTOENDUSERS, "FALSE");
workerprop.setProperty(BaseWorker.PROP_CAIDSTOCHECK, String.valueOf(caid));
workerprop.setProperty(BaseWorker.PROP_TIMEBEFOREEXPIRING, String.valueOf(seconds - 10));
workerprop.setProperty(BaseWorker.PROP_TIMEUNIT, BaseWorker.UNIT_SECONDS);
config.setWorkerProperties(workerprop);
if (serviceSession.getService(admin, CERTIFICATE_EXPIRATION_SERVICE) == null) {
serviceSession.addService(admin, 4711, CERTIFICATE_EXPIRATION_SERVICE, config);
}
serviceSession.activateServiceTimer(admin, CERTIFICATE_EXPIRATION_SERVICE);
// The service will run... the cert should still be active after 5 seconds..
Thread.sleep(5000);
info = certificateStoreSession.getCertificateInfo(admin, fp);
assertEquals("status dotes not match.", SecConst.CERT_ACTIVE, info.getStatus());
// The service will run...We need some tolerance since timers cannot
// be guaranteed to executed at the exact interval.
Thread.sleep(4000);
int tries = 0;
while (info.getStatus() != SecConst.CERT_NOTIFIEDABOUTEXPIRATION && tries<5) {
Thread.sleep(1000);
info = certificateStoreSession.getCertificateInfo(admin, fp);
tries++;
}
info = certificateStoreSession.getCertificateInfo(admin, fp);
assertEquals("Status does not match.", SecConst.CERT_NOTIFIEDABOUTEXPIRATION, info.getStatus());
log.debug("It took >" + (9+tries) + " seconds before the certificate was expired!");
log.trace("<test01CreateNewUser()");
}