NutzCN Logo
问答 nutzwk中shiro的SessionListener的一些疑问
发布于 77天前 作者 码农 199 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk

session在超时之后,得重新刷新一下前端页面才能请到下面的这个方法,能不能session一销毁,不刷新前端页面的情况就能执行到这个方法?

public class UserSessionListener  implements SessionListener {
 @Override
    public void onExpiration(Session session) {
        System.err.println("会话过期了,销毁session");
    }
}
10 回复

shiro有个配置项,是否轮询校验session过期状态

@wendal 可否指点一番

[main]
# cacheManager
;-------------Redis作为shiro二级缓存时注释掉这里---------
cacheManager = org.apache.shiro.cache.ehcache.EhCacheManager
cacheManager.cacheManagerConfigFile = classpath:ehcache.xml
;-------------Redis作为shiro二级缓存时注释掉这里---------

;-------------Redis作为shiro二级缓存时启用这里---------
;jedisAgent = org.nutz.integration.jedis.JedisAgent
;cacheManager_ehcache = org.apache.shiro.cache.ehcache.EhCacheManager
;cacheManager_ehcache.cacheManagerConfigFile=classpath:ehcache.xml
;cacheManager_redis = org.nutz.plugins.cache.impl.redis.RedisCacheManager
;cacheManager_redis.mode=kv
;cacheManager_redis.debug=true
;cacheManager = org.nutz.plugins.cache.impl.lcache.LCacheManager
;cacheManager.jedisAgent = $jedisAgent
;cacheManager.level1 = $cacheManager_ehcache
;cacheManager.level2 = $cacheManager_redis
;-------------Redis作为shiro二级缓存时启用这里---------

# Session
sessionManager = org.apache.shiro.web.session.mgt.DefaultWebSessionManager
sessionManager.sessionValidationSchedulerEnabled = true
sessionListener1 = cn.wizzer.app.web.commons.listener.UserSessionListener
sessionManager.sessionListeners = $sessionListener1


# Session Cache
#sessionDAO = org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO
#sessionDAO.cacheManager = $cacheManager
#sessionDAO.activeSessionsCacheName = shiro-activeSessionCache
#sessionManager.sessionDAO = $sessionDAO
securityManager.sessionManager = $sessionManager

# Cookie
sessionIdCookie = org.apache.shiro.web.servlet.SimpleCookie
sessionIdCookie.name = sid
#sessionIdCookie.domain=wizzer.cn
#sessionIdCookie.path=
sessionIdCookie.maxAge = 946080000
sessionIdCookie.httpOnly = true
sessionManager.sessionIdCookie = $sessionIdCookie
sessionManager.sessionIdCookieEnabled = true
sessionManager.globalSessionTimeout = 180000

#bak...
#sessionManager=org.apache.shiro.web.session.mgt.DefaultWebSessionManager

#sessionManager.globalSessionTimeout=50000
#securityManager.sessionManager=$sessionManager

rememberMeCookie = org.apache.shiro.web.servlet.SimpleCookie
rememberMeCookie.name = remember
rememberMeCookie.maxAge = 604800
rememberMeCookie.httpOnly = true
rememberMeManager = cn.wizzer.framework.shiro.remember.LightCookieRememberMeManager
rememberMeManager.cookie = $rememberMeCookie

sha256Matcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher
sha256Matcher.storedCredentialsHexEncoded = false
sha256Matcher.hashIterations = 1024
sha256Matcher.hashSalted = true

shiroDbRealm = cn.wizzer.app.web.commons.shiro.realm.PlatformAuthorizingRealm
shiroDbRealm.credentialsMatcher = $sha256Matcher

securityManager.realms = $shiroDbRealm
authcStrategy = cn.wizzer.framework.shiro.pam.AnySuccessfulStrategy
securityManager.authenticator.authenticationStrategy = $authcStrategy
securityManager.cacheManager = $cacheManager
securityManager.rememberMeManager = $rememberMeManager

authc = cn.wizzer.app.web.commons.shiro.filter.PlatformAuthenticationFilter
authc.captchaParam=platformCaptcha
authc.loginUrl = /platform/login
logout.redirectUrl = /platform/login

[urls]
/platform/doLogin = anon
/assets/** = anon
/** = anon
/platform/** = authc
/api/** = authc

sessionManager.sessionValidationSchedulerEnabled = true

已经启用了,只是轮询时间未到吧

sessionManager.sessionValidationInterval=60000

减少间隔试试

@wendal session超时之后怎么给前端页面发送通知啊?有什么新丝路?

websocket咯

@wendal websocket是不是得一直处于连接状态,那么session还会过期吗?

websocket并不会更新HttpSession的过期时间

@wendal nutz有websocket的demo吗?观摩观摩

nutzmore有插件呀,nutz-book-project,nutzwk都在使用

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