spring-security 在jsp中的标签库

spring-security 在jsp中的标签库
1.在jsp中声明
[html]  view plain  copy
  1. <%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>  

2.标签
目前共有三个标签
   
[html]  view plain  copy
  1. <sec:authorize></sec:authorize>        
  2. <sec:authentication property=""></sec:authentication>  
  3. <sec:accesscontrollist hasPermission="" domainObject=""></sec:accesscontrollist>  

      
2.1、authorize标签
这个标签用来决定它的内容是否会被执行.
[html]  view plain  copy
  1. <sec:authorize access="hasRole('supervisor')">  
  2.     This content will only be visible to users who have  
  3.     the "supervisor" authority in their list of GrantedAuthoritys.  
  4. </sec:authorize>  



显示一个特定的链接,如果用户允许点击它.
[html]  view plain  copy
  1. <sec:authorize url="/admin">  
  2.     This content will only be visible to users who are authorized to send requests to the "/admin" URL.  
  3. </sec:authorize>  



2.2、authentication标签
这个标签允许访问当前的Authentication 对象, 保存在安全上下文中。
比如,如果Authentication 的principal 属性是Spring Security 的UserDetails 对象的一个实例,
就要使用
[html]  view plain  copy
  1. <sec:authentication property="principal.username" />   

来渲染当前用户的名称。

当然,它不必使用JSP 标签来实现这些功能,一些人更愿意在视图中保持逻辑越少越好。你可以在你的MVC 控制器中访问Authentication 对象( 通过调用
SecurityContextHolder.getContext().getAuthentication()) 然后直接在模型中添加数据,来渲染视图。

2.3、accesscontrollist标签
这个标签纸在使用Spring Security ACL 模块时才可以使用。它检测一个用逗号分隔的特
定领域对象的需要权限列表。如果当前用户拥有这些权限的任何一个,标签内容就会被执行。
否则,就会被略过。
[html]  view plain  copy
  1. <sec:accesscontrollist hasPermission="1,2" domainObject="${someObject}">  
  2.     This will be shown if the user has either of the permissions  
  3.     represented by the values "1" or "2" on the given object.  
  4. </sec:accesscontrollist>  

参考: Spring_Security-3.0.1_中文官方文档(翻译版).pdf
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值