shiro 如何对非url内容授权
2016-02-14 11:54
267 查看
问题描述
应用系统是基于jackrabbit,使用shiro来做授权与认证。在建模时,很多文件操作都建立在 xxx/documents/xxx下。这些文件根据类型对不同角色有不同访问权限,但在url中无法区分。分析
shiro filter 如下图:HttpMethodPermissionFilter类的方法
public boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws IOException { String[] perms = (String[]) mappedValue; // append the http action to the end of the permissions and then back to super String action = getHttpMethodAction(request); String[] resolvedPerms = buildPermissions(perms, action); return super.isAccessAllowed(request, response, resolvedPerms); }
这个函数从shiro.ini中取出permission,并将http method(GET,POST…)翻译成action(read,create…),然后判断是否有权限操作。
方案
可以用建立一个HttpMethodPermissionFilter的子类,将fileType取出来,动态构造Permission,之后可以用jdbcRealm来认证。public boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws IOException { String[] perms = (String[]) mappedValue; // append the http action to the end of the permissions and then back to super String action = getHttpMethodAction(request); String fileType = getFileType(request); String[] resolvedPerms = buildPermissionsByFileType(perms, action,fileType); return super.isAccessAllowed(request, response, resolvedPerms); }
相关文章推荐
- jQuery plugin items filter
- 全国哀悼日网站页面变成灰色的filter方法
- 用css filter做鼠标滑过图片效果
- ASP 使用Filter函数来检索数组的实现代码
- ASP.NET MVC:Filter和Action的执行介绍
- JSP Filter的应用方法
- PHP中实现Bloom Filter算法
- Jquery find与filter函数区别 说明
- Oracle新建用户、角色,授权,建表空间的sql语句
- MySql增加用户、授权、修改密码等语句
- 远程连接mysql 授权方法详解
- 在WIN命令提示符下mysql 用户新建、授权、删除,密码修改
- Apache Shiro 使用手册(一) Shiro架构介绍
- Apache Shiro 使用手册(二) Shiro 认证
- Apache Shiro 使用手册(五) Shiro 配置说明
- Event filter with query SELECT * FROM __InstanceModificationEvent WITHIN
- PHP内置过滤器FILTER使用实例
- Apache Shiro 使用手册(四) Realm 实现
- sqlSQL数据库怎么批量为存储过程/函数授权呢?
- PHP中filter函数校验数据的方法详解