春季安全。不同角色的同一页面的不同视图,可能吗?

Posted

技术标签:

【中文标题】春季安全。不同角色的同一页面的不同视图,可能吗?【英文标题】:Spring Security. Different view for the same page for different roles, possible? 【发布时间】:2012-03-04 03:52:35 【问题描述】:

例如,我们有图书列表页面。

此页面包含书籍列表。

如果用户角色 = “ADMIN”显示在页面按钮“删除图书”或类似“编辑图书”之类的内容上。

如果用户角色 = "SIMPLY_USER" 用户看不到任何按钮,例如“删除..”或“编辑...”。

在快速查看 Spring Security 3 之后 - 我找不到任何适合我的案例的实现。

是真的吗?

【问题讨论】:

【参考方案1】:

你可以在你的jsp中使用spring security taglib来根据用户角色决定显示什么。

<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<sec:authorize access="hasRole('supervisor')">

This content will only be visible to users who have
the "supervisor" authority in their list of <tt>GrantedAuthority</tt>s.

</sec:authorize>

参考:http://static.springsource.org/spring-security/site/docs/3.0.x/reference/taglibs.html

【讨论】:

以上是关于春季安全。不同角色的同一页面的不同视图,可能吗?的主要内容,如果未能解决你的问题,请参考以下文章