use of org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean in project spring-boot by spring-projects.
the class SecurityFilterAutoConfiguration method securityFilterChainRegistration.
@Bean
@ConditionalOnBean(name = DEFAULT_FILTER_NAME)
public DelegatingFilterProxyRegistrationBean securityFilterChainRegistration(SecurityProperties securityProperties) {
DelegatingFilterProxyRegistrationBean registration = new DelegatingFilterProxyRegistrationBean(DEFAULT_FILTER_NAME);
registration.setOrder(securityProperties.getFilterOrder());
registration.setDispatcherTypes(getDispatcherTypes(securityProperties));
return registration;
}
use of org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean in project spring-boot by spring-projects.
the class SecurityAutoConfigurationTests method customFilterDispatcherTypes.
@Test
public void customFilterDispatcherTypes() {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(SecurityAutoConfiguration.class, SecurityFilterAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context, "security.filter-dispatcher-types:INCLUDE,ERROR");
this.context.refresh();
DelegatingFilterProxyRegistrationBean bean = this.context.getBean("securityFilterChainRegistration", DelegatingFilterProxyRegistrationBean.class);
@SuppressWarnings("unchecked") EnumSet<DispatcherType> dispatcherTypes = (EnumSet<DispatcherType>) ReflectionTestUtils.getField(bean, "dispatcherTypes");
assertThat(dispatcherTypes).containsOnly(DispatcherType.INCLUDE, DispatcherType.ERROR);
}
use of org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean in project incubator-servicecomb-java-chassis by apache.
the class LoggingFilterConfig method delegatingFilterProxyRegistrationBean.
@Bean
DelegatingFilterProxyRegistrationBean delegatingFilterProxyRegistrationBean() {
DelegatingFilterProxyRegistrationBean bean = new DelegatingFilterProxyRegistrationBean("traceLoggingFilter");
bean.setDispatcherTypes(ASYNC, ERROR, FORWARD, INCLUDE, REQUEST);
bean.setOrder(Ordered.LOWEST_PRECEDENCE);
return bean;
}
use of org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean in project spring-boot by spring-projects.
the class ServletWebServerApplicationContextTests method delegatingFilterProxyRegistrationBeansSkipsTargetBeanNames.
@Test
void delegatingFilterProxyRegistrationBeansSkipsTargetBeanNames() {
addWebServerFactoryBean();
DelegatingFilterProxyRegistrationBean initializer = new DelegatingFilterProxyRegistrationBean("filterBean");
this.context.registerBeanDefinition("initializerBean", beanDefinition(initializer));
BeanDefinition filterBeanDefinition = beanDefinition(new IllegalStateException("Create FilterBean Failure"));
filterBeanDefinition.setLazyInit(true);
this.context.registerBeanDefinition("filterBean", filterBeanDefinition);
this.context.refresh();
ServletContext servletContext = getWebServerFactory().getServletContext();
then(servletContext).should(atMost(1)).addFilter(anyString(), this.filterCaptor.capture());
// Up to this point the filterBean should not have been created, calling
// the delegate proxy will trigger creation and an exception
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> {
this.filterCaptor.getValue().init(new MockFilterConfig());
this.filterCaptor.getValue().doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain());
}).withMessageContaining("Create FilterBean Failure");
}
use of org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean in project spring-boot by spring-projects.
the class SecurityAutoConfigurationTests method customFilterDispatcherTypes.
@Test
void customFilterDispatcherTypes() {
this.contextRunner.withPropertyValues("spring.security.filter.dispatcher-types:INCLUDE,ERROR").withConfiguration(AutoConfigurations.of(SecurityFilterAutoConfiguration.class)).run((context) -> {
DelegatingFilterProxyRegistrationBean bean = context.getBean("securityFilterChainRegistration", DelegatingFilterProxyRegistrationBean.class);
assertThat(bean).extracting("dispatcherTypes", InstanceOfAssertFactories.iterable(DispatcherType.class)).containsOnly(DispatcherType.INCLUDE, DispatcherType.ERROR);
});
}
Aggregations