/** * Returns any available {@link Cache} instance to use for authentication caching. This functions as follows: * <ol> * <li>If an {@link #setAuthenticationCache(org.apache.shiro.cache.Cache) authenticationCache} has been explicitly * configured (it is not null), it is returned.</li> * <li>If there is no {@link #getAuthenticationCache() authenticationCache} configured: * <ol> * <li>If authentication caching is {@link #isAuthenticationCachingEnabled() enabled}, any available * {@link #getCacheManager() cacheManager} will be consulted to obtain an available authentication cache. * </li> * <li>If authentication caching is disabled, this implementation does nothing.</li> * </ol> * </li> * </ol> * * @return any available {@link Cache} instance to use for authentication caching. */ private Cache<Object, AuthenticationInfo> getAvailableAuthenticationCache() { Cache<Object, AuthenticationInfo> cache = getAuthenticationCache(); boolean authcCachingEnabled = isAuthenticationCachingEnabled(); if (cache == null && authcCachingEnabled) { cache = getAuthenticationCacheLazy(); } return cache; }
private static Cache<Object, AuthenticationInfo> getAuthenticationCacheLazy(AuthenticatingRealm realm) { if (realm.getAuthenticationCache() == null) { log.trace("No authenticationCache instance set. Checking for a cacheManager..."); CacheManager cacheManager = realm.getCacheManager(); if (cacheManager != null) { String cacheName = realm.getAuthenticationCacheName(); log.debug("CacheManager [{}] configured. Building authentication cache '{}'", cacheManager, cacheName); realm.setAuthenticationCache(cacheManager.getCache(cacheName)); } } return realm.getAuthenticationCache(); }
private static Cache<Object, AuthenticationInfo> getAuthenticationCache(AuthenticatingRealm realm) { AuthenticatingRealm authenticatingRealm = realm; Cache<Object, AuthenticationInfo> cache = authenticatingRealm.getAuthenticationCache(); boolean authcCachingEnabled = authenticatingRealm.isAuthenticationCachingEnabled(); if (cache == null && authcCachingEnabled) { cache = getAuthenticationCacheLazy(authenticatingRealm); } return cache; }
/** * Returns any available {@link Cache} instance to use for authentication caching. This functions as follows: * <ol> * <li>If an {@link #setAuthenticationCache(org.apache.shiro.cache.Cache) authenticationCache} has been explicitly * configured (it is not null), it is returned.</li> * <li>If there is no {@link #getAuthenticationCache() authenticationCache} configured: * <ol> * <li>If authentication caching is {@link #isAuthenticationCachingEnabled() enabled}, any available * {@link #getCacheManager() cacheManager} will be consulted to obtain an available authentication cache. * </li> * <li>If authentication caching is disabled, this implementation does nothing.</li> * </ol> * </li> * </ol> * * @return any available {@link Cache} instance to use for authentication caching. */ private Cache<Object, AuthenticationInfo> getAvailableAuthenticationCache() { Cache<Object, AuthenticationInfo> cache = getAuthenticationCache(); boolean authcCachingEnabled = isAuthenticationCachingEnabled(); if (cache == null && authcCachingEnabled) { cache = getAuthenticationCacheLazy(); } return cache; }
/** * Looks up registered {@link AuthenticatingRealm}s, and clears their authc caches if they have it set. */ private void clearAuthcRealmCaches() { // NOTE: we don't need to iterate all the Sec Managers, they use the same Realms, so one is fine. Collection<Realm> realms = realmSecurityManager.getRealms(); if (realms != null) { for (Realm realm : realms) { if (realm instanceof AuthenticatingRealm) { Cache<Object, AuthenticationInfo> cache = ((AuthenticatingRealm) realm).getAuthenticationCache(); if (cache != null) { log.debug("Clearing cache: {}", cache); cache.clear(); } } } } }
@Override public void clearAuthCache() { for ( Realm realm : realms ) { if ( realm instanceof AuthenticatingRealm ) { Cache<Object,AuthenticationInfo> cache = ((AuthenticatingRealm) realm).getAuthenticationCache(); if ( cache != null ) { cache.clear(); } } if ( realm instanceof AuthorizingRealm ) { Cache<Object,AuthorizationInfo> cache = ((AuthorizingRealm) realm).getAuthorizationCache(); if ( cache != null ) { cache.clear(); } } } }