Search in sources :

Example 1 with TestOAuthAuthenticator

use of es.moki.ratelimij.dropwizard.component.app.auth.TestOAuthAuthenticator in project ratelimitj by mokies.

the class RateLimitApplication method run.

@Override
public void run(Configuration configuration, Environment environment) {
    environment.jersey().register(new LoginResource());
    environment.jersey().register(new UserResource());
    environment.jersey().register(new TrekResource());
    environment.jersey().register(new AuthDynamicFeature(new OAuthCredentialAuthFilter.Builder<PrincipalImpl>().setAuthenticator(new TestOAuthAuthenticator()).setPrefix("Bearer").buildAuthFilter()));
    environment.jersey().register(RolesAllowedDynamicFeature.class);
    environment.jersey().register(new AuthValueFactoryProvider.Binder<>(PrincipalImpl.class));
    // TODO move this cleanup into the tests
    environment.lifecycle().manage(new Managed() {

        @Override
        public void start() {
        }

        @Override
        public void stop() {
            flushRedis();
        }

        private void flushRedis() {
            try (StatefulRedisConnection<String, String> connection = redisClient.connect()) {
                connection.sync().flushdb();
            }
            redisClient.shutdownAsync();
        }
    });
}
Also used : UserResource(es.moki.ratelimij.dropwizard.component.app.api.UserResource) TestOAuthAuthenticator(es.moki.ratelimij.dropwizard.component.app.auth.TestOAuthAuthenticator) AuthValueFactoryProvider(io.dropwizard.auth.AuthValueFactoryProvider) LoginResource(es.moki.ratelimij.dropwizard.component.app.api.LoginResource) TrekResource(es.moki.ratelimij.dropwizard.component.app.api.TrekResource) StatefulRedisConnection(io.lettuce.core.api.StatefulRedisConnection) OAuthCredentialAuthFilter(io.dropwizard.auth.oauth.OAuthCredentialAuthFilter) AuthDynamicFeature(io.dropwizard.auth.AuthDynamicFeature) PrincipalImpl(io.dropwizard.auth.PrincipalImpl) Managed(io.dropwizard.lifecycle.Managed)

Aggregations

LoginResource (es.moki.ratelimij.dropwizard.component.app.api.LoginResource)1 TrekResource (es.moki.ratelimij.dropwizard.component.app.api.TrekResource)1 UserResource (es.moki.ratelimij.dropwizard.component.app.api.UserResource)1 TestOAuthAuthenticator (es.moki.ratelimij.dropwizard.component.app.auth.TestOAuthAuthenticator)1 AuthDynamicFeature (io.dropwizard.auth.AuthDynamicFeature)1 AuthValueFactoryProvider (io.dropwizard.auth.AuthValueFactoryProvider)1 PrincipalImpl (io.dropwizard.auth.PrincipalImpl)1 OAuthCredentialAuthFilter (io.dropwizard.auth.oauth.OAuthCredentialAuthFilter)1 Managed (io.dropwizard.lifecycle.Managed)1 StatefulRedisConnection (io.lettuce.core.api.StatefulRedisConnection)1