shiro 1.2.2和1.2.3
为shiro设置了缓存,但是当服务器运行几个小时后,页面判断
<shiro:hasPermission name="admin">
一直未显示。重新登陆也无效。判断问题应该是,实际缓存失效了,但是框架仍然认为有效。 尝试无效办法 (1) 倘若把shiro对应的ehcache配置文章,该掉设置, timeToIdleSeconds="10"
该问题依旧出现。但出问题频次减少 (2)在application-shiro里面添加 <bean id="sessionManager" class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager"> <bean id="sessionDAO" 依旧没用 google到 http:///questions/17657283/cache-invalidate-not-working-in-shiro
(3)验证权限的时候,主动清除缓存。
15:31:24.379 [main] DEBUG o.a.shiro.realm.AuthorizingRealm - No authorizationCache instance set. Checking for a cacheManager...
在shiroDbRealm里面添加这一句 <property name="cacheManager" ref="shiroEhcacheManager" />
问题依旧无解
终极解决
1、 log配置文件里面添加
<logger name="org.apache.shiro" level="trace" >
之后得到日志信息
22:48:20.765 [http-80-3] DEBUG o.a.shiro.realm.AuthenticatingRealm - AuthenticationInfo caching is disabled for info [null].
加上以下内容以后,依旧无效。 <property name="authenticationCachingEnabled" value="true" />
<property name="authorizationCachingEnabled" value="true" />
根源在ShiroUser对象的tostring方法,用的是loginName,但由于业务不需要,loginName根本就没有赋值。所以字符串“NULL”是缓存的key。 故当所有人登录以后,保存的cache key是“null”,一直会互相覆盖。
改写ShiroUser的Tostring()方法,用系统唯一值登录名赋值。问题解决 |
|