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>
相关文章
相关标签/搜索