shiro權限驗證標籤

實例:html

spring-shiro.xmljava

				/admin/repairType/index = roles["ROLE_ADMIN"]
				/admin/user=roles["ROLE_ADMIN"]
				/admin/complaint/list= roles["ROLE_SERVICE,ROLE_ADMIN"]

jsp頁面:spring

            <shiro:hasRole name="ROLE_ADMIN">
                <li class="user"><a href="${ctx}/admin/user">用戶</a></li>
            </shiro:hasRole>
            <shiro:hasAnyRoles name="ROLE_ADMIN,ROLE_SERVICE">
                <li class="complaint"><a href="${ctx}/admin/complaint/list">服務</a></li>
            </shiro:hasAnyRoles>
            <shiro:hasRole name="ROLE_ADMIN">
                <li class="system"><a href="${ctx}/admin/repairType/index">系統設置</a></li>
            </shiro:hasRole>

  

在使用Shiro標籤庫前,首先須要在JSP引入shiro標籤: apache

<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>

  

一、介紹Shiro的標籤guest標籤 :驗證當前用戶是否爲「訪客」,即未認證(包含未記住)的用戶。jsp

<shiro:guest>  

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

</shiro:guest>

  

二、user標籤 :認證經過或已記住的用戶。spa

<shiro:user>  

    Welcome back John!  Not John? Click <a href="login.jsp">here<a> to login.  

</shiro:user>

  

三、authenticated標籤 :已認證經過的用戶。不包含已記住的用戶,這是與user標籤的區別所在。orm

<shiro:authenticated>  

    <a href="updateAccount.jsp">Update your contact information</a>.  

</shiro:authenticated>

  

四、notAuthenticated標籤 :未認證經過用戶,與authenticated標籤相對應。與guest標籤的區別是,該標籤包含已記住用戶。 xml

<shiro:notAuthenticated>  

    Please <a href="login.jsp">login</a> in order to update your credit card information.  

</shiro:notAuthenticated>

  

五、principal 標籤 :輸出當前用戶信息,一般爲登陸賬號信息。htm

Hello, <shiro:principal/>, how are you today? 

  

六、hasRole標籤 :驗證當前用戶是否屬於該角色。blog

<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>
相關文章
相關標籤/搜索