Shiro grails插件 - 配置

时间:2011-12-26 07:49:33

标签: grails shiro

使用ehcache + terracotta设置shiro会话缓存,在config.groovy中输入这些配置 -

security.shiro.sessionDAO =“org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO”

//此名称与ehcache.xml中的缓存名称匹配: security.shiro.sessionDAO.activeSessionsCacheName =“shiro-activeSessionsCache” security.shiro.securityManager.sessionManager.sessionDAO =“org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO”

//配置EhCacheManager: security.shiro.cacheManager =“org.apache.shiro.cache.ehcache.EhCacheManager” security.shiro.cacheManager.cacheManagerConfigFile =“classpath:session_ehcache.xml”

//在Shiro的SecurityManager上配置上面的CacheManager //将它用于Shiro的所有缓存需求: security.shiro.securityManager.cacheManager =“org.apache.shiro.cache.ehcache.EhCacheManager”

但看起来像shiro插件没有读取配置,使用“security.shiro”作为前缀

提前致谢

1 个答案:

答案 0 :(得分:0)

想出这可以通过一种方式完成 -

1.在resources.groovy配置(覆盖插件定义)正确的shiroSecurityManager bean:

myShiroSessionDAO(org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO) {
    activeSessionsCacheName="shiro-activeSessionsCache"
}
myShiroSessionManager(org.apache.shiro.web.session.mgt.DefaultWebSessionManager) {
    sessionDAO = ref("myShiroSessionDAO")
}
myShiroCacheManager(org.apache.shiro.cache.ehcache.EhCacheManager) {
    cacheManagerConfigFile = "classpath:session_ehcache.xml"
   //cacheManager = CacheManager.create()
}
shiroSecurityManager(org.apache.shiro.web.mgt.DefaultWebSecurityManager) {
    cacheManager = ref("myShiroCacheManager")
    sessionManager = ref("myShiroSessionManager")
}

OR

2.在Bootstrap.groovy

配置shiroSecurityManager
def sessionDao = new org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO()
sessionDao.activeSessionsCacheName="shiro-activeSessionCache"
shiroSecurityManager.sessionManager.sessionDAO = sessionDao
def cacheManager = new org.apache.shiro.cache.ehcache.EhCacheManager()
cacheManager.cacheManagerConfigFile = "classpath:session_ehcache.xml"
shiroSecurityManager.cacheManager = cacheManager

@ Config.groovy put -

security.shiro.session.mode="native"