4

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?

UnlikePluto
  • 3,101
  • 4
  • 23
  • 33
atian25
  • 4,166
  • 8
  • 37
  • 60

1 Answers1

2

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

Les Hazlewood
  • 18,480
  • 13
  • 68
  • 76
  • @Les - I am in need of doing the same, I want to use the built in caching support that comes with grails, but I think it's not possible with the way grails-shriro plugin is implemented. Grails shiro plugin doesn't extend any of the built in realm (eg AuthorizingRealm) but rather implements the Realm inteface it self. So in order to do caching, we have to do that manually in the realm itself and can not depends on shiro to cache the authentication info for us – Sudhir N Sep 07 '12 at 10:00