Search in sources :

Example 1 with AuthFilterFactory

use of io.liftwizard.dropwizard.configuration.auth.filter.AuthFilterFactory in project liftwizard by motlin.

the class ImpersonationAuthFilterFactoryTest method impersonationAuthFilter.

@Test
public void impersonationAuthFilter() throws Exception {
    URL resource = Resources.getResource("config-test.json5");
    File json = new File(resource.toURI());
    AuthFilterFactory authFilterFactory = this.factory.build(json);
    assertThat(authFilterFactory, instanceOf(ImpersonationAuthFilterFactory.class));
    AuthFilter<?, ? extends Principal> authFilter = authFilterFactory.createAuthFilter();
    assertThat(authFilter, instanceOf(OAuthCredentialAuthFilter.class));
}
Also used : OAuthCredentialAuthFilter(io.dropwizard.auth.oauth.OAuthCredentialAuthFilter) AuthFilterFactory(io.liftwizard.dropwizard.configuration.auth.filter.AuthFilterFactory) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 2 with AuthFilterFactory

use of io.liftwizard.dropwizard.configuration.auth.filter.AuthFilterFactory in project liftwizard by motlin.

the class AuthFilterBundle method runWithMdc.

@Override
public void runWithMdc(@Nonnull Object configuration, @Nonnull Environment environment) {
    AuthFilterFactoryProvider authFilterFactoryProvider = this.safeCastConfiguration(AuthFilterFactoryProvider.class, configuration);
    List<AuthFilterFactory> authFilterFactories = authFilterFactoryProvider.getAuthFilterFactories();
    List<AuthFilter<?, ? extends Principal>> authFilters = this.getAuthFilters(authFilterFactories);
    if (authFilters.isEmpty()) {
        LOGGER.warn("{} disabled.", this.getClass().getSimpleName());
        return;
    }
    List<String> authFilterNames = authFilters.stream().map(Object::getClass).map(Class::getSimpleName).collect(Collectors.toList());
    LOGGER.info("Running {} with auth filters {}.", this.getClass().getSimpleName(), authFilterNames);
    environment.jersey().register(this.getAuthDynamicFeature(authFilters));
    environment.jersey().register(RolesAllowedDynamicFeature.class);
    environment.jersey().register(new Binder<>(Principal.class));
    Filter clearMDCFilter = this.getClearMDCFilter(authFilterFactories);
    FilterHolder filterHolder = new FilterHolder(clearMDCFilter);
    EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST);
    environment.getApplicationContext().addFilter(filterHolder, "/*", dispatcherTypes);
    LOGGER.info("Completing {}.", this.getClass().getSimpleName());
}
Also used : FilterHolder(org.eclipse.jetty.servlet.FilterHolder) AuthFilterFactory(io.liftwizard.dropwizard.configuration.auth.filter.AuthFilterFactory) AuthFilter(io.dropwizard.auth.AuthFilter) ChainedAuthFilter(io.dropwizard.auth.chained.ChainedAuthFilter) AuthFilterFactoryProvider(io.liftwizard.dropwizard.configuration.auth.filter.AuthFilterFactoryProvider) AuthFilter(io.dropwizard.auth.AuthFilter) ClearMDCKeysFilter(io.liftwizard.servlet.filter.mdc.keys.ClearMDCKeysFilter) Filter(javax.servlet.Filter) ChainedAuthFilter(io.dropwizard.auth.chained.ChainedAuthFilter) DispatcherType(javax.servlet.DispatcherType) Principal(java.security.Principal)

Example 3 with AuthFilterFactory

use of io.liftwizard.dropwizard.configuration.auth.filter.AuthFilterFactory in project liftwizard by motlin.

the class FirebaseAuthFilterFactoryTest method firebaseAuthFilter.

@Test
public void firebaseAuthFilter() throws Exception {
    URL resource = Resources.getResource("config-test.json5");
    File json = new File(resource.toURI());
    AuthFilterFactory authFilterFactory = this.factory.build(json);
    assertThat(authFilterFactory, instanceOf(FirebaseAuthFilterFactory.class));
}
Also used : AuthFilterFactory(io.liftwizard.dropwizard.configuration.auth.filter.AuthFilterFactory) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Aggregations

AuthFilterFactory (io.liftwizard.dropwizard.configuration.auth.filter.AuthFilterFactory)3 File (java.io.File)2 URL (java.net.URL)2 Test (org.junit.Test)2 AuthFilter (io.dropwizard.auth.AuthFilter)1 ChainedAuthFilter (io.dropwizard.auth.chained.ChainedAuthFilter)1 OAuthCredentialAuthFilter (io.dropwizard.auth.oauth.OAuthCredentialAuthFilter)1 AuthFilterFactoryProvider (io.liftwizard.dropwizard.configuration.auth.filter.AuthFilterFactoryProvider)1 ClearMDCKeysFilter (io.liftwizard.servlet.filter.mdc.keys.ClearMDCKeysFilter)1 Principal (java.security.Principal)1 DispatcherType (javax.servlet.DispatcherType)1 Filter (javax.servlet.Filter)1 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)1