Improve Error Message for Conflicting Filter Chains
Closes gh-15874
This commit is contained in:
+8
-6
@@ -302,16 +302,18 @@ public final class WebSecurity extends AbstractConfiguredSecurityBuilder<Filter,
|
||||
requestMatcherPrivilegeEvaluatorsEntries
|
||||
.add(getRequestMatcherPrivilegeEvaluatorsEntry(securityFilterChain));
|
||||
}
|
||||
boolean anyRequestConfigured = false;
|
||||
DefaultSecurityFilterChain anyRequestFilterChain = 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 ["
|
||||
+ 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 (anyRequestFilterChain != null) {
|
||||
String message = "A filter chain that matches any request [" + anyRequestFilterChain
|
||||
+ "] 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.";
|
||||
throw new IllegalArgumentException(message);
|
||||
}
|
||||
if (securityFilterChain instanceof DefaultSecurityFilterChain defaultSecurityFilterChain) {
|
||||
if (defaultSecurityFilterChain.getRequestMatcher() instanceof AnyRequestMatcher) {
|
||||
anyRequestConfigured = true;
|
||||
anyRequestFilterChain = defaultSecurityFilterChain;
|
||||
}
|
||||
}
|
||||
securityFilterChains.add(securityFilterChain);
|
||||
|
||||
Reference in New Issue
Block a user