Shiro实现授权的三种操作方式
来源:互联网 发布:淘宝使用的第三方平台 编辑:程序博客网 时间:2024/06/06 19:32
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>
0 0
- Shiro实现授权的三种操作方式
- shiro实现授权的三种操作
- Shiro授权的三种方式
- Shiro入门9:Shiro授权流程和三种授权方式和权限标识符规则
- Shiro学习随笔【三】授权方式
- Shiro之授权管理与授权的三种方式(1、编程方式,2、注解方式,3、jsp标签)-yellowcong
- Apache Shiro (三) ---- 授权
- shiro学习:shiro实现授权
- shiro实现基于角色的权限授权
- 将 Shiro 作为应用的权限基础 三:基于注解实现的授权认证过程
- 将 Shiro 作为应用的权限基础 三:基于注解实现的授权认证过程
- Shiro 授权实现
- Apache Shiro 编程方式授权
- Apache Shiro 注解方式授权
- Apache Shiro 标签方式授权
- Apache Shiro 标签方式授权
- Apache Shiro 标签方式授权
- shiro 授权方式及其应用
- java内存管理
- Struts-Menu角色权限的实例代码
- Python资源
- 欢迎使用CSDN-markdown编辑器
- Android开源项目分类汇总
- Shiro实现授权的三种操作方式
- Node.js模块 require和 exports
- 通过ffmpeg把图片转换成视频
- 计算坐标之间的距离
- NSFileManager— NSProcessInfo类的使用
- 毕业了,异地恋只能分手吗?
- 支撑树的插点问题
- 无线网突然提示IP地址冲突,无法连接
- MySQL数据类型和常用字段属性总结