Skip to content

Commit 0e7566e

Browse files
committed
Adjust any-request check
Storing the request matcher outside of the for loop means that if one of the SecurityFilterChain instances is not of type DefaultSecurityFilterChain, then the error may print out an earlier request matcher instead of the current one. Instead, this commit changes to print out the entire filter chain so that it can be inside of the for loop, regardless of type. Issue gh-15220
1 parent 4c780bf commit 0e7566e

File tree

1 file changed

+3
-5
lines changed
  • config/src/main/java/org/springframework/security/config/annotation/web/builders

1 file changed

+3
-5
lines changed

config/src/main/java/org/springframework/security/config/annotation/web/builders/WebSecurity.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -298,16 +298,14 @@ protected Filter performBuild() throws Exception {
298298
.add(getRequestMatcherPrivilegeEvaluatorsEntry(securityFilterChain));
299299
}
300300
boolean anyRequestConfigured = false;
301-
RequestMatcher matcher = null;
302301
for (SecurityBuilder<? extends SecurityFilterChain> securityFilterChainBuilder : this.securityFilterChainBuilders) {
303302
SecurityFilterChain securityFilterChain = securityFilterChainBuilder.build();
304303
Assert.isTrue(!anyRequestConfigured,
305-
"A filter chain that matches any request has already been configured, which means that this filter chain for ["
306-
+ matcher
304+
"A filter chain that matches any request has already been configured, which means that this filter chain ["
305+
+ securityFilterChain
307306
+ "] will never get invoked. Please use `HttpSecurity#securityMatcher` to ensure that there is only one filter chain configured for 'any request' and that the 'any request' filter chain is published last.");
308307
if (securityFilterChain instanceof DefaultSecurityFilterChain defaultSecurityFilterChain) {
309-
matcher = defaultSecurityFilterChain.getRequestMatcher();
310-
if (matcher instanceof AnyRequestMatcher) {
308+
if (defaultSecurityFilterChain.getRequestMatcher() instanceof AnyRequestMatcher) {
311309
anyRequestConfigured = true;
312310
}
313311
}

0 commit comments

Comments
 (0)