-
Notifications
You must be signed in to change notification settings - Fork 0
Polish SecurityFilterChain Validation #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 2002-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.security.web; | ||
|
||
import org.springframework.security.core.SpringSecurityCoreVersion; | ||
|
||
/** | ||
* Thrown if {@link SecurityFilterChain securityFilterChain} is not valid. | ||
* | ||
* @author Max Batischev | ||
* @since 6.5 | ||
*/ | ||
public class UnreachableFilterChainException extends IllegalArgumentException { | ||
|
||
private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID; | ||
|
||
private final SecurityFilterChain filterChain; | ||
|
||
private final SecurityFilterChain unreachableFilterChain; | ||
|
||
/** | ||
* Constructs an <code>UnreachableFilterChainException</code> with the specified | ||
* message. | ||
* @param message the detail message | ||
*/ | ||
public UnreachableFilterChainException(String message, SecurityFilterChain filterChain, | ||
SecurityFilterChain unreachableFilterChain) { | ||
super(message); | ||
this.filterChain = filterChain; | ||
this.unreachableFilterChain = unreachableFilterChain; | ||
} | ||
|
||
public SecurityFilterChain getFilterChain() { | ||
return this.filterChain; | ||
} | ||
|
||
public SecurityFilterChain getUnreachableFilterChain() { | ||
return this.unreachableFilterChain; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2002-2023 the original author or authors. | ||
* Copyright 2002-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -18,6 +18,7 @@ | |
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
|
||
|
@@ -81,6 +82,23 @@ public MatchResult matcher(HttpServletRequest request) { | |
return MatchResult.notMatch(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
Comment on lines
+85
to
+86
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: Evaluate equality semantics for OrRequestMatcher. Similar to AndRequestMatcher, the equals implementation here uses an order-sensitive comparison on the requestMatchers list. Confirm that the ordering should affect equality, or consider an alternative approach if order should be ignored. |
||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
OrRequestMatcher that = (OrRequestMatcher) o; | ||
return Objects.equals(this.requestMatchers, that.requestMatchers); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(this.requestMatchers); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Or " + this.requestMatchers; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question (bug_risk): Review order sensitivity in equals/hashCode for AndRequestMatcher.
The equals method compares this.requestMatchers using Objects.equals, which is order-sensitive. Ensure that the ordering of request matchers is significant for equality; otherwise, consider an order-insensitive comparison if the logical contract requires it.