Search in sources :

Example 1 with AuthFilterFactoryProvider

use of io.liftwizard.dropwizard.configuration.auth.filter.AuthFilterFactoryProvider 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)

Aggregations

AuthFilter (io.dropwizard.auth.AuthFilter)1 ChainedAuthFilter (io.dropwizard.auth.chained.ChainedAuthFilter)1 AuthFilterFactory (io.liftwizard.dropwizard.configuration.auth.filter.AuthFilterFactory)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