Search in sources :

Example 1 with Cache

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("说明【授权】缓存被清空了。");
    }
}
Also used : Cache(org.apache.shiro.cache.Cache)

Example 2 with Cache

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("说明【认证】缓存被清空了。");
    }
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) Cache(org.apache.shiro.cache.Cache)

Example 3 with Cache

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;
}
Also used : Serializable(java.io.Serializable) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) CacheProvider(com.adeptj.modularweb.cache.api.CacheProvider) AuthorizationInfo(org.apache.shiro.authz.AuthorizationInfo) Cache(org.apache.shiro.cache.Cache) Session(org.apache.shiro.session.Session)

Aggregations

Cache (org.apache.shiro.cache.Cache)3 CacheProvider (com.adeptj.modularweb.cache.api.CacheProvider)1 PmphUser (com.bc.pmpheep.back.po.PmphUser)1 Serializable (java.io.Serializable)1 AuthorizationInfo (org.apache.shiro.authz.AuthorizationInfo)1 Session (org.apache.shiro.session.Session)1 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)1 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)1