Search in sources :

Example 6 with FilterChainProxy

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

the class WebTestUtilsTests method findFilterNoSpringSecurityFilterChainInContext.

@Test
public void findFilterNoSpringSecurityFilterChainInContext() {
    loadConfig(NoSecurityConfig.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())).isEqualTo(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.Test)

Example 7 with FilterChainProxy

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

the class WebSecurity method performBuild.

@Override
protected Filter performBuild() throws Exception {
    Assert.state(!securityFilterChainBuilders.isEmpty(), "At least one SecurityBuilder<? extends SecurityFilterChain> needs to be specified. Typically this done by adding a @Configuration that extends WebSecurityConfigurerAdapter. More advanced users can invoke " + WebSecurity.class.getSimpleName() + ".addSecurityFilterChainBuilder directly");
    int chainSize = ignoredRequests.size() + securityFilterChainBuilders.size();
    List<SecurityFilterChain> securityFilterChains = new ArrayList<SecurityFilterChain>(chainSize);
    for (RequestMatcher ignoredRequest : ignoredRequests) {
        securityFilterChains.add(new DefaultSecurityFilterChain(ignoredRequest));
    }
    for (SecurityBuilder<? extends SecurityFilterChain> securityFilterChainBuilder : securityFilterChainBuilders) {
        securityFilterChains.add(securityFilterChainBuilder.build());
    }
    FilterChainProxy filterChainProxy = new FilterChainProxy(securityFilterChains);
    if (httpFirewall != null) {
        filterChainProxy.setFirewall(httpFirewall);
    }
    filterChainProxy.afterPropertiesSet();
    Filter result = filterChainProxy;
    if (debugEnabled) {
        logger.warn("\n\n" + "********************************************************************\n" + "**********        Security debugging is enabled.       *************\n" + "**********    This may include sensitive information.  *************\n" + "**********      Do not use in a production system!     *************\n" + "********************************************************************\n\n");
        result = new DebugFilter(filterChainProxy);
    }
    postBuildAction.run();
    return result;
}
Also used : DefaultSecurityFilterChain(org.springframework.security.web.DefaultSecurityFilterChain) SecurityFilterChain(org.springframework.security.web.SecurityFilterChain) RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) MvcRequestMatcher(org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher) FilterChainProxy(org.springframework.security.web.FilterChainProxy) EnableWebSecurity(org.springframework.security.config.annotation.web.configuration.EnableWebSecurity) DebugFilter(org.springframework.security.web.debug.DebugFilter) Filter(javax.servlet.Filter) ArrayList(java.util.ArrayList) DefaultSecurityFilterChain(org.springframework.security.web.DefaultSecurityFilterChain) DebugFilter(org.springframework.security.web.debug.DebugFilter)

Example 8 with FilterChainProxy

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

the class FilterChainProxyConfigTests method normalOperationWithNewConfigNonNamespace.

@Test
public void normalOperationWithNewConfigNonNamespace() throws Exception {
    FilterChainProxy filterChainProxy = appCtx.getBean("newFilterChainProxyNonNamespace", FilterChainProxy.class);
    checkPathAndFilterOrder(filterChainProxy);
    doNormalOperation(filterChainProxy);
}
Also used : FilterChainProxy(org.springframework.security.web.FilterChainProxy) Test(org.junit.Test)

Example 9 with FilterChainProxy

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

the class FilterChainProxyConfigTests method normalOperationWithNewConfigRegex.

@Test
public void normalOperationWithNewConfigRegex() throws Exception {
    FilterChainProxy filterChainProxy = appCtx.getBean("newFilterChainProxyRegex", FilterChainProxy.class);
    checkPathAndFilterOrder(filterChainProxy);
    doNormalOperation(filterChainProxy);
}
Also used : FilterChainProxy(org.springframework.security.web.FilterChainProxy) Test(org.junit.Test)

Example 10 with FilterChainProxy

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

the class FilterChainProxyConfigTests method normalOperationWithNewConfig.

@Test
public void normalOperationWithNewConfig() throws Exception {
    FilterChainProxy filterChainProxy = appCtx.getBean("newFilterChainProxy", FilterChainProxy.class);
    checkPathAndFilterOrder(filterChainProxy);
    doNormalOperation(filterChainProxy);
}
Also used : FilterChainProxy(org.springframework.security.web.FilterChainProxy) Test(org.junit.Test)

Aggregations

FilterChainProxy (org.springframework.security.web.FilterChainProxy)14 Test (org.junit.Test)12 DefaultSecurityFilterChain (org.springframework.security.web.DefaultSecurityFilterChain)5 Filter (javax.servlet.Filter)4 MockMvc (org.springframework.test.web.servlet.MockMvc)3 SecurityFilterChain (org.springframework.security.web.SecurityFilterChain)2 CsrfFilter (org.springframework.security.web.csrf.CsrfFilter)2 HttpSessionCsrfTokenRepository (org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository)2 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 MockServletContext (org.springframework.mock.web.MockServletContext)1 EnableWebSecurity (org.springframework.security.config.annotation.web.configuration.EnableWebSecurity)1 AuthenticationEntryPoint (org.springframework.security.web.AuthenticationEntryPoint)1 ExceptionTranslationFilter (org.springframework.security.web.access.ExceptionTranslationFilter)1 FilterSecurityInterceptor (org.springframework.security.web.access.intercept.FilterSecurityInterceptor)1 AnonymousAuthenticationFilter (org.springframework.security.web.authentication.AnonymousAuthenticationFilter)1 LoginUrlAuthenticationEntryPoint (org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint)1 DebugFilter (org.springframework.security.web.debug.DebugFilter)1 MvcRequestMatcher (org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher)1 AnyRequestMatcher (org.springframework.security.web.util.matcher.AnyRequestMatcher)1