jeudi 19 février 2015

Spring Security Role Hierarchy not working with Thymeleaf sec:authorize

I'm using Spring Security 3.2.5.RELEASE with ThymeLeaf 2.1.4.RELEASE. I've defined Role Hierarchy in my security context. In my view layer I'm using sec:authorize attribute to define menu items. I expect to see all menu items under the top level role but I only see the menus defined under that role. How can I fix this problem so that I see all menus under the top level?


Any pointers would be really appreciated. Thanks.



<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_ADMINISTRATOR > ROLE_MANAGER > ROLE_CONTENT_ADMINISTRATOR
</beans:value>
</beans:property>
</beans:bean>


And in my view page I'm using sec:authorize attribute like below:



<!DOCTYPE html>
<html xmlns="http://ift.tt/lH0Osb"
xmlns:th="http://ift.tt/wfNV60"
xmlns:sec="http://ift.tt/1vQCupq">
<body th:fragment="admin-menu" sec:authorize="hasRole('ROLE_ADMINISTRATOR')">
<li>
<a href="#"><i class="fa fa-users"></i> <span class="nav-label">Users</span> </a>
</li>
</body>
</html>

Aucun commentaire:

Enregistrer un commentaire