@Override
 public void fireCheck(ServiceConfiguration config) throws ServiceRegistrationException {
   EventRecord.here(
           ServiceBuilder.class,
           EventType.COMPONENT_SERVICE_CHECK,
           config.getFullName().toString(),
           config.toString())
       .exhaust();
 }
 /** Add a new user and an expire service. Test that the service expires the users password */
 @Test
 public void testExpireCertificateWithCertificateProfiles() throws Exception {
   final String certificateprofilename = "testExpireCertificateWithCertificateProfiles";
   int certificateProfileId =
       certificateProfileSession.addCertificateProfile(
           admin, certificateprofilename, new CertificateProfile());
   try {
     createCertificate(certificateProfileId);
     long seconds = (cert.getNotAfter().getTime() - new Date().getTime()) / 1000l;
     // 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_CERTIFICATE_PROFILE_IDS_TO_CHECK, Integer.toString(certificateProfileId));
     workerprop.setProperty(BaseWorker.PROP_TIMEBEFOREEXPIRING, String.valueOf(seconds - 5));
     workerprop.setProperty(BaseWorker.PROP_TIMEUNIT, BaseWorker.UNIT_SECONDS);
     config.setWorkerProperties(workerprop);
     if (serviceSession.getService(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 2
     // seconds..
     Thread.sleep(2000);
     info = certificateStoreSession.getCertificateInfo(fingerprint);
     assertEquals("status does not match.", CertificateConstants.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(10000);
     int tries = 0;
     while (info.getStatus() != CertificateConstants.CERT_NOTIFIEDABOUTEXPIRATION && tries < 5) {
       Thread.sleep(1000);
       info = certificateStoreSession.getCertificateInfo(fingerprint);
       tries++;
     }
     info = certificateStoreSession.getCertificateInfo(fingerprint);
     assertEquals(
         "Status does not match.",
         CertificateConstants.CERT_NOTIFIEDABOUTEXPIRATION,
         info.getStatus());
   } finally {
     // Clean the certificate profile
     certificateProfileSession.removeCertificateProfile(admin, certificateprofilename);
   }
 }
예제 #3
0
 public static <T extends ServiceConfiguration> T lookupByName(final String name) {
   for (ComponentId c : ComponentIds.list()) {
     ServiceConfiguration example = ServiceBuilders.lookup(c.getClass()).newInstance();
     example.setName(name);
     try {
       return (T) lookup(example);
     } catch (Exception ex) {
     }
   }
   throw new NoSuchElementException(
       "Failed to lookup any registered component with the name: " + name);
 }
예제 #4
0
 @Override
 public ServiceBuilder<? extends ServiceConfiguration> apply(final ServiceConfiguration input) {
   return ServiceBuilders.lookup(input.getComponentId());
 }
예제 #5
0
 @Override
 public boolean apply(final ServiceConfiguration arg0) {
   return Component.State.ENABLED.equals(arg0.lookupState());
 }
  /** Add a new user and an expire service. Test running on all CAs. */
  @Test
  public void testExpireCertificateWithAllCAs() throws Exception {
    try {
      createCertificate();
      long seconds = (cert.getNotAfter().getTime() - new Date().getTime()) / 1000l;
      // 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");
      // Here is the line that matters for this test
      workerprop.setProperty(BaseWorker.PROP_CAIDSTOCHECK, String.valueOf(SecConst.ALLCAS));

      workerprop.setProperty(BaseWorker.PROP_TIMEBEFOREEXPIRING, String.valueOf(seconds - 5));
      workerprop.setProperty(BaseWorker.PROP_TIMEUNIT, BaseWorker.UNIT_SECONDS);
      config.setWorkerProperties(workerprop);
      if (serviceSession.getService(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 2
      // seconds..
      Thread.sleep(2000);
      info = certificateStoreSession.getCertificateInfo(fingerprint);
      assertEquals("status does not match.", CertificateConstants.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(10000);
      int tries = 0;
      while (info.getStatus() != CertificateConstants.CERT_NOTIFIEDABOUTEXPIRATION && tries < 8) {
        Thread.sleep(1000);
        info = certificateStoreSession.getCertificateInfo(fingerprint);
        tries++;
      }
      info = certificateStoreSession.getCertificateInfo(fingerprint);
      assertEquals(
          "Status does not match.",
          CertificateConstants.CERT_NOTIFIEDABOUTEXPIRATION,
          info.getStatus());
    } finally {
      // Restore superadmin CA if it got screwed up.
      List<Certificate> certs = certificateStoreSession.findCertificatesByUsername("superadmin");
      for (Certificate certificate : certs) {
        String superAdminFingerprint = CertTools.getFingerprintAsString(certificate);
        internalCertificateStoreSession.setStatus(
            admin, superAdminFingerprint, CertificateConstants.CERT_ACTIVE);
      }
    }
  }
 @Bean(name = "defaultObjectMapper")
 public ObjectMapper getObjectMapper() {
   ServiceConfiguration sc = new ServiceConfiguration();
   return sc.getObjectMapper();
 }