io.dropwizard.auth.CachingAuthenticator Java Examples

The following examples show how to use io.dropwizard.auth.CachingAuthenticator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BreakerboxService.java    From breakerbox with Apache License 2.0 6 votes vote down vote up
private static void setupLdapAuth(LdapConfiguration ldapConfiguration, Environment environment) {
    final LdapAuthenticator ldapAuthenticator = new LdapAuthenticator(ldapConfiguration);
    final CachingAuthenticator<BasicCredentials, User> cachingAuthenticator =
            new CachingAuthenticator<>(
                    environment.metrics(),
                    TenacityAuthenticator.wrap(
                            new ResourceAuthenticator(ldapAuthenticator), BreakerboxDependencyKey.BRKRBX_LDAP_AUTH),
                    ldapConfiguration.getCachePolicy()
            );
    environment.jersey().register(new AuthDynamicFeature(
                    new BasicCredentialAuthFilter.Builder<User>()
                            .setAuthenticator(cachingAuthenticator)
                            .setRealm("breakerbox")
                            .buildAuthFilter()));
    environment.jersey().register(new AuthValueFactoryProvider.Binder<>(User.class));
}
 
Example #2
Source File: ExampleAppTest.java    From dropwizard-auth-ldap with Apache License 2.0 6 votes vote down vote up
@Override
public void run(ExampleAppConfiguration configuration, Environment environment) throws Exception {
    final LdapConfiguration ldapConfiguration = configuration.getLdapConfiguration();

    Authenticator<BasicCredentials, User> ldapAuthenticator = new CachingAuthenticator<>(
            environment.metrics(),
            new ResourceAuthenticator(new LdapAuthenticator(ldapConfiguration)),
            ldapConfiguration.getCachePolicy());

    environment.jersey().register(new AuthDynamicFeature(
            new BasicCredentialAuthFilter.Builder<User>()
                    .setAuthenticator(ldapAuthenticator)
                    .setRealm("LDAP")
                    .buildAuthFilter()));

    environment.jersey().register(new AuthValueFactoryProvider.Binder<>(User.class));

    environment.healthChecks().register("ldap", new LdapHealthCheck<>(
            new ResourceAuthenticator(new LdapCanAuthenticate(ldapConfiguration))));
}
 
Example #3
Source File: ServerApplication.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
private static CachingAuthenticator<String, AuthenticatedUser> buildAuthenticator(
    final MetricRegistry metrics, final Jdbi jdbi) {
  return new CachingAuthenticator<>(
      metrics,
      ApiKeyAuthenticator.build(jdbi),
      CacheBuilder.newBuilder().expireAfterAccess(Duration.ofMinutes(10)).maximumSize(10000));
}
 
Example #4
Source File: PublicApi.java    From pay-publicapi with MIT License 4 votes vote down vote up
@Override
public void run(PublicApiConfig configuration, Environment environment) {
    initialiseSSLSocketFactory();

    final Injector injector = Guice.createInjector(new PublicApiModule(configuration, environment));

    environment.healthChecks().register("ping", new Ping());

    environment.jersey().register(injector.getInstance(HealthCheckResource.class));
    environment.jersey().register(injector.getInstance(PaymentsResource.class));
    environment.jersey().register(injector.getInstance(DirectDebitEventsResource.class));
    environment.jersey().register(injector.getInstance(PaymentRefundsResource.class));
    environment.jersey().register(injector.getInstance(RequestDeniedResource.class));
    environment.jersey().register(injector.getInstance(MandatesResource.class));
    environment.jersey().register(injector.getInstance(SearchRefundsResource.class));
    environment.jersey().register(injector.getInstance(DirectDebitPaymentsResource.class));
    environment.jersey().register(injector.getInstance(TransactionsResource.class));
    environment.jersey().register(injector.getInstance(TelephonePaymentNotificationResource.class));
    environment.jersey().register(new InjectingValidationFeature(injector));
    environment.jersey().register(injector.getInstance(ReturnUrlValidator.class));

    environment.jersey().register(injector.getInstance(RateLimiterFilter.class));
    environment.jersey().register(injector.getInstance(LoggingMDCRequestFilter.class));

    environment.servlets().addFilter("ClearMdcValuesFilter", injector.getInstance(ClearMdcValuesFilter.class))
            .addMappingForUrlPatterns(of(REQUEST), true, "/v1/*");

    environment.servlets().addFilter("AuthorizationValidationFilter", injector.getInstance(AuthorizationValidationFilter.class))
            .addMappingForUrlPatterns(of(REQUEST), true, "/v1/*");

    environment.servlets().addFilter("LoggingFilter", injector.getInstance(LoggingFilter.class))
            .addMappingForUrlPatterns(of(REQUEST), true, "/v1/*");

    /*
       Turn off 'FilteringJacksonJaxbJsonProvider' which overrides dropwizard JacksonMessageBodyProvider.
       Fails on Integration tests if not disabled. 
           - https://github.com/dropwizard/dropwizard/issues/1341
    */
    environment.jersey().property(CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE, Boolean.TRUE);

    CachingAuthenticator<String, Account> cachingAuthenticator = new CachingAuthenticator<>(
            environment.metrics(),
            injector.getInstance(AccountAuthenticator.class),
            configuration.getAuthenticationCachePolicy());

    environment.jersey().register(new AuthDynamicFeature(
            new OAuthCredentialAuthFilter.Builder<Account>()
                    .setAuthenticator(cachingAuthenticator)
                    .setPrefix("Bearer")
                    .buildAuthFilter()));
    environment.jersey().register(new AuthValueFactoryProvider.Binder<>(Account.class));

    attachExceptionMappersTo(environment.jersey());

    initialiseMetrics(configuration, environment);

    //health check removed as redis is not a mandatory dependency
    environment.healthChecks().unregister("redis");
}
 
Example #5
Source File: BasicAuthBuilder.java    From eagle with Apache License 2.0 4 votes vote down vote up
private Authenticator<BasicCredentials, User> cache(Authenticator<BasicCredentials, User> authenticator) {
    return new CachingAuthenticator<>(environment.metrics(), authenticator, CacheBuilderSpec.parse(authConfig.getCachePolicy()));
}