Search in sources :

Example 6 with DelegatingFilterProxyRegistrationBean

use of org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean in project spring-boot by spring-projects.

the class SecurityAutoConfigurationTests method defaultFilterDispatcherTypes.

@Test
void defaultFilterDispatcherTypes() {
    this.contextRunner.withConfiguration(AutoConfigurations.of(SecurityFilterAutoConfiguration.class)).run((context) -> {
        DelegatingFilterProxyRegistrationBean bean = context.getBean("securityFilterChainRegistration", DelegatingFilterProxyRegistrationBean.class);
        assertThat(bean).extracting("dispatcherTypes", InstanceOfAssertFactories.iterable(DispatcherType.class)).containsOnly(DispatcherType.ASYNC, DispatcherType.ERROR, DispatcherType.REQUEST);
    });
}
Also used : DelegatingFilterProxyRegistrationBean(org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean) Test(org.junit.jupiter.api.Test)

Example 7 with DelegatingFilterProxyRegistrationBean

use of org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean in project spring-boot by spring-projects.

the class SecurityAutoConfigurationTests method defaultFilterDispatcherTypes.

@Test
public void defaultFilterDispatcherTypes() {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(SecurityAutoConfiguration.class, SecurityFilterAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    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.ASYNC, DispatcherType.ERROR, DispatcherType.REQUEST);
}
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 8 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.getFilter().getOrder());
    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 9 with DelegatingFilterProxyRegistrationBean

use of org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean in project spring-boot by spring-projects.

the class SecurityAutoConfigurationTests method emptyFilterDispatcherTypesDoNotThrowException.

@Test
void emptyFilterDispatcherTypesDoNotThrowException() {
    this.contextRunner.withPropertyValues("spring.security.filter.dispatcher-types:").withConfiguration(AutoConfigurations.of(SecurityFilterAutoConfiguration.class)).run((context) -> {
        DelegatingFilterProxyRegistrationBean bean = context.getBean("securityFilterChainRegistration", DelegatingFilterProxyRegistrationBean.class);
        assertThat(bean).extracting("dispatcherTypes", InstanceOfAssertFactories.iterable(DispatcherType.class)).isEmpty();
    });
}
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