`
IT_稻草人
  • 浏览: 5242 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
文章分类
社区版块
存档分类
最新评论

shiro

 
阅读更多
spring-shiro.xml

1
2
3
/admin/repairType/index = roles["ROLE_ADMIN"]
/admin/user=roles["ROLE_ADMIN"]
/admin/complaint/list= roles["ROLE_SERVICE,ROLE_ADMIN"]
jsp页面:

1
2
3
4
5
6
7
8
9
<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标签:

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

1、介绍Shiro的标签guest标签 :验证当前用户是否为“访客”,即未认证(包含未记住)的用户。

1
2
3
4
5
<shiro:guest>

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

</shiro:guest>
  

2、user标签 :认证通过或已记住的用户。

1
2
3
4
5
<shiro:user>

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

</shiro:user>
  

3、authenticated标签 :已认证通过的用户。不包含已记住的用户,这是与user标签的区别所在。

1
2
3
4
5
<shiro:authenticated>

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

</shiro:authenticated>
  

4、notAuthenticated标签 :未认证通过用户,与authenticated标签相对应。与guest标签的区别是,该标签包含已记住用户。

1
2
3
4
5
<shiro:notAuthenticated>

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

</shiro:notAuthenticated>
  

5、principal 标签 :输出当前用户信息,通常为登录帐号信息。

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

6、hasRole标签 :验证当前用户是否属于该角色。

1
2
3
4
5
<shiro:hasRole name="administrator">

    <a href="admin.jsp">Administer the system</a>

</shiro:hasRole>
  

7、lacksRole标签 :与hasRole标签逻辑相反,当用户不属于该角色时验证通过。

1
2
3
4
5
<shiro:lacksRole name="administrator">

    Sorry, you are not allowed to administer the system.

</shiro:lacksRole>
  

8、hasAnyRole标签 :验证当前用户是否属于以下任意一个角色。

1
2
3
4
5
<shiro:hasAnyRoles name="developer, project manager, administrator">

    You are either a developer, project manager, or administrator.

</shiro:lacksRole>
  

9、hasPermission标签 :验证当前用户是否拥有指定权限。

1
2
3
4
5
<shiro:hasPermission name="user:create">

    <a href="createUser.jsp">Create a new User</a>

</shiro:hasPermission>
10、lacksPermission标签 :与hasPermission标签逻辑相反,当前用户没有制定权限时,验证通过。

1
2
3
4
5
<shiro:hasPermission name="user:create">

    <a href="createUser.jsp">Create a new User</a>

</shiro:hasPermission>
分享到:
评论

相关推荐

    shiro1.5.3

    Apache Shiro 是一个强大且易用的Java安全框架,提供了认证、授权、加密和会话管理功能,可以非常轻松地开发出足够安全的应用。你提到的 "shiro1.5.3" 是Shiro框架的一个特定版本,包含了该版本的所有核心组件和相关...

    shiro1.6版本

    Apache Shiro 是一个强大且易用的Java安全框架,提供了身份验证、授权、加密和会话管理功能,简化了企业级应用的安全实现。在本文中,我们将深入探讨Apache Shiro 1.6版本的重要更新,以及它如何修复了一个绕过认证...

    shiro1.7.1.zip

    在使用Shiro 1.7.1时,开发者可以根据具体需求选择合适的模块进行集成,例如,Web应用可能会主要依赖`shiro-core`、`shiro-web`和`shiro-spring`,而需要进行复杂加密操作的应用可能需要`shiro-crypto-hash`和`shiro...

    shiro文档以及代码

    Apache Shiro 是一个强大且易用的Java安全框架,提供了认证、授权、加密和会话管理功能,可以非常轻松地开发出足够安全的应用。Shiro 不仅可以用于Web应用,还可以用于任何Java应用,如桌面应用、服务器端应用等。 ...

    shiro demoshiro demoshiro demo

    Apache Shiro 是一个强大且易用的 Java 安全框架,提供身份认证、授权、加密以及会话管理功能,简化了开发者在应用中处理安全问题的过程。标题和描述中的 "shiro demoshiro demoshiro demo" 可能是指一个 Shiro 的...

    shiro源码(shiro-root-1.8.0-source-release.zip)

    Apache Shiro 是一个强大且易用的Java安全框架,提供了认证、授权、加密和会话管理功能,可以非常轻松地开发出足够安全的应用程序。它既适用于传统的Web应用,也适用于现代的Java EE和Android应用。现在我们来深入...

Global site tag (gtag.js) - Google Analytics