I do it like this:
--------------------------------------
public class MyShiroWebModule extends ShiroWebModule {
public MyShiroWebModule(ServletContext servletContext) {
super(servletContext);
}
@SuppressWarnings("unchecked")
protected void configureShiroWeb() {
// ...
expose(CacheManager.class);
}
@Provides
@Singleton
CacheManager getCacheManager() {
EhCacheManager cacheManager = new EhCacheManager();
cacheManager.setCacheManagerConfigFile("classpath:org/bla/bla/cache/ehcache.xml");
return cacheManager;
}
}
--------------------------
public class MyRealm extends AuthorizingRealm {
@Inject
public MyRealm(CacheManager cacheManager, CredentialsMatcher matcher, ...) {
super(cacheManager, matcher);
setCachingEnabled(true);
}
}
---------------------------
I don't know if that works if you do not extend AuthorizingRealm, though!
On Fri, Jul 18, 2014 at 5:04 AM, Warren Bell <[email protected]> wrote:
> How do I do this in a Guice ShiroModule:
>
> cacheManager = org.apache.shiro.cache.MemoryConstrainedCacheManager
> securityManager.cacheManager = $cacheManager
>
> I have tried this and I am still getting no cache.
>
> bindConstant().annotatedWith(Names.named("shiro.cacheManager")).to("org.apache.shiro.cache.MemoryConstrainedCacheManager");
>
> bindConstant().annotatedWith(Names.named("shiro.securityManager.cacheManager")).to(“$cacheManager”);
>
>
> 9:40:47.987 [RMI TCP Connection(3)-127.0.0.1] DEBUG
> o.a.shiro.realm.AuthorizingRealm - No authorizationCache instance set.
> Checking for a cacheManager...
> 19:40:47.987 [RMI TCP Connection(3)-127.0.0.1] INFO
> o.a.shiro.realm.AuthorizingRealm - No cache or cacheManager properties have
> been set. Authorization cache cannot be obtained.
>
>
> Thanks,
>
> Warren
>
>
>
>