Shiro实现授权的三种操作方式
2015-12-23 09:49
423 查看
1. 你可以使用Apache Shiro帮你做:
验证用户来核实他们的身份对用户执行访问控制,如:
判断用户是否被分配了一个确定的安全角色
判断用户是否被允许做某事
在任何环境下使用 Session API,即使没有 Web 或 EJB 容器
在身份验证,访问控制期间或在会话的生命周期,对事件作出反应
聚集一个或多个用户安全数据的数据源,并作为一个单一的复合用户“视图”
启用单点登录(SSO)功能
为没有关联到登录的用户启用”Remember Me”服务
……
2. Shiro实现授权的三种操作方式:
授权就是控制你是否可以访问某个页面,可以操作某个按钮,是否可以编缉对应的数据等。1)使用编程方式,举例如下:
判断是否有管理员角色
if (currentUser.hasRole("admin"))
判断用户是否有打印的权限
Permission printPermission =new PrinterPermission(“laserjet3000n”,“print”); If (currentUser.isPermitted(printPermission)) { //do one thing (show the print button?) } else { //don’t show the button? }
使用字符串的方式验证
String perm = “printer:print:laserjet4400n”; if(currentUser.isPermitted(perm)){ //show the print button? }else { //don’t show the button? }
2)使用注释方式,举例如下:
判断用户是否有 创建账户权限
//Will throw an AuthorizationException if none //of the caller’s roles imply the Account //'create' permission\u000B @RequiresPermissions(“account:create”) public void openAccount( Account acct ) { //create the account }
判断用户角色,如果符合角色,可以使用对应方法
//Throws an AuthorizationException if the caller //doesn’t have the ‘teller’ role: @RequiresRoles( “teller” ) public void openAccount( Account acct ) { //do something in here that only a teller //should do }
3)使用jsp taglib
判断用户是否有管理权限
<%@ taglib prefix=“shiro” uri=http://shiro.apache.org/tags %> <html> <body> <shiro:hasPermission name=“users:manage”> <a href=“manageUsers.jsp”> Click here to manage users </a> </shiro:hasPermission> <shiro:lacksPermission name=“users:manage”> No user managementfor you! </shiro:lacksPermission> </body> </html>
相关文章推荐
- reactjs+ace+shiro+ssm+jpa的web框架的整合
- Shrio的域-————Realm,安全数据的保存地方。
- Shrio的入门例子,从基础教你使用shrio
- Redis-shrio集成
- Shiro教程
- DelegatingFilterProxy管理过滤器详解
- 平台即服务,PAAS,关于shrio中权限过滤的问题
- springmvc+spring+mybatis+shrio+mysql
- SSM整合shrio异常处理
- apache shiro简单整合
- Spring-boot结合Shrio实现JWT的方法
- Apache Shrio安全框架实现原理及实例详解
- Android学习笔记45之gson解析json
- Android开源项目分类汇总
- 手机页面页脚代码
- who命令参数及用法详解(linux查看在线用户命令)
- Ios开发之多线程编程——NSThread
- SublimeText2 快捷键一览表
- 学习笔记 :DrawText
- Struts-Menu角色权限的实例代码