-
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
Incomplete documentation regarding Hierarchical roles. #12766
Comments
Thanks for the report, @istoony. In the meantime, to configure @Bean
static RoleHierarchy roleHierarchy() {
RoleHierarchy hierarchy = new RoleHierarchyImpl();
hierarchy.setHierarchy("ROLE_ADMIN > ROLE_STAFF\n" +
"ROLE_STAFF > ROLE_USER\n" +
"ROLE_USER > ROLE_GUEST");
return new RoleHierarchyVoter(hierarchy);
}
@Bean
static DefaultMethodSecurityExpressionHandler methodSecurityExpressionHandler(RoleHierarchy roleHierarchy) {
DefaultMethodSecurityExpressionHandler expressionHandler = new DefaultMethodSecurityExpressionHandler();
expressionHandler.setRoleHierarchy(roleHierarchy);
return expressionHandler;
} And to configure it for filter security, use the AuthorityAuthorizationManager<RequestAuthorizationContext> hasRoleUser =
AuthorityAuthorizationManager.hasRole("USER");
hasRoleUser.setRoleHierarchy(roleHierarchy);
http
.authorizeHttpRequests((authorize) -> authorize
.requestMatchers("/needs/user/**").access(hasRoleUser)
.anyRequest().authenticated()
)
// ... |
@jzheaux Thanks for your contribution! I tried the RoleHierarchy mentioned above, but it seems like there is an issue with it:
Casting the return type to RoleHierarchy produces other issues since they are incompatible. I wonder, how did you manage to make it work? |
On the current 6.0.2 official documentation we have this small sample code related to hierarchical roles:
This code is using deprecated classes and it is not providing any sample that can be used in the current spring version.
The text was updated successfully, but these errors were encountered: