-
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
Support RoleHierarchy
Bean in authorizeHttpRequests
Kotlin DSL
#15136
Comments
Hi, @ttasjwi. Thanks for the report. Can you clarify what is inconsistent between the two configurations? |
Hi, To clarify the inconsistencies between the two configurations: When using the traditional DSL configuration, the RoleHierarchy works as expected. However, when using the Kotlin DSL configuration, the RoleHierarchy seems to behave inconsistently. For example, an ADMIN user should be able to access the Here's a summary of the issue I’m encountering:
The only difference between the two setups is the declaration of the securityFilterChain method. All other components, including the Controller, UserDetailsService, and RoleHierarchy bean, remain the same. Here are the two securityFilterChain configurations for comparison: Traditional DSL Configuration@Bean
fun securityFilterChain(http: HttpSecurity): SecurityFilterChain {
http.authorizeHttpRequests {
it
.requestMatchers("/user").hasRole("USER")
.requestMatchers("/admin").hasRole("ADMIN")
.requestMatchers("/db").hasRole("DB")
}
.formLogin(Customizer.withDefaults())
.csrf { it.disable() }
return http.build()
} Kotlin DSL Configurationimport org.springframework.security.config.annotation.web.invoke
@Bean
fun securityFilterChain(http: HttpSecurity): SecurityFilterChain {
http {
authorizeHttpRequests {
authorize("/user", hasRole("USER"))
authorize("/admin", hasRole("ADMIN"))
authorize("/db", hasRole("DB"))
authorize(anyRequest, authenticated)
}
formLogin { }
csrf { disable() }
}
return http.build()
} I would like to know if I am missing something in my Kotlin DSL configuration or if there are additional steps required to properly set up the RoleHierarchy in Kotlin DSL. Thank you for your assistance. |
RoleHierarchy
Bean in authorizeHttpRequests
Kotlin DSL
Hello, Spring Security Team.
I have encountered an issue when configuring security with Kotlin DSL and RoleHierarchy. The behavior seems inconsistent compared to the traditional DSL configuration.
Controller
UserDetailsService
RoleHierarchy Bean
The RoleHierarchy bean is configured as follows:
Traditional DSL Configuration
Using the traditional DSL configuration, RoleHierarchy works as expected:
Kotlin DSL Configuration
However, when using the Kotlin DSL configuration, the RoleHierarchy seems to behave inconsistently:
Environment
The text was updated successfully, but these errors were encountered: