Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 具有多个角色的Spring安全访问_Java_Spring_Spring Security - Fatal编程技术网

Java 具有多个角色的Spring安全访问

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-

我想为具有以下角色之一(角色1或角色2)的用户定义某些页面的访问权限

我正试图在我的spring security xml文件中对此进行如下配置:

<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')