小编Pra*_*sht的帖子

如何在应用程序的任何部分从shiro框架获取cacheManager

如何在我的应用程序的任何部分中获取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)

java shiro

9
推荐指数
1
解决办法
126
查看次数

标签 统计

java ×1

shiro ×1