Skip to content

Commit 5c8972b

Browse files
committed
Add test for ordered WebSecurityCustomizers
Issue gh-9154
1 parent 25a7482 commit 5c8972b

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

config/src/test/java/org/springframework/security/config/annotation/web/configuration/WebSecurityConfigurationTests.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,21 @@ public void loadConfigWhenCustomizerAndAdapterConfigureWebSecurityThenBothConfig
326326
assertThat(filterChains.get(1).getFilters()).isEmpty();
327327
}
328328

329+
@Test
330+
public void loadConfigWhenCustomizersHaveOrderThenCustomizersOrdered() {
331+
this.spring.register(OrderedCustomizerConfig.class).autowire();
332+
FilterChainProxy filterChainProxy = this.spring.getContext().getBean(FilterChainProxy.class);
333+
List<SecurityFilterChain> filterChains = filterChainProxy.getFilterChains();
334+
assertThat(filterChains).hasSize(3);
335+
MockHttpServletRequest request = new MockHttpServletRequest("GET", "");
336+
request.setServletPath("/ignore1");
337+
assertThat(filterChains.get(0).matches(request)).isTrue();
338+
assertThat(filterChains.get(0).getFilters()).isEmpty();
339+
request.setServletPath("/ignore2");
340+
assertThat(filterChains.get(1).matches(request)).isTrue();
341+
assertThat(filterChains.get(1).getFilters()).isEmpty();
342+
}
343+
329344
@EnableWebSecurity
330345
@Import(AuthenticationTestConfiguration.class)
331346
static class SortedWebSecurityConfigurerAdaptersConfig {
@@ -834,4 +849,22 @@ public void configure(WebSecurity web) throws Exception {
834849

835850
}
836851

852+
@EnableWebSecurity
853+
@Import(AuthenticationTestConfiguration.class)
854+
static class OrderedCustomizerConfig {
855+
856+
@Order(1)
857+
@Bean
858+
public WebSecurityCustomizer webSecurityCustomizer1() {
859+
return (web) -> web.ignoring().antMatchers("/ignore1");
860+
}
861+
862+
@Order(2)
863+
@Bean
864+
public WebSecurityCustomizer webSecurityCustomizer2() {
865+
return (web) -> web.ignoring().antMatchers("/ignore2");
866+
}
867+
868+
}
869+
837870
}

0 commit comments

Comments
 (0)