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

Evg*_*rov 12 java spring spring-security

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

我正在尝试在我的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>
Run Code Online (Sandbox Code Playgroud)

我尝试过各种方式:

access="hasRole('ROLE1, ROLE2')"
access="hasRole('ROLE1', 'ROLE2')"
access="hasAnyRole('[ROLE1', 'ROLE2]')"
Run Code Online (Sandbox Code Playgroud)

等等

但似乎没有任何工作.

我一直在异常

java.lang.IllegalArgumentException: Unsupported configuration attributes:
Run Code Online (Sandbox Code Playgroud)

要么

java.lang.IllegalArgumentException: Failed to parse expression 'hasAnyRole(['ROLE1', 'ROLE2'])'
Run Code Online (Sandbox Code Playgroud)

应该如何配置?

谢谢

Wun*_*orn 30

如何尝试,分开.请参阅此处此处的文档.

<security:intercept-url pattern="/rest/api/myUrl*" access="ROLE1,ROLE2"/>
Run Code Online (Sandbox Code Playgroud)

要么

hasAnyRole('ROLE1','ROLE2')
Run Code Online (Sandbox Code Playgroud)


Evg*_*rov -2

问题是我配置了自定义access-decision-manager-ref="accessDecisionManager" ,但没有通过其中一位投票者。

org.springframework.security.web.access.expression.WebExpressionVoter通过添加到accessDecisionManagerbean来解决。