Shiro

Shiro-JSP标签库

2020-05-28  本文已影响0人  李白不喜欢杜甫

简介

Apache Shiro提供了Subject-aware JSP / GSP标记库,该库可让您根据当前Subject的状态来控制JSP,JSTL或GSP页面输出。这对于基于查看网页的当前用户的身份和授权状态来个性化视图非常有用。

标签库的配置

标签库描述符(TLD)文件捆绑shiro-web.jar在该META-INF/shiro.tld文件中。要使用任何标记,请将以下行添加到JSP页面顶部(或定义页面指令的任何位置):

<%@ 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>

注意:user标签是的逻辑相反的guest标签

authenticated标签

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

noAuthenticated标签

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

注意:notAuthenticated标签是的逻辑相反的authenticated标签。

principal标签

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

注意:其实就是我们在用户验证成功时创建的一个用户变量,可以是一个字符串也能是一个对象,如果是字符串直接调用就好,如果是对象,调用属性是加入property="属性名即可"。

hasRole标签

<shiro:hasRole name="administrator">
    <a href="admin.jsp">Administer the system</a>
</shiro:hasRole>

lacksRole标签

<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:hasAnyRoles>

hasPermission标签

<shiro:lacksPermission name="user:delete">
    Sorry, you are not allowed to delete user accounts.
</shiro:lacksPermission>
上一篇 下一篇

猜你喜欢

热点阅读