AccessDeniedException 如果使用 RoleHierarchyImpl [英] AccessDeniedException if using RoleHierarchyImpl

查看:17
本文介绍了AccessDeniedException 如果使用 RoleHierarchyImpl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Spring Security 中使用角色层次结构.

I am using role hierarchy in Spring Security.

<beans:bean id="roleVoter" class="org.springframework.security.access.vote.RoleHierarchyVoter">
    <beans:constructor-arg ref="roleHierarchy" />
</beans:bean>

<beans:bean id="roleHierarchy"
        class="org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl">
    <beans:property name="hierarchy">
        <beans:value>
            ROLE_USER > ROLE_GUEST
        </beans:value>
    </beans:property>
</beans:bean>

我正在使用保护切入点来保护方法

I am securing methods using protect-pointcut

<global-method-security secured-annotations="enabled" pre-post-annotations="enabled">
  <protect-pointcut expression="execution(* my.package.*(..))"
     access="ROLE_GUEST"/>
</global-method-security>

但是,如果我使用具有 ROLE_USER 权限的用户登录,则会收到 AccessDeniedException.如果我使用 access="ROLE_GUEST,ROLE_USER" 指定保护切入点,我没有问题.

However, I got AccessDeniedException if I login with user that has authority ROLE_USER. I have no issue if I specified protect-pointcut with access="ROLE_GUEST,ROLE_USER".

我是否遗漏了一些步骤?仅供参考,我使用的是 Spring 3.0.5.

Am I missing some steps? FYI, I am using Spring 3.0.5.

谢谢.

推荐答案

查看错误报告 SEC-1163 和下面的评论.

Have a look at bug report SEC-1163 and the comment below.

如果您想要角色层次结构的基本支持,请使用 RoleHierarchyVoter,而不是 RoleVoter.

If you want basic support for role hierarchies, then use a RoleHierarchyVoter, instead of a RoleVoter.

所以你需要一些想法:

<bean id="accessDecisionManager" class="org.springframework.security.access.vote.AffirmativeBased">
    <property name="decisionVoters">
        <list>              
            <ref bean="roleHierarchyVoter" />
            <ref bean="authenticatedVoter" />
            <ref bean="preAdviceVoter" />
            <ref bean="mediaItemReadVoter" />
            <ref bean="mediaItemWriteVoter" />
        </list>
    </property>
</bean>

<bean id="roleVoter" class="org.springframework.security.access.vote.RoleHierarchyVoter">
    <constructor-arg ref="roleHierarchy"/>
</bean>

这篇关于AccessDeniedException 如果使用 RoleHierarchyImpl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆