Shiro权限验证标签

来源:互联网 发布:地下车库层高算法 编辑:程序博客网 时间:2024/05/16 10:16

在使用Shiro标签库前,首先需要在JSP引入shiro标签: 

[html] view plain copy
 print?
  1. <%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>  

1、guest标签 :验证当前用户是否为“访客”,即未认证(包含未记住)的用户。

[html] view plain copy
 print?
  1. <shiro:guest>   
  2.    Hi there!  Please <a href="login.jsp">Login</a> or <a href="signup.jsp">Signup</a> today!   
  3. </shiro:guest>  

2、user标签 :认证通过或已记住的用户。

[html] view plain copy
 print?
  1. <shiro:user>   
  2.     Welcome back John!  Not John? Click <a href="login.jsp">here<a> to login.   
  3. </shiro:user>  

3、authenticated标签 :已认证通过的用户。不包含已记住的用户,这是与user标签的区别所在。

[html] view plain copy
 print?
  1. <shiro:authenticated>   
  2.     <a href="updateAccount.jsp">Update your contact information</a>.   
  3. </shiro:authenticated>  

4、notAuthenticated标签 :未认证通过用户,与authenticated标签相对应。与guest标签的区别是,该标签包含已记住用户。

[html] view plain copy
 print?
  1. <shiro:notAuthenticated>   
  2.     Please <a href="login.jsp">login</a> in order to update your credit card information.   
  3. </shiro:notAuthenticated>  

5、principal 标签 :输出当前用户信息,通常为登录帐号信息。

[html] view plain copy
 print?
  1. Hello, <shiro:principal/>, how are you today?  

6、hasRole标签 :验证当前用户是否属于该角色。

[html] view plain copy
 print?
  1. <shiro:hasRole name="administrator">   
  2.     <a href="admin.jsp">Administer the system</a>   
  3. </shiro:hasRole>  

7、lacksRole标签 :与hasRole标签逻辑相反,当用户不属于该角色时验证通过。

[html] view plain copy
 print?
  1. <shiro:lacksRole name="administrator">   
  2.     Sorry, you are not allowed to administer the system.   
  3. </shiro:lacksRole>  

8、hasAnyRole标签 :验证当前用户是否属于以下任意一个角色。 

[html] view plain copy
 print?
  1. <shiro:hasAnyRoles name="developer, project manager, administrator">   
  2.     You are either a developer, project manager, or administrator.   
  3. </shiro:lacksRole>  

9、hasPermission标签 :验证当前用户是否拥有指定权限。

[html] view plain copy
 print?
  1. <shiro:hasPermission name="user:create">   
  2.     <a href="createUser.jsp">Create a new User</a>   
  3. </shiro:hasPermission>  

10、lacksPermission标签 :与hasPermission标签逻辑相反,当前用户没有制定权限时,验证通过。

[html] view plain copy
 print?
  1. <shiro:hasPermission name="user:create">   
  2.     <a href="createUser.jsp">Create a new User</a>   
  3. </shiro:hasPermission>  

原创粉丝点击