We are currently working on a Web Application which integrates Wicket,
Spring and Shiro. I would like to enable Shiro for using our ehCache. In
our SpringConfig I define the following beans:
The first one is the definition of our Realm. It extends
AuthorizingRealm and thus should support caching according to the Shiro
documentation.
@Bean
public W7Realm W7Realm() {
W7Realm realm = new W7Realm();
HashedCredentialsMatcher credentialsMatcher = new
HashedCredentialsMatcher(ShiroPasswordUtil.ALGORITHM);
credentialsMatcher.setHashIterations(ShiroPasswordUtil.ITERATIONS);
realm.setCredentialsMatcher(credentialsMatcher);
return realm;
}
Next, I define our login cache, which should cache the user credentials:
@Bean(name="loginCache")
public CacheManager shiroCacheManager() {
EhCacheManager shiroCache = new EhCacheManager();
shiroCache.setCacheManager(ehcache().getObject());
return shiroCache;
}
Thereby, the ehcache() call refers to our regular ehcache, which is also
defined in the SpringConfig by:
@Bean(name = "cacheManager")
public EhCacheManagerFactoryBean ehcache() {
EhCacheManagerFactoryBean mfb = new EhCacheManagerFactoryBean();
mfb.setConfigLocation(new ClassPathResource("ehcache.xml"));
return mfb;
}
Finally, I am setting our security manager
@Bean(name = "securityManager")
public DefaultWebSecurityManager securityManager() {
DefaultWebSecurityManager sm = new DefaultWebSecurityManager();
sm.setCacheManager(shiroCacheManager());
sm.setSessionMode(DefaultWebSecurityManager.HTTP_SESSION_MODE);
sm.setRealm(W7Realm());
// Set a servletcontainer session manager
SessionManager session = new ServletContainerSessionManager();
sm.setSessionManager(session);
SecurityUtils.setSecurityManager(sm);
return sm;
}
However, Shiro does not use the cache manager which I set with the call
sm.setCacheManager(shiroCacheManager());
Additionally, we tried to set the cache manager directly on the realm,
but that did help either.
I am somewhat stuck here and any help would be greatly appreciated.