首页 技术 正文
技术 2022年11月19日
0 收藏 473 点赞 3,050 浏览 1588 个字

Shiro提供了一套JSP标签库来实现页面级的授权控制。

在使用Shiro标签库前,首先需要在JSP引入shiro标签:

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

下面介绍Shiro的标签:

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>

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,556
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898