-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
RoleHierarchy is ignored with GlobalMethodSecurityConfiguration and @Secured annotation #9158
Comments
Thanks for the report mkrasuki. Would you be interested in submitting a pull request? If not, could you at least put together a complete minimal example demonstrating the problem? |
I've created demo app here |
It seems when combining @secured with RoleHierarchy injection, the superclass RoleVoter is used during voting process instead of RoleHierarchyVoter, which contains inherited authorities. With @PreAuthorize, the RoleHierarchyVoter.extractAuthorities() is called correctly. The issue is still reproducible in spring security 5.3.6(referred by springboot 2.3.7) |
I believe this is because That said, I think it would be best to see what happens with #9290 before enhancing |
Is this still an open issue? I am having an issue that sounds very similar to this. I have a custom permission evaluator I wrote so that I can make part of the authorization work off of the URI component, I used SPeL for that piece and do this.
That works great, but now I have need on another method to do @secured (or some equivalent) to check for a claim in the JWT. That doesn't seem to work at all and always returns a 403. I confirmed that the role is in the JWT. I have tried a bunch of variations but all of them seem to lead to getting a 403. I tried all of the following.
Any suggestions would be greatly appreciated. I am using SpringBoot 2.7.2 and Java 11. This is my GlobalMethodSecurityConfiguration
|
@howellevans, thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. We prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it). Based on the provided details it doesn't sound related to this issue, which is focused on |
This still seems to be an issue. When using the |
This issue still seems to be present with the new You can work around by defining your own bean.
This seems to fix
|
Same problem here with Spring Boot 3.1.4. I have As fas as I understand, a @jzheaux As this was working with Spring Boot 2.7.x but not with 3.x., I would consider this is a bug. |
I would be able to do a simple fix in org.springframework.security.config.annotation.method.configuration.SecuredMethodSecurityConfiguration by injecting the RoleHierarchy and setting it into the SecuredAuthorizationManager, with some reasonable default behavior. Would a PR be accepeted? |
I just checked open PRs, and this would be resolved with this PR |
Given that |
Describe the bug
Using
@EnableGlobalMethodSecurity(securedEnabled = true)
does not work with injectedRoleHierarchy
For
@Secured
based version of interceptor the only Voters configured inAffirmativeBased
areRoleVoter
andAuthenticatedVoter
. InjectedRoleHierarchy
is only used with Spel and@PreAuthorize
sample DEBUG logs are
The text was updated successfully, but these errors were encountered: