我的 Spring Boot 应用程序在 Spring Security 3.2.7.RELEASE
上运行。
现在,我想将其更新为 4.0.2.RELEASE
。
经过数小时的调试,我发现 Spring Security 4.0.2.RELEASE 使用 defaultRolePrefix="ROLE_"
在
org.springframework.security.access.expression.SecurityExpressionRoot.hasAnyAuthorityName(String prefix, String...roles)
方法
在我的应用程序中,我使用不带此前缀的角色,因此我得到 AccessDeniedException
。
如何配置 Spring Boot 以使用 SecurityExpressionRoot.defaultRolePrefix=""
?
最佳答案
我找到了解决方法。我需要将hasRole改为hasAuthority,例如:
@PreAuthorize("hasAuthority('PERMISSION_CREATE_NODE')")
关于spring - Spring Security 从 3.2.7 更新到 4.0.2.RELEASE 如何处理 defaultRolePrefix ="ROLE_",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31996567/