我尝试让角色层次结构在我的应用程序中发挥作用。我唯一想要的是在所有级别定义的层次结构:在 url 级别,现在也在视图级别(在我的 jsp 文件中)。
我使用以下设置:
<beans:bean id="accessDecisionManager" class="org.springframework.security.access.vote.AffirmativeBased">
<beans:property name="decisionVoters">
<beans:list>
<beans:ref bean="roleHierarchyVoter"/>
<beans:bean class="org.springframework.security.web.access.expression.WebExpressionVoter">
<beans:property name="expressionHandler">
<beans:bean class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler">
<beans:property name="roleHierarchy" ref="roleHierarchy"/>
</beans:bean>
</beans:property>
</beans:bean>
<beans:bean class="org.springframework.security.access.vote.AuthenticatedVoter"/>
</beans:list>
</beans:property>
</beans:bean>
<beans:bean id="roleHierarchyVoter" 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_ADMIN > ROLE_OWNER
ROLE_OWNER > ROLE_DISTRIBUTOR
ROLE_DISTRIBUTOR > ROLE_RESELLER
ROLE_RESELLER > ROLE_USER
</beans:value>
</beans:property>
</beans:bean>
<http auto-config="true" use-expressions="true" access-decision-manager-ref="accessDecisionManager">
...
</http>
对于 URL 级别(拦截 URL),它工作得很好,但在我的 jsp 文件中不起作用。问题是我没有正确理解配置以使角色层次结构正常工作。
<security:authorize access="hasRole('ROLE_ADMIN')">
<div class="span4">
<h2>Admin</h2>
</div><!--/span-->
</security:authorize>
<security:authorize access="hasRole('ROLE_OWNER')">
<div class="span4">
<h2>Owner</h2>
</div><!--/span-->
</security:authorize>
<security:authorize access="hasRole('ROLE_DISTRIBUTOR')">
<div class="span4">
<h2>Distributor</h2>
</div><!--/span-->
</security:authorize>
我使用这个简单的示例来测试视图级别的角色层次结构,但它不起作用。只有具有管理员角色的用户才能看到他的块,而其他人则看不到。
有人知道我的配置做错了什么。
我有同样的问题(Spring Security 3.2.5)。
通过声明我的解决方案DefaultWebSecurityExpressionHandler
之前<http>
section
<!-- This must go before the http element in order to be used by security:authorize tags using the access attribute -->
<!-- https://jira.spring.io/browse/SEC-1452 -->
<beans:bean id="webSecurityExpressionHandler" class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler">
<beans:property name="roleHierarchy" ref="roleHierarchy" />
</beans:bean>
see
https://jira.spring.io/browse/SEC-1452 https://jira.spring.io/browse/SEC-1452
and
http://forum.spring.io/forum/spring-projects/security/67494-configuration-of-spring-security-3-0m1-expression-handler-bug/page3 http://forum.spring.io/forum/spring-projects/security/67494-configuration-of-spring-security-3-0m1-expression-handler-bug/page3
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)