use of org.springframework.security.web.FilterChainProxy 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);
}
use of org.springframework.security.web.FilterChainProxy in project spring-boot by spring-projects.
the class SpringBootWebSecurityConfigurationTests method defaultHeaderConfiguration.
@Test
public void defaultHeaderConfiguration() throws Exception {
this.context = SpringApplication.run(VanillaWebConfiguration.class, "--server.port=0");
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup((WebApplicationContext) this.context).addFilters((FilterChainProxy) this.context.getBean("springSecurityFilterChain", Filter.class)).build();
mockMvc.perform(MockMvcRequestBuilders.get("/")).andExpect(MockMvcResultMatchers.header().string("X-Content-Type-Options", is(notNullValue()))).andExpect(MockMvcResultMatchers.header().string("X-XSS-Protection", is(notNullValue()))).andExpect(MockMvcResultMatchers.header().string("Cache-Control", is(notNullValue()))).andExpect(MockMvcResultMatchers.header().string("X-Frame-Options", is(notNullValue()))).andExpect(MockMvcResultMatchers.header().doesNotExist("Content-Security-Policy"));
}
use of org.springframework.security.web.FilterChainProxy in project spring-boot by spring-projects.
the class SpringBootWebSecurityConfigurationTests method contentSecurityPolicyConfiguration.
@Test
public void contentSecurityPolicyConfiguration() throws Exception {
this.context = SpringApplication.run(VanillaWebConfiguration.class, "--security.headers.content-security-policy=default-src 'self';", "--server.port=0");
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup((WebApplicationContext) this.context).addFilters((FilterChainProxy) this.context.getBean("springSecurityFilterChain", Filter.class)).build();
mockMvc.perform(MockMvcRequestBuilders.get("/")).andExpect(MockMvcResultMatchers.header().string("Content-Security-Policy", is("default-src 'self';"))).andExpect(MockMvcResultMatchers.header().doesNotExist("Content-Security-Policy-Report-Only"));
}
use of org.springframework.security.web.FilterChainProxy in project spring-boot by spring-projects.
the class SpringBootWebSecurityConfigurationTests method contentSecurityPolicyReportOnlyConfiguration.
@Test
public void contentSecurityPolicyReportOnlyConfiguration() throws Exception {
this.context = SpringApplication.run(VanillaWebConfiguration.class, "--security.headers.content-security-policy=default-src 'self';", "--security.headers.content-security-policy-mode=report-only", "--server.port=0");
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup((WebApplicationContext) this.context).addFilters((FilterChainProxy) this.context.getBean("springSecurityFilterChain", Filter.class)).build();
mockMvc.perform(MockMvcRequestBuilders.get("/")).andExpect(MockMvcResultMatchers.header().string("Content-Security-Policy-Report-Only", is("default-src 'self';"))).andExpect(MockMvcResultMatchers.header().doesNotExist("Content-Security-Policy"));
}
Aggregations