Search in sources :

Example 1 with CacheProvider

use of com.adeptj.modularweb.cache.api.CacheProvider 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

CacheProvider (com.adeptj.modularweb.cache.api.CacheProvider)1 Serializable (java.io.Serializable)1 AuthorizationInfo (org.apache.shiro.authz.AuthorizationInfo)1 Cache (org.apache.shiro.cache.Cache)1 Session (org.apache.shiro.session.Session)1 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)1