前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Shiro 修改权限,刷新权限

Shiro 修改权限,刷新权限

作者头像
WindWant
发布2020-09-11 11:11:12
2K0
发布2020-09-11 11:11:12
举报
文章被收录于专栏:后端码事后端码事

shiro 访问鉴权:Realm

代码语言:javascript
复制
AuthorizingRealm->doGetAuthorizationInfo
代码语言:javascript
复制
doGetAuthorizationInfo
代码语言:javascript
复制
protected abstract AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals)
代码语言:javascript
复制
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.
代码语言:javascript
复制
Parameters:
代码语言:javascript
复制
principals - the primary identifying principals of the AuthorizationInfo that should be retrieved.
代码语言:javascript
复制
Returns:
代码语言:javascript
复制
the AuthorizationInfo associated with this principals.
代码语言:javascript
复制
See Also:
代码语言:javascript
复制
SimpleAuthorizationInfo

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

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

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

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

解决方法:

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

代码语言:javascript
复制
clearCachedAuthorizationInfo
代码语言:javascript
复制
protected void clearCachedAuthorizationInfo(PrincipalCollection principals)
代码语言:javascript
复制
Clears out the AuthorizationInfo cache entry for the specified account.
代码语言:javascript
复制
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.
代码语言:javascript
复制
代码语言:javascript
复制
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.
代码语言:javascript
复制
代码语言:javascript
复制
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).
代码语言:javascript
复制
代码语言:javascript
复制
Parameters:
代码语言:javascript
复制
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
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-01-30 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
数据库
云数据库为企业提供了完善的关系型数据库、非关系型数据库、分析型数据库和数据库生态工具。您可以通过产品选择和组合搭建,轻松实现高可靠、高可用性、高性能等数据库需求。云数据库服务也可大幅减少您的运维工作量,更专注于业务发展,让企业一站式享受数据上云及分布式架构的技术红利!
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档