Java 具有多个角色的Spring安全访问
我想为具有以下角色之一(角色1或角色2)的用户定义某些页面的访问权限 我正试图在我的spring security xml文件中对此进行如下配置:Java 具有多个角色的Spring安全访问,java,spring,spring-security,Java,Spring,Spring Security,我想为具有以下角色之一(角色1或角色2)的用户定义某些页面的访问权限 我正试图在我的spring security xml文件中对此进行如下配置: <security:http entry-point-ref="restAuthenticationEntryPoint" access-decision-manager-ref="accessDecisionManager" xmlns="http://www.springframework.org/schema/security" use-
<security:http entry-point-ref="restAuthenticationEntryPoint" access-decision-manager-ref="accessDecisionManager" xmlns="http://www.springframework.org/schema/security" use-expressions="true">
<!-- skipped configuration -->
<security:intercept-url pattern="/rest/api/myUrl*" access="hasRole('ROLE1') or hasRole('ROLE2')" />
<!-- skipped configuration -->
</security:http>
等
但似乎一切都不起作用
我总是有例外
java.lang.IllegalArgumentException: Unsupported configuration attributes:
或
它应该如何配置
谢谢如何尝试
,
分开。见医生和医生
问题是我配置了自定义
accessDecisionManager ref=“accessDecisionManager”
没有通过一个选民的投票
通过将
org.springframework.security.web.access.expression.WebExpressionVoter
添加到accessDecisionManager
bean来解决此问题。如果您正在使用OAuth2玩它,请确保签出此选项以解决您的问题
我花了很多时间尝试所有的尝试和错误。你把它放进去了吗?是的。它可以在我的配置上看到对不起我的坏。你也试过扮演什么角色吗?太好了!您使用了hasRole()的哪个版本?hasRole('ROLE1','ROLE2')?我现在记不起来了……但其中一个是肯定的)
hasAnyRole
是我需要的。非常感谢。
java.lang.IllegalArgumentException: Unsupported configuration attributes:
java.lang.IllegalArgumentException: Failed to parse expression 'hasAnyRole(['ROLE1', 'ROLE2'])'
<security:intercept-url pattern="/rest/api/myUrl*" access="ROLE1,ROLE2"/>
hasAnyRole('ROLE1','ROLE2')