Shiro集成Web时的Shiro JSP标签

场景

从实例入手学习Shiro与Web的整合:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/90140802

在上面已经实现整合Web的基础上实现 Shiro JSP标签的使用。

实现

导入标签库

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

常用标签

1.guest标签

用户没有身份验证时显示相应信息,即游客访问信息。

2.user标签

用户已经身份验证 / 记住我登录后显示相应的信息。

3.principal 标签

显示用户身份信息,默认调用 Subject.getPrincipal() 获取,即 Primary Principal。

4.authenticated 标签

用户已经身份验证通过,即 Subject.login 登录成功,不是记住我登录的。

5.notAuthenticated 标签

用户没有身份验证通过,即没有调用 Subject.login 进行登录,包括记住我自动登录的也属于未进行身份验证。

6.hasRole 标签

如果当前 Subject 有角色将显示 body 体内容。

7.hasAnyRoles 标签

如果当前 Subject 有任意一个角色(或的关系)将显示 body 体内容。

8.lacksRole 标签

如果当前 Subject 没有角色将显示 body 体内容。

9.hasPermission 标签

如果当前 Subject 有权限将显示 body 体内容。

10. lacksPermission 标签

如果当前 Subject 没有权限将显示 body 体内容。

标签使用示例

1.guest标签

<shiro:guest>
欢迎游客访问,<a href="${pageContext.request.contextPath}/login.jsp">登录</a>
</shiro:guest>

2.user标签

<shiro:user>
 <a href="<c:url value="/logout"/>">注销</a>
</shiro:user>

3.principal 标签

登录成功,欢迎你!用户[<shiro:principal/>]

4.authenticated 标签

<shiro:authenticated>
    用户[<shiro:principal/>]已身份验证通过
</shiro:authenticated>

5.notAuthenticated 标签

<shiro:notAuthenticated>
    Please <a href="${pageContext.request.contextPath}/login.jsp">login</a> in order to update your credit card information.
</shiro:notAuthenticated>

6.hasRole 标签

<shiro:hasRole name="admin">
    用户[<shiro:principal/>]拥有角色admin<br/>
</shiro:hasRole>

7.hasAnyRoles 标签

<shiro:hasAnyRoles name="admin,user">
    用户[<shiro:principal/>]拥有角色admin或user<br/>
</shiro:hasAnyRoles>

8.lacksRole 标签

<shiro:lacksRole name="abc">
    用户[<shiro:principal/>]没有角色abc<br/>
</shiro:lacksRole>

9.hasPermission 标签

<shiro:hasPermission name="user:create">
    用户[<shiro:principal/>]拥有权限user:create<br/>
</shiro:hasPermission>

 10. lacksPermission 标签

<shiro:lacksPermission name="org:create">
    用户[<shiro:principal/>]没有权限org:create<br/>
</shiro:lacksPermission>

猜你喜欢

转载自blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/90144553