Search in sources :

Example 11 with DefaultSecurityFilterChain

use of org.springframework.security.web.DefaultSecurityFilterChain in project spring-security by spring-projects.

the class NamespaceHttpTests method configureWhenRequestMatcherProvidedThenRequestMatcherUsed.

// http@request-matcher-ref
@Test
public void configureWhenRequestMatcherProvidedThenRequestMatcherUsed() {
    this.spring.register(RequestMatcherRefConfig.class).autowire();
    FilterChainProxy filterChainProxy = this.spring.getContext().getBean(FilterChainProxy.class);
    assertThat(filterChainProxy.getFilterChains().get(0)).isInstanceOf(DefaultSecurityFilterChain.class);
    DefaultSecurityFilterChain securityFilterChain = (DefaultSecurityFilterChain) filterChainProxy.getFilterChains().get(0);
    assertThat(securityFilterChain.getRequestMatcher()).isInstanceOf(RequestMatcherRefConfig.MyRequestMatcher.class);
}
Also used : FilterChainProxy(org.springframework.security.web.FilterChainProxy) DefaultSecurityFilterChain(org.springframework.security.web.DefaultSecurityFilterChain) Test(org.junit.jupiter.api.Test)

Example 12 with DefaultSecurityFilterChain

use of org.springframework.security.web.DefaultSecurityFilterChain in project spring-security by spring-projects.

the class NamespaceHttpTests method configureWhenAntPatternMatchingThenAntPathRequestMatcherUsed.

// http@request-matcher-ref ant
@Test
public void configureWhenAntPatternMatchingThenAntPathRequestMatcherUsed() {
    this.spring.register(RequestMatcherAntConfig.class).autowire();
    FilterChainProxy filterChainProxy = this.spring.getContext().getBean(FilterChainProxy.class);
    assertThat(filterChainProxy.getFilterChains().get(0)).isInstanceOf(DefaultSecurityFilterChain.class);
    DefaultSecurityFilterChain securityFilterChain = (DefaultSecurityFilterChain) filterChainProxy.getFilterChains().get(0);
    assertThat(securityFilterChain.getRequestMatcher()).isInstanceOf(AntPathRequestMatcher.class);
}
Also used : FilterChainProxy(org.springframework.security.web.FilterChainProxy) DefaultSecurityFilterChain(org.springframework.security.web.DefaultSecurityFilterChain) Test(org.junit.jupiter.api.Test)

Example 13 with DefaultSecurityFilterChain

use of org.springframework.security.web.DefaultSecurityFilterChain in project spring-security by spring-projects.

the class NamespaceHttpTests method configureWhenRegexPatternMatchingThenRegexRequestMatcherUsed.

// http@request-matcher-ref regex
@Test
public void configureWhenRegexPatternMatchingThenRegexRequestMatcherUsed() {
    this.spring.register(RequestMatcherRegexConfig.class).autowire();
    FilterChainProxy filterChainProxy = this.spring.getContext().getBean(FilterChainProxy.class);
    assertThat(filterChainProxy.getFilterChains().get(0)).isInstanceOf(DefaultSecurityFilterChain.class);
    DefaultSecurityFilterChain securityFilterChain = (DefaultSecurityFilterChain) filterChainProxy.getFilterChains().get(0);
    assertThat(securityFilterChain.getRequestMatcher()).isInstanceOf(RegexRequestMatcher.class);
}
Also used : FilterChainProxy(org.springframework.security.web.FilterChainProxy) DefaultSecurityFilterChain(org.springframework.security.web.DefaultSecurityFilterChain) Test(org.junit.jupiter.api.Test)

Example 14 with DefaultSecurityFilterChain

use of org.springframework.security.web.DefaultSecurityFilterChain in project spring-security by spring-projects.

the class SecurityMockMvcRequestPostProcessorsJwtTests method setup.

@BeforeEach
public void setup() {
    SecurityContextPersistenceFilter filter = new SecurityContextPersistenceFilter(this.repository);
    MockServletContext servletContext = new MockServletContext();
    servletContext.setAttribute(BeanIds.SPRING_SECURITY_FILTER_CHAIN, new FilterChainProxy(new DefaultSecurityFilterChain(AnyRequestMatcher.INSTANCE, filter)));
    this.request = new MockHttpServletRequest(servletContext);
    WebTestUtils.setSecurityContextRepository(this.request, this.repository);
}
Also used : FilterChainProxy(org.springframework.security.web.FilterChainProxy) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DefaultSecurityFilterChain(org.springframework.security.web.DefaultSecurityFilterChain) MockServletContext(org.springframework.mock.web.MockServletContext) SecurityContextPersistenceFilter(org.springframework.security.web.context.SecurityContextPersistenceFilter) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 15 with DefaultSecurityFilterChain

use of org.springframework.security.web.DefaultSecurityFilterChain in project spring-security by spring-projects.

the class WebTestUtilsTests method findFilterExplicitWithSecurityFilterInContext.

@Test
public void findFilterExplicitWithSecurityFilterInContext() {
    loadConfig(SecurityConfigWithDefaults.class);
    CsrfFilter toFind = new CsrfFilter(new HttpSessionCsrfTokenRepository());
    FilterChainProxy springSecurityFilterChain = new FilterChainProxy(new DefaultSecurityFilterChain(AnyRequestMatcher.INSTANCE, toFind));
    this.request.getServletContext().setAttribute(BeanIds.SPRING_SECURITY_FILTER_CHAIN, springSecurityFilterChain);
    assertThat(WebTestUtils.findFilter(this.request, toFind.getClass())).isSameAs(toFind);
}
Also used : FilterChainProxy(org.springframework.security.web.FilterChainProxy) CsrfFilter(org.springframework.security.web.csrf.CsrfFilter) HttpSessionCsrfTokenRepository(org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository) DefaultSecurityFilterChain(org.springframework.security.web.DefaultSecurityFilterChain) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultSecurityFilterChain (org.springframework.security.web.DefaultSecurityFilterChain)15 FilterChainProxy (org.springframework.security.web.FilterChainProxy)13 Test (org.junit.jupiter.api.Test)9 SecurityFilterChain (org.springframework.security.web.SecurityFilterChain)6 ArrayList (java.util.ArrayList)4 Filter (jakarta.servlet.Filter)3 Bean (org.springframework.context.annotation.Bean)3 CsrfFilter (org.springframework.security.web.csrf.CsrfFilter)3 HttpSessionCsrfTokenRepository (org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository)3 AntPathRequestMatcher (org.springframework.security.web.util.matcher.AntPathRequestMatcher)3 BeforeEach (org.junit.jupiter.api.BeforeEach)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 EnableWebSecurity (org.springframework.security.config.annotation.web.configuration.EnableWebSecurity)2 ExceptionTranslationFilter (org.springframework.security.web.access.ExceptionTranslationFilter)2 FilterSecurityInterceptor (org.springframework.security.web.access.intercept.FilterSecurityInterceptor)2 AnonymousAuthenticationFilter (org.springframework.security.web.authentication.AnonymousAuthenticationFilter)2 UsernamePasswordAuthenticationFilter (org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter)2 AnyRequestMatcher (org.springframework.security.web.util.matcher.AnyRequestMatcher)2 AlertFilterChainProxy (com.synopsys.integration.alert.component.authentication.security.saml.AlertFilterChainProxy)1 ServletException (jakarta.servlet.ServletException)1