shiro 访问鉴权:Realm

AuthorizingRealm->doGetAuthorizationInfo
doGetAuthorizationInfo
protected abstract AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals)
Retrieves the AuthorizationInfo for the given principals from the underlying data store. When returning an instance from this method, you might want to consider using an instance of SimpleAuthorizationInfo, as it is suitable in most cases.
Parameters:
principals - the primary identifying principals of the AuthorizationInfo that should be retrieved.
Returns:
the AuthorizationInfo associated with this principals.
See Also:
SimpleAuthorizationInfo

shiro 需要访问数据库查询权限信息。

结合缓存框架,第一次查询权限信息后缓存,在缓存生存期内,访问鉴权使用缓存中的权限信息。

优点:减少数据库查询,缓存快速获取,提升了每次访问效率,减少了数据库压力。

缺点:涉及权限修改,生效会有一个最大缓存生存周期的间隔期。

解决方法:

每次修改权限后,调用 clearCachedAuthorizationInfo 刷新权限:

clearCachedAuthorizationInfo
protected void clearCachedAuthorizationInfo(PrincipalCollection principals)
Clears out the AuthorizationInfo cache entry for the specified account.
This method is provided as a convenience to subclasses so they can invalidate a cache entry when they change an account's authorization data (add/remove roles or permissions) during runtime. Because an account's AuthorizationInfo can be cached, there needs to be a way to invalidate the cache for only that account so that subsequent authorization operations don't used the (old) cached value if account data changes.

After this method is called, the next authorization check for that same account will result in a call to getAuthorizationInfo, and the resulting return value will be cached before being returned so it can be reused for later authorization checks.

If you wish to clear out all associated cached data (and not just authorization data), use the CachingRealm.clearCache(org.apache.shiro.subject.PrincipalCollection) method instead (which will in turn call this method by default).

Parameters:
principals - the principals of the account for which to clear the cached AuthorizationInfo.

示例项目:https://github.com/windwant/spring-dubbo-service           https://github.com/windwant/spring-boot-service

Shiro 修改权限,刷新权限的更多相关文章

  1. 7. 整合shiro,搭建粗粒度权限管理

    shiro是一个易用的权限管理框架,只需提供一个Realm即可在项目中使用,本文就将结合上一篇中搭建的权限模块.角色模块和用户模块来搭建一个粗粒度的权限管理系统,具体如下:1. 添加shiro依赖和与 ...

  2. 将 Shiro 作为应用的权限基础

    Shiro 是 Java 世界中新近出现的权限框架,较之 JAAS 和 Spring Security,Shiro 在保持强大功能的同时,还在简单性和灵活性方面拥有巨大优势.本文介绍了 Shiro 的 ...

  3. mysql修改数据库表权限

    ps:通常我用的是:1.“grant all on *.* to root@'%' identified by 'yourpassword';”——这个还可以顺带设置密码.2.“flush privi ...

  4. 使用Mongodb+Shiro+SpringMVC实现动态权限分配

    此次的文档只对Mongodb整合Shiro并且实现动态权限分配做整理,其它的内容以后会补上. 第一步.创建在web.xml中配置 Spring .Shiro shiroFilter 过滤器是用来将请求 ...

  5. JAVAEE——BOS物流项目11:在realm中授权、shiro的方法注解权限控制、shiro的标签权限控制、总结shiro的权限控制方式、权限管理

    1 学习计划 1.在realm中进行授权 2.使用shiro的方法注解方式权限控制 n 在spring文件中配置开启shiro注解支持 n 在Action方法上使用注解 3.★使用shiro的标签进行 ...

  6. 修改linux文件权限

    Linux系统中的每个文件和目录都有访问许可权限,用它来确定谁可以通过何种方式对文件和目录进行访问和操作. 文件或目录的访问权限分为只读,只写和可执行三种.以文件为例,只读权限表示只允许读其内容,而禁 ...

  7. 60-chmod 修改文件的权限

    修改文件的权限 chmod [options] who operator permission file-list (符号模式) chmod [options] mode file-list (绝对模 ...

  8. chmod修改文件的权限/chown修改文件和目录的所有者

    ll指令的显示的信息为(当前目录下只有nameservice1一个目录): drwxr-xr-x 3 hdfs hdfs 4096 4月 14 16:19 nameservice1 上述信息分别表示: ...

  9. linux 修改目录文件权限,目录文件所属用户,用户组

    1:查看命令:ll drwxr-xr-x  4 gamer ftp      4096 Mar  7 16:56 gstore drwxrwxrwx 10 root  ftp      4096 De ...

随机推荐

  1. HTTPweb服务器——HTTP基本知识

    对于HTTP来说,我们不需要说太多,HTTP又叫做超文本传输协议,现如今利用最多的版本是1.1版本. HTTP的特点:C/S模式,B/S模式 简单快速:基于请求和响应,请求只需要传送请求方法和路径.  ...

  2. Ajax缓存

    一.Ajax缓存的好处 这种设计使客户端对一些静态页面内容的请求,比如图片,css文件,js脚本等,变得更加快捷,提高了页面的响应速度,也节省了网络通信资源. 二.Ajax缓存的不足 Ajax缓存虽然 ...

  3. 【mySQL】 - 主键

    什么是主键? 对于表中的每一行数据,都会有一个字段或一组字段,用于标识自己的唯一性,这样的一个或一组字段,就叫主键 如果没有这个主键,那么对于表中的每一行的管理,会陷入混乱,我要更新某一特定行的数值, ...

  4. c#采用emit将DataTable转List

    前面已经说了List转DataTable,也整理了代码. 现在转回来说说DataTable转List. 先举一个例子 public class Person { public int Age{get; ...

  5. vue项目获取当前地址栏参数(非路由传参)

    项目中遇到一个需求,就是另一个管理系统带参直接单纯的跳转跳转到vue pc项目中的某个页面,后再初始化查询数据,参数以地址栏的形式传入 管理系统:打开新地址地址 let obj = { id: 21, ...

  6. js 时间转换毫秒的四种方法(转)

    将时间转换为毫秒数的方法有四个: Date.parse()Date.UTCvalueOf()getTime() 1. Date.parse():该方法接受一个表示日期的字符串参数,然后尝试根据这个日期 ...

  7. MySQL学习之路(二)——数据类型和操作数据表

    数据类型和操作数据表 2.1 MySQL类型之整型 2.2 MySQL数据类型之浮点型 2.3 日期时间型 DATE 1支持时间:1000年1月1日~9999年12月31日 DATETIME 3 支持 ...

  8. eclipse 打开一个新工程的基本设置

    1.代码自动提示 Window -> Preferences -> Java -> Editor -> Content Assist -> Auto Activation ...

  9. Google Cloud Platform 续

    Google Cloud Platform 创建新实例 地区:australia-southeast1-a 机器类型:1个vCPU n1-standard-1 系统:Ubuntu 16.04 LTS ...

  10. Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first.

    最近在开发一个网站时,有个需要是 如果有新预警信息要在网页中播放提示音.页面打开会请求是否有新信息,有则播放提示音.在Chrome的最新浏览器中,播放会报错,控制台显示Uncaught (in pro ...