-
Notifications
You must be signed in to change notification settings - Fork 6k
Configure WebInvocationPrivilegeEvaluator for multiple SecurityFilterChain
s
#10575
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
Configure WebInvocationPrivilegeEvaluator for multiple SecurityFilterChain
s
#10575
Conversation
c5a9ba8
to
4e80f70
Compare
4e80f70
to
a9d98e0
Compare
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.
Thank you for the PR. I've provided feedback.
...springframework/security/web/access/AuthorizationManagerWebInvocationPrivilegeEvaluator.java
Show resolved
Hide resolved
|
||
public RequestMatcherPrivilegeEvaluator(Function<HttpServletRequest, Boolean> requestMatcher, | ||
WebInvocationPrivilegeEvaluator privilegeEvaluator) { | ||
Assert.notNull(requestMatcher, "requestMatcher cannot be null"); |
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.
Should we check if privilegeEvaluators is null/empty?
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.
It looks like there is still the need for an empty check on privilegeEvalutators
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.
There will be some scenarios where it makes sense to have an empty list. When using web.ignoring(...)
we have a SecurityFilterChain
with no filters, therefore no WebInvocationPrivilegeEvaluator
s. So, in this scenario we can accept an empty list
...ngframework/security/web/access/RequestMatcherDelegatingWebInvocationPrivilegeEvaluator.java
Outdated
Show resolved
Hide resolved
return null; | ||
} | ||
|
||
public static class DelegatePrivilegeEvaluator { |
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.
The class name does not make it clear that this is a mapping of the RequestMatcher
to WebInvocationPrivilegeEvaluator
s. Perhaps something like, RequestMatcherPrivilegeEvaluatorsEntry
would work better?
*/ | ||
@Override | ||
public boolean isAllowed(String uri, Authentication authentication) { | ||
return isAllowed(null, uri, null, authentication); |
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.
This should not presume that calling isAllowed(null, uri, null, authentication)
is the same as calling this method. Instead, the code should invoke delegate.isAllowed(uri, authentication)
.
...ngframework/security/web/access/RequestMatcherDelegatingWebInvocationPrivilegeEvaluator.java
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
public static final class Builder { |
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.
Perhaps remove this Builder for now since all of the operations are happening on the DelegatePrivilegeEvaluator anyway (i.e. an invalid DelegatePrivilegeEvaluator can be created).
...ngframework/security/web/access/RequestMatcherDelegatingWebInvocationPrivilegeEvaluator.java
Outdated
Show resolved
Hide resolved
} | ||
delegates.add(builder.build()); | ||
} | ||
this.privilegeEvaluator = new RequestMatcherDelegatingWebInvocationPrivilegeEvaluator(delegates); |
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.
instead of initializing privilegeEvaluator it should create an instance and be assigned in getPrivilegeEvaluator. See https://github.com/spring-projects/spring-security/pull/10575/files#diff-2a3768a3ea186b6702859073cc35bc02aa6c8ebf6b20f19a67323f7c20d3bd38R295
return delegate; | ||
} | ||
} | ||
return null; |
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.
Instead of null, change the return type to List<WebInvocationPrivilegeEvaluator>
. If nothing is found return an empty List
.
8ed0f42
to
d8c2076
Compare
Thanks for the review @rwinch. I've updated the PR based on your suggestions. |
|
||
public RequestMatcherPrivilegeEvaluator(Function<HttpServletRequest, Boolean> requestMatcher, | ||
WebInvocationPrivilegeEvaluator privilegeEvaluator) { | ||
Assert.notNull(requestMatcher, "requestMatcher cannot be null"); |
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.
It looks like there is still the need for an empty check on privilegeEvalutators
d8c2076
to
a61811b
Compare
a61811b
to
fd7b58c
Compare
fd7b58c
to
0c167a1
Compare
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.
Thanks for the PR! LGTM
Closes gh-10554, gh-10590