-
Notifications
You must be signed in to change notification settings - Fork 6k
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
GrantedAuthorityDefaults does not apply on ExpressionInterceptUrlRegistry#hasRole #4134
Comments
Related with this, the @Bean
public UserDetailsService userDetailsService() {
InMemoryUserDetailsManager userDetailsManager = new InMemoryUserDetailsManager();
userDetailsManager.createUser(
User.withUsername("kazuki43zoo")
.password("password")
.roles("USER") // has been append the ROLE_ prefix
// .authorities("USER")
.build());
return userDetailsManager;
} In this case, we can use the |
I can confirm that it's not working in version 4.2.3. ExpressionUrlAuthorizationConfigurer.hasRole(role)
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
private static String hasRole(String role) {
Assert.notNull(role, "role cannot be null");
if(role.startsWith("ROLE_")) {
throw new IllegalArgumentException("role should not start with 'ROLE_' since it is automatically inserted. Got '" + role + "'");
} else {
return "hasRole('ROLE_" + role + "')";
}
} and same constant string "ROLE_" is on several places in this class. |
Possibly related to this: https://stackoverflow.com/a/46817507/1469525 GrantedAuthorityDefaults will change the prefix for the DefaultWebSecurityExpressionHandler and the DefaultMethodSecurityExpressionHandler, but it doesn't modify the RoleVoter.rolePrefix that is setup from It would be nice if the RoleVoter also could get the rolePrefix from GrantedAuthorityDefaults |
|
Summary
Since 4.2, we can control the default role prefix(default is
ROLE_
) at the single point of definition (gh-3701).However, it not apply to access control definitions using the
ExpressionInterceptUrlRegistry#hasRole()
.Actual Behavior
If login with the
kazuki43zoo
, 403 Forbidden error has been occurred.Expected Behavior
Can access the specified resource after authentication success. (200 OK)
Version
4.2.0
Workaround
It work as following configuration instead of.
The text was updated successfully, but these errors were encountered: