shiro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexander Openkowski <opn...@googlemail.com>
Subject Re: Shiro Guice Cache Configuration
Date Fri, 18 Jul 2014 05:52:38 GMT
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 <warrenbell2@gmail.com> 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
>
>
>
>

Mime
View raw message