Add test for ordered WebSecurityCustomizers

Issue gh-9154
This commit is contained in:
Eleftheria Stein 2020-11-02 14:19:14 +01:00
parent 25a7482c8c
commit 5c8972b7d5
1 changed files with 33 additions and 0 deletions

View File

@ -326,6 +326,21 @@ public class WebSecurityConfigurationTests {
assertThat(filterChains.get(1).getFilters()).isEmpty();
}
@Test
public void loadConfigWhenCustomizersHaveOrderThenCustomizersOrdered() {
this.spring.register(OrderedCustomizerConfig.class).autowire();
FilterChainProxy filterChainProxy = this.spring.getContext().getBean(FilterChainProxy.class);
List<SecurityFilterChain> filterChains = filterChainProxy.getFilterChains();
assertThat(filterChains).hasSize(3);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "");
request.setServletPath("/ignore1");
assertThat(filterChains.get(0).matches(request)).isTrue();
assertThat(filterChains.get(0).getFilters()).isEmpty();
request.setServletPath("/ignore2");
assertThat(filterChains.get(1).matches(request)).isTrue();
assertThat(filterChains.get(1).getFilters()).isEmpty();
}
@EnableWebSecurity
@Import(AuthenticationTestConfiguration.class)
static class SortedWebSecurityConfigurerAdaptersConfig {
@ -834,4 +849,22 @@ public class WebSecurityConfigurationTests {
}
@EnableWebSecurity
@Import(AuthenticationTestConfiguration.class)
static class OrderedCustomizerConfig {
@Order(1)
@Bean
public WebSecurityCustomizer webSecurityCustomizer1() {
return (web) -> web.ignoring().antMatchers("/ignore1");
}
@Order(2)
@Bean
public WebSecurityCustomizer webSecurityCustomizer2() {
return (web) -> web.ignoring().antMatchers("/ignore2");
}
}
}