spring - Spring Security 从 3.2.7 更新到 4.0.2.RELEASE 如何处理 defaultRolePrefix ="ROLE_"

标签 spring spring-security spring-boot

我的 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/

相关文章:

java - Spring Boot 中 @oneToMany 双向映射的问题

java - 作为没有事务的批处理作业的 Spring Roo 项目

java - 我需要什么配置和库才能在 jsf 项目中使用 spring security taglibs?

java - Eclipse 类未找到异常

java - 使用自定义用户通过数据库进行 Spring Security 身份验证

java - 为什么我们在 spring OAuth 2.0 中将客户端密码作为纯文本存储在数据库中?

java - 获取 MongoCommandException : Command failed with error 18 (AuthenticationFailed): 'Authentication failed.' on server localhost:27017

spring-boot - 为什么弃用@ConfigurationProperties 中的方法位置?

java - 在 Hazelcast 入口监听器中注入(inject) spring bean

java - Spring + hibernate : Initializing database with JUnit doesn't work