Shiro 入门系列 四 (shiro缓冲整合EhCache)
来源:互联网 发布:ubc法学院 知乎 编辑:程序博客网 时间:2024/05/16 14:12
1.Shiro的缓冲
shiro的缓冲是被shiro的缓冲管理器所管理的,即CacheManage,Shiro的用户认证是没有提供缓冲机制的,因为每次登陆一次查询一次数据库比对一下用户名密码,做缓冲的必要几乎是没有的。但是shiro的授权将会是大量的数据,shiro的授权缓冲是默认开启的,接下来我们将对shiro的缓冲使用EhCache来管理,之后授权时只有用户第一次访问系统的时候会走realm查数据库,之后就会走缓冲。
注意:用户正常退出或者非正常退出时都会清空缓冲。
2.代码
!-- 安全管理器 --><bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager"><property name="realm" ref="userRealm" /><property name="cacheManager" ref="cacheManager"/></bean><!-- 缓存管理器 --><bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager"> <property name="cacheManagerConfigFile" value="classpath:shiro-ehcache.xml"/> </bean>
8.4.3配置shiro-ehcache.xml<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="../config/ehcache.xsd"><!--diskStore:缓存数据持久化的目录 地址 --><diskStore path="F:\develop\ehcache" /><defaultCache maxElementsInMemory="1000" maxElementsOnDisk="10000000"eternal="false" overflowToDisk="false" diskPersistent="false"timeToIdleSeconds="120"timeToLiveSeconds="120" diskExpiryThreadIntervalSeconds="120"memoryStoreEvictionPolicy="LRU"></defaultCache></ehcache>
3.缓冲清空
当用户权限修改后,用户再次登陆shiro会自动调用realm从数据库获取权限数据,如果在修改权限后想立即清除缓存则可以调用realm的clearCache方法清除缓存。
realm中定义clearCached方法:
//清除缓存
public void clearCached() {
PrincipalCollection principals = SecurityUtils.getSubject().getPrincipals();
super.clearCache(principals);
}
在权限修改后调用realm中的方法,realm已经由spring管理,所以从spring中获取realm实例,调用clearCached方法。
0 1
- Shiro 入门系列 四 (shiro缓冲整合EhCache)
- Shiro缓存整合EhCache
- shiro整合ehcache
- Spring mvc+shiro+ehcache整合
- Shiro 入门系列 二 (认证与Spring的整合)
- Shiro系列之Shiro+Spring MVC整合
- Shiro系列之Shiro+Spring MVC整合
- shiro ehcache
- shiro ehcache
- Shiro入门-shiro与spring整合
- Shiro入门学习四
- shiro入门学习四
- Shiro入门系列一
- springmvc 整合shiro ehcache 项目源码
- springmvc SSM java redis shiro ehcache 整合
- Shiro入门-整合验证码
- 【shiro】--- spring整合shiro
- 缓存框架EhCache整合shiro权限验证(基于spring整合)
- Xml 格式数据的生成和解析
- Round-robin 算法
- RadioGroup 的 RadioButton 选择改变字体颜色和背景颜色(通过XML设置)
- ubuntu下配置apache,php,mysql
- 基于Swift语言开发微信、QQ跟微博的SSO授权登录代码分析
- Shiro 入门系列 四 (shiro缓冲整合EhCache)
- Js语言中Call方法和Apply方法
- 浙大 PAT b1049
- linux 一次性杀死同一名称的进程
- IHS的esi功能导致下载大文件报500错误
- 重写submit提交事件
- 将项目部署到tomcat的webapps目录下
- 文章标题
- 【HAOI2010】BZOJ2423 BSOJ2775 CODEVS1862 洛谷P2516 最长公共子序列