-
Notifications
You must be signed in to change notification settings - Fork 6k
Role Hierarchy in authorizeHttpRequests() of HttpSecurity #13188
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
Comments
Hi, @esselesse, I think what you are looking for is already implemented, the @Bean
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
return http
.authorizeHttpRequests((requests) -> requests
.anyRequest().hasRole("USER")
)
.build();
}
@Bean
RoleHierarchy roleHierarchy() {
RoleHierarchyImpl roleHierarchy = new RoleHierarchyImpl();
roleHierarchy.setHierarchy("ROLE_ADMIN > ROLE_USER");
return roleHierarchy;
} This was added in #12473, so you may need to consider updating Spring Security version in your project. @jzheaux Could you please remind in which release it was included? |
@evgeniycheban if i use these plugins in build.gradle:
(that are latest versions of plugins at this momentum) i assume that maybe something wrong in versions, cuz the problem seems exactly the same as You mentioned (#12473). should i use explicit version of spring security? ------- my problem is below this line, just as example ---------- i do this:
and in filterchain
when i try to access any URL matches ADMIN_URL_PATTERN using a client with ROLE_USER role, i get 403 error (access denied). |
This feature was released in Can you try using Spring Security 6.1.0 and see if this works for you? |
tried out boot 3.1.0. thank You! |
Glad the latest is working for you, @esselesse! I'll close this in favor of #12505, then. |
Expected Behavior
HttpSecurity's
authorizeHttpRequests()
uses role hierarchy defined as a bean or defined as a separate method likesetRoleHierarchy(RoleHierarchy rh) {...}
so the flow will be like
Current Behavior
HttpSecurity's
authorizeHttpRequests()
uses role hierarchy by.access()
method using redefinedAuthorityAuthorizationManager<RequestAuthorizationContext>
. it is quite inconvenient and quite a lot of code.so i need to do
and then use this
Context
i found that
AuthorityAuthorizationManager
has a non-staticRoleHierarchy
field.well, i propose:
RoleHierarchy
field inAuthorizeHttpRequestsConfigurer.AuthorizedUrl
defaulted toNullRoleHierarchy
setRoleHierarchy()
hasRole...
methods under-the-hoodhasRole...
methods ofAuthorityAuthorizationManager
in 3)roleHierarchy
(!)so, we will have an easy setter for roleHierarchy without clumsy use of redefined classes for each custom role
The text was updated successfully, but these errors were encountered: