NutzCN Logo
问答 NutzBoot中使用shiro,如何配置session过期时间?
发布于 2375天前 作者 qq_e48f71e9 2890 次浏览 复制 上一个帖子 下一个帖子
标签:

shiro的session缓存使用lcache(redis)
查看prev_doc加了如下配置:

# session过期时间,10年
shiro.session.cache.redis.ttl=360000000
#使用redis二级缓存
shiro.session.cache.type=lcache

看浏览器cookie的过期时间为好几十年,redis的key的过期时间的确也是十年,但是浏览器过了段时间还是会提示session失效,不知是我配置不对还是nb的bug? 望指教

21 回复

这么长没测过, 我设置过的最长超时也就一年

好的,我测试一下1年

对了,shiro.session.cache.redis.ttl单位是毫秒还是秒?

失效时间配置为:

shiro.session.cache.redis.ttl=2600000

过了不到2给小时,又超时了,奇怪的是redis里的key还在,浏览器的cookie也还在,但是就是需要重新登陆了。。。。我怀疑是个bug

日志里面有什么提示没?

话说, 是不是ehcache.xml里面配了过期时间?

日志不太好找...不知道多久才出现这种情况....

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="false"
    monitoring="autodetect" dynamicConfig="true" name="aabbccdd">
    <diskStore path="ehcache/aabbccdd"/>
    <cache name="shiro-activeSessionCache"
           maxElementsInMemory="1000"
           overflowToDisk="true"
           eternal="true"
           timeToLiveSeconds="0"
           timeToIdleSeconds="0"
           diskPersistent="true"
           diskExpiryThreadIntervalSeconds="600"/>

    <defaultCache maxElementsInMemory="10000" eternal="false"
                  timeToIdleSeconds="86400" timeToLiveSeconds="86400" overflowToDisk="false"
                  diskPersistent="false" diskExpiryThreadIntervalSeconds="120"
                  statistics="false" />
</ehcache>

ehcache有问题吗?

你本地不能重现吗?

能重现,但是我不知道等多久才会失效....

好巧,重现了

[DEBUG] 16:52:25.168 org.apache.shiro.web.servlet.SimpleCookie.readValue(SimpleCookie.java:389) - Found 'sid' cookie value [3h76fc1n32jcgrr4s3tjsvndgg]
[DEBUG] 16:52:25.177 org.nutz.plugins.cache.impl.lcache.LCache.fire(LCache.java:96) - fire channel=LCache:shiro-activeSessionCache msg=vh1udoli30jckol7naejfu3rj1:3h76fc1n32jcgrr4s3tjsvndgg
[DEBUG] 16:52:25.180 org.nutz.plugins.cache.impl.lcache.CachePubSub.onPMessage(CachePubSub.java:15) - channel=LCache:shiro-activeSessionCache, msg=vh1udoli30jckol7naejfu3rj1:3h76fc1n32jcgrr4s3tjsvndgg
[DEBUG] 16:52:25.180 org.nutz.plugins.cache.impl.lcache.LCache.fire(LCache.java:96) - fire channel=LCache:shiro-activeSessionCache msg=vh1udoli30jckol7naejfu3rj1:3h76fc1n32jcgrr4s3tjsvndgg
[DEBUG] 16:52:25.181 org.apache.shiro.web.session.mgt.DefaultWebSessionManager.onInvalidation(DefaultWebSessionManager.java:300) - Referenced session was invalid.  Removing session ID cookie.
[DEBUG] 16:52:25.181 org.nutz.plugins.cache.impl.lcache.CachePubSub.onPMessage(CachePubSub.java:15) - channel=LCache:shiro-activeSessionCache, msg=vh1udoli30jckol7naejfu3rj1:3h76fc1n32jcgrr4s3tjsvndgg
[DEBUG] 16:52:25.182 org.apache.shiro.web.servlet.SimpleCookie.addCookieHeader(SimpleCookie.java:226) - Added HttpServletResponse Cookie [sid=deleteMe; Path=/; Max-Age=0; Expires=Thu, 21-Jun-2018 08:52:25 GMT]
[DEBUG] 16:52:25.183 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) - Found mapping for [GET] path=/platform/sys/conf : SysConfController.index(SysConfController.java:42)
[DEBUG] 16:52:25.183 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:166) - Get 'sysConfController'<class cn.budiot.app.web.modules.controllers.platform.sys.SysConfController>
[DEBUG] 16:52:25.184 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:192) - 	 >> Load definition name=sysConfController
[DEBUG] 16:52:25.184 org.nutz.ioc.loader.combo.ComboIocLoader.printFoundIocBean(ComboIocLoader.java:226) - Found IocObject(sysConfController) in AnnotationIocLoader(packages=[cn.budiot])
[DEBUG] 16:52:25.185 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:223) - 	 >> Make...'sysConfController'<class cn.budiot.app.web.modules.controllers.platform.sys.SysConfController>
[DEBUG] 16:52:25.185 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:65) - Save object 'sysConfController' to [app] 
[DEBUG] 16:52:25.214 org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:64) - name=sysConfigService not found, search for type=cn.budiot.app.sys.modules.services.SysConfigService
[DEBUG] 16:52:25.215 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:166) - Get '4e7iactcuug8ir7olr7tqspupu'<interface cn.budiot.app.sys.modules.services.SysConfigService>
[DEBUG] 16:52:25.217 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:166) - Get 'pubSubService'<class org.nutz.integration.jedis.pubsub.PubSubService>
[DEBUG] 16:52:25.219 cn.budiot.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) - [GET ]URI=/platform/sys/conf 36ms
[DEBUG] 16:52:25.228 org.apache.shiro.session.mgt.DefaultSessionManager.retrieveSession(DefaultSessionManager.java:218) - Unable to resolve session ID from SessionKey [org.apache.shiro.web.session.mgt.WebSessionKey@7b05bfc0].  Returning null to indicate a session could not be found.
[DEBUG] 16:52:25.229 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) - Found mapping for [GET] path=/platform/login : SysLoginController.login(SysLoginController.java:68)
[DEBUG] 16:52:25.230 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:166) - Get 'sysLoginController'<class cn.budiot.app.web.modules.controllers.platform.sys.SysLoginController>
[DEBUG] 16:52:25.230 org.apache.shiro.session.mgt.DefaultSessionManager.create(DefaultSessionManager.java:175) - Creating new EIS record for new session instance [org.apache.shiro.session.mgt.SimpleSession,id=null]
[DEBUG] 16:52:25.231 org.nutz.plugins.cache.impl.lcache.LCache.fire(LCache.java:96) - fire channel=LCache:shiro-activeSessionCache msg=vh1udoli30jckol7naejfu3rj1:3t1rsvetbqid2puegue4gus4gp
[DEBUG] 16:52:25.232 org.nutz.plugins.cache.impl.lcache.CachePubSub.onPMessage(CachePubSub.java:15) - channel=LCache:shiro-activeSessionCache, msg=vh1udoli30jckol7naejfu3rj1:3t1rsvetbqid2puegue4gus4gp
[DEBUG] 16:52:25.233 org.nutz.plugins.cache.impl.lcache.LCache.fire(LCache.java:96) - fire channel=LCache:shiro-activeSessionCache msg=vh1udoli30jckol7naejfu3rj1:3t1rsvetbqid2puegue4gus4gp
[DEBUG] 16:52:25.233 org.nutz.plugins.cache.impl.lcache.CachePubSub.onPMessage(CachePubSub.java:15) - channel=LCache:shiro-activeSessionCache, msg=vh1udoli30jckol7naejfu3rj1:3t1rsvetbqid2puegue4gus4gp
[DEBUG] 16:52:25.234 org.apache.shiro.web.servlet.SimpleCookie.addCookieHeader(SimpleCookie.java:226) - Added HttpServletResponse Cookie [sid=3t1rsvetbqid2puegue4gus4gp; Path=/; Max-Age=946080000; Expires=Sun, 14-Jun-2048 08:52:25 GMT; HttpOnly]
[DEBUG] 16:52:25.331 org.nutz.plugins.cache.impl.lcache.LCache.fire(LCache.java:96) - fire channel=LCache:shiro-activeSessionCache msg=vh1udoli30jckol7naejfu3rj1:3t1rsvetbqid2puegue4gus4gp
[DEBUG] 16:52:25.331 org.nutz.plugins.cache.impl.lcache.CachePubSub.onPMessage(CachePubSub.java:15) - channel=LCache:shiro-activeSessionCache, msg=vh1udoli30jckol7naejfu3rj1:3t1rsvetbqid2puegue4gus4gp
[DEBUG] 16:52:25.332 cn.budiot.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) - [GET ]URI=/platform/login 103ms
[DEBUG] 16:52:25.407 org.apache.shiro.web.servlet.SimpleCookie.readValue(SimpleCookie.java:389) - Found 'sid' cookie value [3t1rsvetbqid2puegue4gus4gp]
[DEBUG] 16:52:25.414 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) - Found mapping for [GET] path=/platform/login/captcha : SysLoginController.next(SysLoginController.java:243)
[DEBUG] 16:52:25.416 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:166) - Get 'sysLoginController'<class cn.budiot.app.web.modules.controllers.platform.sys.SysLoginController>
[DEBUG] 16:52:25.460 cn.budiot.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) - [GET ]URI=/platform/login/captcha 45ms
[DEBUG] 16:52:27.937 org.apache.zookeeper.ClientCnxn$SendThread.readResponse(ClientCnxn.java:742) - Got ping response for sessionid: 0x100000b866c0012 after 0ms

想起来了,得配一下shiro本身的session超时时间呢,你写的两个只是缓存session的时间,还不是session过期的时间

so, 如何配置?

看配置手册啊,里面有

貌似是我的锅?

shiro.session.manager.globalSessionTimeout=86400

配置总览木有这个呢

嗯, 我补充一下,单位毫秒

好了, 加了代码了

nice,wendal无敌

添加回复
请先登陆
回到顶部