use of org.apache.shiro.cache.Cache in project pmph by BCSquad.
the class PmphUserRealm method clearCachedAuthorizationInfo.
/**
* <pre>
* 功能描述:更新用户授权信息缓存
* 使用示范:
*
* @param principals
* </pre>
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void clearCachedAuthorizationInfo(PrincipalCollection principals) {
logger.info("清除【授权】缓存之前");
Cache c = getAuthorizationCache();
for (Object o : c.keys()) {
logger.info(o + " , " + c.get(o));
}
super.clearCachedAuthorizationInfo(principals);
logger.info("清除【授权】缓存之后");
int cacheSize = c.keys().size();
logger.info("【授权】缓存的大小:" + cacheSize);
for (Object o : c.keys()) {
logger.info(o + " , " + c.get(o));
}
if (cacheSize == 0) {
logger.info("说明【授权】缓存被清空了。");
}
}
use of org.apache.shiro.cache.Cache in project pmph by BCSquad.
the class PmphUserRealm method clearCachedAuthenticationInfo.
/**
* <pre>
* 功能描述:更新身份验证信息缓存
* 使用示范:
*
* @param principals
* </pre>
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected void clearCachedAuthenticationInfo(PrincipalCollection principals) {
Cache c = getAuthenticationCache();
logger.info("清除【认证】缓存之前");
for (Object o : c.keys()) {
logger.info(o + " , " + c.get(o));
}
super.clearCachedAuthenticationInfo(principals);
logger.info("调用父类清除【认证】缓存之后");
for (Object o : c.keys()) {
logger.info(o + " , " + c.get(o));
}
// 添加下面的代码清空【认证】的缓存
PmphUser user = (PmphUser) principals.getPrimaryPrincipal();
SimplePrincipalCollection spc = new SimplePrincipalCollection(user.getUsername(), getName());
super.clearCachedAuthenticationInfo(spc);
logger.info("添加了代码清除【认证】缓存之后");
int cacheSize = c.keys().size();
logger.info("【认证】缓存的大小:" + c.keys().size());
if (cacheSize == 0) {
logger.info("说明【认证】缓存被清空了。");
}
}
use of org.apache.shiro.cache.Cache in project adeptj-modules by AdeptJ.
the class ShiroCacheManager method getCache.
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public <K, V> Cache<K, V> getCache(String name) throws CacheException {
LOGGER.info("Getting cache: [{}]", name);
CacheProvider cacheProvider = CacheProviderTracker.getCacheProvider();
Cache<K, V> shiroCache = null;
switch(name) {
case SHIRO_AUTHORIZATION_CACHE:
com.adeptj.modularweb.cache.api.Cache<K, V> cache = (com.adeptj.modularweb.cache.api.Cache<K, V>) cacheProvider.getCache(SHIRO_AUTHORIZATION_CACHE, PrincipalCollection.class, AuthorizationInfo.class);
if (cache == null) {
LOGGER.warn("Cache: [{}] is not configured properly!!", name);
} else {
shiroCache = new AuthorizationCache<>(cache);
}
break;
case SHIRO_SESSION_CACHE:
com.adeptj.modularweb.cache.api.Cache<K, V> sessionCache = (com.adeptj.modularweb.cache.api.Cache<K, V>) cacheProvider.getCache(SHIRO_SESSION_CACHE, Serializable.class, Session.class);
if (sessionCache == null) {
LOGGER.warn("Cache: [{}] is not configured properly!!", name);
} else {
shiroCache = new ShiroSessionCache<>(sessionCache);
}
break;
default:
LOGGER.warn("Unknown Cache: {}", name);
break;
}
return shiroCache;
}
Aggregations