How to override defaultRolePrefix when using @Secured or @PreAuthorize in Spring Security

拟墨画扇 提交于 2019-12-11 03:18:46

问题


I am using @Secured("ADMIN"), my role definition is also ADMIN (not ROLE_ADMIN). When I access the API, I am not getting the expected value, it says access denied.

Below is the code, how I have overridden ROLE_ value

@PostMapping("/users")
@Loggable   
@Secured({"Administrator"})
public ResponseEntity<?> createUser( @Valid @RequestBody  User userRequest) {
.....
}

Implemented CustomAccessDecisionManager where the role prefix (setRolePrefix("")) was set to empty and the CustomDecisionManager was configured in my security configuration file.

The empty role prefix is working fine, the code is below for that

.authorizeRequests().anyRequest().authenticated()
        .accessDecisionManager(customAD()).hasRole("ADMIN")

But it's not working when I use @Secured.

My DB contains role as USER1, USER2.

Any help is greatly appreciated. Thank you.

来源:https://stackoverflow.com/questions/46756013/how-to-override-defaultroleprefix-when-using-secured-or-preauthorize-in-spring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!