Java源码示例:io.dropwizard.logging.DefaultLoggingFactory

示例1
private ComplianceToolModeConfiguration createComplianceToolModeConfiguration() throws IOException {
    String serviceEntityId = UUID.randomUUID().toString();
    KeysAndCert signingKeysAndCert = createKeysAndCert(serviceEntityId);
    KeysAndCert encryptionKeysAndCert = createKeysAndCert(serviceEntityId);

    ComplianceToolModeConfiguration complianceToolModeConfiguration = new ComplianceToolModeConfiguration(serviceEntityId, signingKeysAndCert, encryptionKeysAndCert);

    HttpConnectorFactory httpConnectorFactory = new HttpConnectorFactory();
    httpConnectorFactory.setPort(port);
    httpConnectorFactory.setBindHost(bindHost);
    SimpleServerFactory simpleServerFactory = new SimpleServerFactory();
    simpleServerFactory.setApplicationContextPath("/");
    simpleServerFactory.setConnector(httpConnectorFactory);
    complianceToolModeConfiguration.setServerFactory(simpleServerFactory);
    complianceToolModeConfiguration.setLoggingFactory(new DefaultLoggingFactory());

    return complianceToolModeConfiguration;
}
 
示例2
@Test
public void applicationShouldStartUp() throws Exception {
    environmentHelper.setEnv(new HashMap<String, String>() {{
        put("PORT", "50555");
        put("LOG_LEVEL", "ERROR");
        put("VERIFY_ENVIRONMENT", "COMPLIANCE_TOOL");
        put("SERVICE_ENTITY_IDS", "[\"http://some-service-entity-id\"]");
        put("SAML_SIGNING_KEY", TEST_RP_PRIVATE_SIGNING_KEY);
        put("SAML_PRIMARY_ENCRYPTION_KEY", TEST_RP_PRIVATE_ENCRYPTION_KEY);
        put("SAML_SECONDARY_ENCRYPTION_KEY", TEST_RP_PRIVATE_ENCRYPTION_KEY);
        put("CLOCK_SKEW", "PT30s");
    }});

    application.getTestSupport().before();

    VerifyServiceProviderConfiguration configuration = application.getConfiguration();

    assertThat(application.getLocalPort()).isEqualTo(50555);
    assertThat(((DefaultLoggingFactory) configuration.getLoggingFactory()).getLevel()).isEqualTo("ERROR");
    assertThat(configuration.getHubSsoLocation().toString()).isEqualTo(HubEnvironment.COMPLIANCE_TOOL.getSsoLocation().toString());
    assertThat(configuration.getVerifyHubMetadata().getUri().toString()).isEqualTo(HubEnvironment.COMPLIANCE_TOOL.getMetadataUri().toString());
    assertThat(configuration.getVerifyHubMetadata().getExpectedEntityId()).isEqualTo("https://signin.service.gov.uk");
    assertThat(configuration.getServiceEntityIds()).containsExactly("http://some-service-entity-id");
    assertThat(configuration.getSamlSigningKey().getEncoded()).isEqualTo(decode(TEST_RP_PRIVATE_SIGNING_KEY));
    assertThat(configuration.getSamlPrimaryEncryptionKey().getEncoded()).isEqualTo(decode(TEST_RP_PRIVATE_ENCRYPTION_KEY));
    assertThat(configuration.getSamlSecondaryEncryptionKey().getEncoded()).isEqualTo(decode(TEST_RP_PRIVATE_ENCRYPTION_KEY));
    assertThat(configuration.getClockSkew()).isEqualTo(Duration.standardSeconds(30));
    assertThat(configuration.getEuropeanIdentity().isPresent()).isTrue();
    assertThat(configuration.getEuropeanIdentity().get().getAllAcceptableHubConnectorEntityIds()).containsAll(HubEnvironment.COMPLIANCE_TOOL.getEidasDefaultAcceptableHubConnectorEntityIds());
    assertThat(configuration.getEuropeanIdentity().get().getMetadataSourceUri()).isEqualTo(HubEnvironment.COMPLIANCE_TOOL.getEidasMetadataSourceUri());
    assertThat(configuration.getEuropeanIdentity().get().getTrustAnchorUri()).isEqualTo(HubEnvironment.COMPLIANCE_TOOL.getEidasMetadataTrustAnchorUri());
    assertThat(configuration.getEuropeanIdentity().get().getTrustStore().getCertificate("idaca").toString())
            .isEqualTo(HubEnvironment.COMPLIANCE_TOOL.getMetadataTrustStore().getCertificate("idaca").toString());
    assertThat(configuration.getEuropeanIdentity().get().getTrustStore().getCertificate("idametadata").toString())
            .isEqualTo(HubEnvironment.COMPLIANCE_TOOL.getMetadataTrustStore().getCertificate("idametadata").toString());

}
 
示例3
@Test
public void applicationShouldStartUpWithListOfServiceEntityIds() throws Exception {
    environmentHelper.setEnv(new HashMap<String, String>() {{
        put("PORT", "50555");
        put("LOG_LEVEL", "ERROR");
        put("VERIFY_ENVIRONMENT", "COMPLIANCE_TOOL");
        put("SERVICE_ENTITY_IDS", "[\"http://some-service-entity-id\",\"http://some-other-service-entity-id\"]");
        put("HASHING_ENTITY_ID", "some-hashing-entity-id");
        put("SAML_SIGNING_KEY", TEST_RP_PRIVATE_SIGNING_KEY);
        put("SAML_PRIMARY_ENCRYPTION_KEY", TEST_RP_PRIVATE_ENCRYPTION_KEY);
        put("SAML_SECONDARY_ENCRYPTION_KEY", TEST_RP_PRIVATE_ENCRYPTION_KEY);
        put("CLOCK_SKEW", "PT30s");
    }});

    application.getTestSupport().before();

    VerifyServiceProviderConfiguration configuration = application.getConfiguration();

    assertThat(application.getLocalPort()).isEqualTo(50555);
    assertThat(((DefaultLoggingFactory) configuration.getLoggingFactory()).getLevel()).isEqualTo("ERROR");
    assertThat(configuration.getHubSsoLocation().toString()).isEqualTo(HubEnvironment.COMPLIANCE_TOOL.getSsoLocation().toString());
    assertThat(configuration.getVerifyHubMetadata().getUri().toString()).isEqualTo(HubEnvironment.COMPLIANCE_TOOL.getMetadataUri().toString());
    assertThat(configuration.getVerifyHubMetadata().getExpectedEntityId()).isEqualTo("https://signin.service.gov.uk");
    assertThat(configuration.getServiceEntityIds()).containsExactly("http://some-service-entity-id", "http://some-other-service-entity-id");
    assertThat(configuration.getHashingEntityId()).isEqualTo("some-hashing-entity-id");
    assertThat(configuration.getSamlSigningKey().getEncoded()).isEqualTo(decode(TEST_RP_PRIVATE_SIGNING_KEY));
    assertThat(configuration.getSamlPrimaryEncryptionKey().getEncoded()).isEqualTo(decode(TEST_RP_PRIVATE_ENCRYPTION_KEY));
    assertThat(configuration.getSamlSecondaryEncryptionKey().getEncoded()).isEqualTo(decode(TEST_RP_PRIVATE_ENCRYPTION_KEY));
    assertThat(configuration.getClockSkew()).isEqualTo(Duration.standardSeconds(30));
}
 
示例4
private LoggingReader initLogging(Configuration configuration) throws IOException
{
    Set<File> mainFiles = Sets.newHashSet();
    Set<File> archiveDirectories = Sets.newHashSet();
    LoggingFactory loggingFactory = configuration.getLoggingFactory();
    if ( loggingFactory instanceof DefaultLoggingFactory )
    {
        for ( AppenderFactory appenderFactory : ((DefaultLoggingFactory)loggingFactory).getAppenders() )
        {
            if ( appenderFactory instanceof FileAppenderFactory )
            {
                FileAppenderFactory fileAppenderFactory = (FileAppenderFactory)appenderFactory;
                if ( fileAppenderFactory.getCurrentLogFilename() != null )
                {
                    mainFiles.add(new File(fileAppenderFactory.getCurrentLogFilename()).getCanonicalFile());
                }

                if ( fileAppenderFactory.getArchivedLogFilenamePattern() != null )
                {
                    File archive = new File(fileAppenderFactory.getArchivedLogFilenamePattern()).getParentFile().getCanonicalFile();
                    archiveDirectories.add(archive);
                }
            }
        }
    }

    if ( (mainFiles.size() == 0) && (archiveDirectories.size() == 0) )
    {
        log.warn("No log files found in config");
    }

    return new LoggingReader(mainFiles, archiveDirectories);
}
 
示例5
@Override
@JsonProperty("logging")
@Value.Default
public LoggingFactory getLoggingFactory() {
  return new DefaultLoggingFactory();
}