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());
}
Aggregations