码迷,mamicode.com
首页 > 其他好文 > 详细

Shiro标签使用实例

时间:2017-11-21 14:23:10      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:r.js   hello   信息   asp   nis   ica   creat   developer   ota   

shiro.xml

/admin/repairType/index = roles["ROLE_ADMIN"]
/admin/user=roles["ROLE_ADMIN"]
/admin/complaint/list= roles["ROLE_SERVICE,ROLE_ADMIN"]
在使用Shiro标签库前,首先需要在JSP引入shiro标签:
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
  • guest标签 :验证当前用户是否为“访客”,即未认证(包含未记住)的用户

    <shiro:guest> 
     
    Hi there!  Please <a href="login.jsp">Login</a> or <a href="signup.jsp">Signup</a> today! 
     
    </shiro:guest>

     

  • user标签 :认证通过或已记住的用户
    <shiro:user> 
     
        Welcome back John!  Not John? Click <a href="login.jsp">here<a> to login. 
     
    </shiro:user>

     

  • authenticated标签 :已认证通过的用户。不包含已记住的用户,这是与user标签的区别所在
    <shiro:authenticated> 
     
        <a href="updateAccount.jsp">Update your contact information</a>. 
     
    </shiro:authenticated>

     

  • notAuthenticated标签 :未认证通过用户,与authenticated标签相对应。与guest标签的区别是,该标签包含已记住用户
    <shiro:notAuthenticated> 
     
        Please <a href="login.jsp">login</a> in order to update your credit card information. 
     
    </shiro:notAuthenticated>

     

  • principal 标签 :输出当前用户信息,通常为登录帐号信息
    Hello, <shiro:principal/>, how are you today?

     

  • hasRole标签 :验证当前用户是否属于该角色
    <shiro:hasRole name="administrator"> 
     
        <a href="admin.jsp">Administer the system</a> 
     
    </shiro:hasRole>

     

  • lacksRole标签 :与hasRole标签逻辑相反,当用户不属于该角色时验证通过
    <shiro:lacksRole name="administrator"> 
     
        Sorry, you are not allowed to administer the system. 
     
    </shiro:lacksRole>

     

  • hasAnyRole标签 :验证当前用户是否属于以下任意一个角色
    <shiro:hasAnyRoles name="developer, project manager, administrator"> 
     
        You are either a developer, project manager, or administrator. 
     
    </shiro:lacksRole>

     

  • hasPermission标签 :验证当前用户是否拥有指定权限
    <shiro:hasPermission name="user:create"> 
     
        <a href="createUser.jsp">Create a new User</a> 
     
    </shiro:hasPermission>

     

  • lacksPermission标签 :与hasPermission标签逻辑相反,当前用户没有制定权限时,验证通过
    <shiro:hasPermission name="user:create"> 
     
        <a href="createUser.jsp">Create a new User</a> 
     
    </shiro:hasPermission>

     

Shiro标签使用实例

标签:r.js   hello   信息   asp   nis   ica   creat   developer   ota   

原文地址:http://www.cnblogs.com/mrelk/p/7872188.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!