Search in sources :

Example 1 with DelegatingFilterProxyRegistrationBean

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;
}
Also used : DelegatingFilterProxyRegistrationBean(org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) Bean(org.springframework.context.annotation.Bean) DelegatingFilterProxyRegistrationBean(org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean)

Example 2 with DelegatingFilterProxyRegistrationBean

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);
}
Also used : DelegatingFilterProxyRegistrationBean(org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean) EnumSet(java.util.EnumSet) DispatcherType(javax.servlet.DispatcherType) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.Test)

Example 3 with DelegatingFilterProxyRegistrationBean

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;
}
Also used : DelegatingFilterProxyRegistrationBean(org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean) Bean(org.springframework.context.annotation.Bean) DelegatingFilterProxyRegistrationBean(org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean)

Example 4 with DelegatingFilterProxyRegistrationBean

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");
}
Also used : DelegatingFilterProxyRegistrationBean(org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletContext(jakarta.servlet.ServletContext) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) MockFilterChain(org.springframework.mock.web.MockFilterChain) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockFilterConfig(org.springframework.mock.web.MockFilterConfig) Test(org.junit.jupiter.api.Test)

Example 5 with DelegatingFilterProxyRegistrationBean

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);
    });
}
Also used : DelegatingFilterProxyRegistrationBean(org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean) Test(org.junit.jupiter.api.Test)

Aggregations

DelegatingFilterProxyRegistrationBean (org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean)9 Test (org.junit.jupiter.api.Test)4 Bean (org.springframework.context.annotation.Bean)3 EnumSet (java.util.EnumSet)2 DispatcherType (javax.servlet.DispatcherType)2 Test (org.junit.Test)2 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)2 MockServletContext (org.springframework.mock.web.MockServletContext)2 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)2 ServletContext (jakarta.servlet.ServletContext)1 Assertions.assertThatIllegalStateException (org.assertj.core.api.Assertions.assertThatIllegalStateException)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)1 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)1 MockFilterChain (org.springframework.mock.web.MockFilterChain)1 MockFilterConfig (org.springframework.mock.web.MockFilterConfig)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1