How can I get a reference to the cacheManager object in the Shiro framework in any part of my application? For example, I want to remove the old user data that was cached during the removal of a user or updating its permission. Right now I am handling it following way
public void cleanUserCache(final String userName) {
final EmbeddedCacheManager embeddedCacheManager = securityRealmsProducer.getEmbeddedCacheManger();
final Cache<Object, Object> authenticationCache = embeddedCacheManager.getCache("JPA-Auth-Realm.authenticationCache");
final Cache<Object, Object> authrizationCache = embeddedCacheManager.getCache("JPA-Auth-Realm.authorizationCache");
final Object userAuthenticationInfo = authenticationCache.get(userName);
if (userAuthenticationInfo != null) {
authenticationCache.remove(userName);
final SimpleAuthenticationInfo principle = (SimpleAuthenticationInfo) userAuthenticationInfo;
final SimplePrincipalCollection simple = (SimplePrincipalCollection) principle.getPrincipals();
authorizationCache.remove(simple);
}
}