NutzCN Logo
问答 shiro+redis做session共享如何自定义redis中缓存名称
发布于 2209天前 作者 xiaoqiu1235 3768 次浏览 复制 上一个帖子 下一个帖子
标签:

目前默认key的开头为shiro-activeSessionCache:
shiro.ini中的代码

[main]

#Session管理器,关闭定时校验机制,持久化环境下会非常耗内存
sessionManager = org.apache.shiro.web.session.mgt.DefaultWebSessionManager
sessionManager.sessionValidationSchedulerEnabled = false
sessionManager.sessionIdUrlRewritingEnabled = false
sessionManager.deleteInvalidSessions = true

#带缓存的SessionDAO
sessionDAO = org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO
sessionManager.sessionDAO = $sessionDAO
securityManager.sessionManager = $sessionManager

# use R.UU32(), 原生的是UUID,比较长
sessionIdGenerator = org.nutz.integration.shiro.UU32SessionIdGenerator
securityManager.sessionManager.sessionDAO.sessionIdGenerator = $sessionIdGenerator

#记住我
rememberMeCookie = org.apache.shiro.web.servlet.SimpleCookie
rememberMeCookie.name=remember
rememberMeCookie.maxAge = 604800
rememberMeCookie.httpOnly = true
rememberMeManager = org.apache.shiro.web.mgt.CookieRememberMeManager
rememberMeManager.cookie = $rememberMeCookie

# 2层缓存配置
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_redis.ttl=1800
cacheManager = org.nutz.plugins.cache.impl.lcache.LCacheManager
cacheManager.level1 = $cacheManager_ehcache
cacheManager.level2 = $cacheManager_redis
cacheManager.jedisAgent = $jedisAgent
securityManager.sessionManager.cacheManager = $cacheManager
#securityManager.rememberMeManager = $rememberMeManager

# realm声明
nutzdao_realm = com.hxd.shiro.realm.UserRealm

# cookie, nutzcn使用超长时间的cookie,所以下面的timeout都很长
sessionIdCookie=org.apache.shiro.web.servlet.SimpleCookie
sessionIdCookie.name=sid
sessionIdCookie.maxAge=1800000
sessionIdCookie.httpOnly=true
sessionManager.sessionIdCookie=$sessionIdCookie
sessionManager.sessionIdCookieEnabled=true
sessionManager.globalSessionTimeout=1800000

kickout=com.hxd.shiro.filter.KickoutSessionControlFilter
kickout.cacheManager=$cacheManager
kickout.sessionManager=$sessionManager
kickout.kickoutUrl=/login

authc = com.hxd.shiro.filter.UserAuthenticationFilter
authc.loginUrl  = /login
;perms.loginUrl  = /login
;roles.loginUrl  = /login
;user.loginUrl   = /login
;rest.loginUrl   = /login
logout.redirectUrl= /login


[urls]
/static/*        = anon, noSessionCreation
/swagger/**        = anon, noSessionCreation

/home = authc,kickout
/ = authc,kickout
/mana/** = authc,kickout

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

嗯嗯,刚才把sesisondao点进去看了父类CachingSessionDAO里面有设置名称的,蟹蟹

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