How to use cache permissions in grails shiro

倖福魔咒の 提交于 2019-12-09 18:40:24

问题


Everytime i call subject.isPermitted(), it sends a sql to db.
How can i cache it? Any example? Thanks.


I read the doc of shiro grails plugin, but cant solove it.

DataSource:

hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = true
    cache.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider'
}

How to set the cachemanager to shiro? I try spring.resource,throw an error.

What's the instance bean name of cachemanager? Do i need to config sth else?


回答1:


You'll need to configure an org.apache.shiro.cache.CacheManager instance on Shiro's SecurityManager. Most of Shiro's out-of-the-box Realm implementations know how to work with a configured CacheManager and will cache AuthorizationInfo returned from a Realm permission lookup automatically.

I'm not sure how to do this using the Grails Shiro plugin, but in Shiro's INI, you would do that this way:

[main]
...
cacheManager = com.my.implementation.of.CacheManager
securityManager.cacheManager = $cacheManager
...

I'd recommend asking the grails-user mailing list to see if there is a more 'grailsy' way to configure this for the Grails Shiro plugin.

HTH,

Les



来源:https://stackoverflow.com/questions/4425283/how-to-use-cache-permissions-in-grails-shiro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!