-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Add AuthorizationManagerFactory #17673
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?
Add AuthorizationManagerFactory #17673
Conversation
4ef91a4
to
1de115e
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 updates @sjohnr! I've provided feedback inline.
...n/java/org/springframework/security/access/expression/AbstractSecurityExpressionHandler.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/springframework/security/access/expression/SecurityExpressionRoot.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/springframework/security/access/expression/SecurityExpressionRoot.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/springframework/security/access/expression/SecurityExpressionRoot.java
Outdated
Show resolved
Hide resolved
...main/java/org/springframework/security/authorization/DefaultAuthorizationManagerFactory.java
Outdated
Show resolved
Hide resolved
.../org/springframework/security/messaging/access/expression/MessageSecurityExpressionRoot.java
Outdated
Show resolved
Hide resolved
.../org/springframework/security/messaging/access/expression/MessageSecurityExpressionRoot.java
Outdated
Show resolved
Hide resolved
...gframework/security/messaging/access/expression/DefaultMessageSecurityExpressionHandler.java
Outdated
Show resolved
Hide resolved
.../org/springframework/security/web/access/expression/DefaultWebSecurityExpressionHandler.java
Outdated
Show resolved
Hide resolved
.../org/springframework/security/web/access/expression/DefaultWebSecurityExpressionHandler.java
Outdated
Show resolved
Hide resolved
@rwinch Thanks for the review! Changing the generic type of |
I think that this can work if we update the constructor too. For example: public class MessageSecurityExpressionRoot<T> extends SecurityExpressionRoot {
public final Message<T> message;
public MessageSecurityExpressionRoot(Authentication authentication, Message<T> message) {
...
public MessageSecurityExpressionRoot(Supplier<Authentication> authentication, Message<T> message) {
... Then this will compile: Message<?> message = ...
MessageSecurityExpressionRoot root = new MessageSecurityExpressionRoot<>(authentication, message); |
Signed-off-by: Steve Riesenberg <[email protected]>
1de115e
to
5fb6f37
Compare
@rwinch I've working through the changes and it's looking really good. The only thing I'm noticing is that a few packages are missing nullability defaults.
As it stands now, classes in these packages show as having inconsistent nullability. These show up as IntelliJ inspections for me, similar to our conversation a few weeks ago. I think adding |
.../springframework/security/data/repository/query/SecurityEvaluationContextExtensionTests.java
Show resolved
Hide resolved
...pringframework/security/access/expression/method/DefaultMethodSecurityExpressionHandler.java
Show resolved
Hide resolved
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 is looking great @sjohnr!
I think we are very close 😄 I provided a few minor comments inline.
Now that we are almost done, please also add documentation (using include-code).
After those are addressed, I think we will be ready to merge!
* authentication. | ||
* @return the {@link AuthenticationTrustResolver} | ||
*/ | ||
public AuthenticationTrustResolver getTrustResolver() { |
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.
Rather than exposing a getter here, I'd prefer that DefaultMethodSecurityExpressionHandler
keep a copy of the TrustResolver
and return that.
public class DefaultMethodSecurityExpressionHandler .... {
...
public void setTrustResolver(AuthenticationTrustResolver trustResolver) {
this.trustResolver = trustResolver;
getDefaultMethodSecurityExpressionHandler().setTrustResolver(trustResolver);
}
public AuthenticationTrustResolver getTrustResolver() {
return this.trustResolver;
}
}
The rational is twofold:
-
As we've seen in places like
DefaultMethodSecurityExpressionHandler
, exposing getters unnecessarily makes refactoring more difficult -
The
trustResolver
property is deprecated and so we only need to keep the copy around until it is removed. When we remove it, I don't want to be stuck with a getter onDefaultAuthorizationManagerFactory
that we only created for a deprecated property.
* Returns the {@link RoleHierarchy} used to discover reachable authorities. | ||
* @return the {@link RoleHierarchy} | ||
*/ | ||
public RoleHierarchy getRoleHierarchy() { |
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.
Similar to trustResolver, I'd prefer to remove this getter and keep a copy of RoleHiearchy in the classes that need access to it.
* Returns the prefix used to create an authority name from a role name. | ||
* @return the role prefix | ||
*/ | ||
public String getRolePrefix() { |
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.
Similar to trustResolver
, I'd prefer to remove this getter and keep a copy of rolePrefix
in the classes that need access to it.
.../springframework/security/data/repository/query/SecurityEvaluationContextExtensionTests.java
Show resolved
Hide resolved
@@ -36,6 +36,7 @@ | |||
<suppress files="JoseHeader\.java" checks="SpringMethodVisibility"/> | |||
<suppress files="DefaultLoginPageGeneratingFilterTests\.java" checks="SpringLeadingWhitespace"/> | |||
<suppress files="AuthenticationException\.java" checks="MutableException"/> | |||
<suppress files="FilterInvocationExpressionRoot\.java" checks="SpringMethodVisibility|RedundantModifier"/> |
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.
I think that if you make the constructor for FilterInvocationExpressionRoot
package-private, then you can remove RedundantModifier
.
* @author Steve Riesenberg | ||
* @since 7.0 | ||
*/ | ||
final class FilterInvocationExpressionRoot extends SecurityExpressionRoot<FilterInvocation> { |
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.
I think that this makes more sense to be called HttpServletRequestExpressionRoot
rather than FilterInvocationExpressionRoot
(I know I proposed using FilterInvocationExpressionRoot
, but seeing it shows me that it doesn't make sense - sorry about that!). It would then accept just the HttpServletRequest
instance.
/** | ||
* @author Steve Riesenberg | ||
* @since 7.0 | ||
*/ |
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.
We've only added nullability for crypto and core so feel free to leave as is. We'll get the rest of the module in a different ticket commit. |
This PR is a work in progress. cc: @rwinch