如何在我的应用程序的任何部分中获取Shiro框架中的cacheManager对象的引用?例如,我想删除在删除用户或更新其权限期间缓存的旧用户数据.现在我按照以下方式处理它
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);
}
}
Run Code Online (Sandbox Code Playgroud)