mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-23 12:32:13 +00:00
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
This commit is contained in:
parent
4c780bf8d4
commit
0e7566ede3
@ -298,16 +298,14 @@ public final class WebSecurity extends AbstractConfiguredSecurityBuilder<Filter,
|
||||
.add(getRequestMatcherPrivilegeEvaluatorsEntry(securityFilterChain));
|
||||
}
|
||||
boolean anyRequestConfigured = false;
|
||||
RequestMatcher matcher = null;
|
||||
for (SecurityBuilder<? extends SecurityFilterChain> securityFilterChainBuilder : this.securityFilterChainBuilders) {
|
||||
SecurityFilterChain securityFilterChain = securityFilterChainBuilder.build();
|
||||
Assert.isTrue(!anyRequestConfigured,
|
||||
"A filter chain that matches any request has already been configured, which means that this filter chain for ["
|
||||
+ matcher
|
||||
"A filter chain that matches any request has already been configured, which means that this filter chain ["
|
||||
+ securityFilterChain
|
||||
+ "] 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.");
|
||||
if (securityFilterChain instanceof DefaultSecurityFilterChain defaultSecurityFilterChain) {
|
||||
matcher = defaultSecurityFilterChain.getRequestMatcher();
|
||||
if (matcher instanceof AnyRequestMatcher) {
|
||||
if (defaultSecurityFilterChain.getRequestMatcher() instanceof AnyRequestMatcher) {
|
||||
anyRequestConfigured = true;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user