【发布时间】:2014-01-14 06:31:57
【问题描述】:
在我们的应用程序中,我们使用的是 Spring Security,我们观察到如果角色名称没有以 ROLE 为前缀,它就不起作用。
我们的角色是在 DB 中配置的,并且对角色的名称没有限制。
有什么办法可以避免角色的 ROLE 前缀?
【问题讨论】:
在我们的应用程序中,我们使用的是 Spring Security,我们观察到如果角色名称没有以 ROLE 为前缀,它就不起作用。
我们的角色是在 DB 中配置的,并且对角色的名称没有限制。
有什么办法可以避免角色的 ROLE 前缀?
【问题讨论】:
您可以在这里找到解决方案:Spring Security – adding a custom Role Prefix,据此您只需配置RoleVoter:
<beans:bean id="roleVoter" class="org.springframework.security.access.vote.RoleVoter">
<beans:property name="rolePrefix" value="" />
</beans:bean>
另见Spring Security Role Prefix and Custom User Details Service。
【讨论】:
至于我,我没有注意到这种行为。
在我的项目中,我使用 Spring Security 3.1.4.RELEASE 和 Spring 3.2.3.RELEASE。我的 securityContext.xml 包含以下几行:
<security:http auto-config="false" use-expressions="true" access-denied-page="/denied.do"
entry-point-ref="authenticationEntryPoint">
<security:intercept-url pattern="/index.do" access="hasAnyRole('PROJECT_REVIEW', 'PROJECT_ADMINISTRATOR')"/>
<!-- Skipped -->
<security:intercept-url pattern="/**" access="hasAnyRole('PROJECT_REVIEW', 'PROJECT_ADMINISTRATOR')"/>
<!-- Skipped -->
</security:http>
所以,我正在使用我的自定义角色 PROJECT_REVIEW、PROJECT_ADMINISTRATOR。而且效果很好。
你能告诉你得到了什么错误吗?
【讨论】: