當前位置: 首頁>>代碼示例>>Java>>正文


Java CacheManager類代碼示例

本文整理匯總了Java中org.apache.shiro.cache.CacheManager的典型用法代碼示例。如果您正苦於以下問題:Java CacheManager類的具體用法?Java CacheManager怎麽用?Java CacheManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CacheManager類屬於org.apache.shiro.cache包,在下文中一共展示了CacheManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: securityManager

import org.apache.shiro.cache.CacheManager; //導入依賴的package包/類
@Bean(name = "securityManager")
	@ConditionalOnMissingBean
	public DefaultSecurityManager securityManager(CacheManager shiroCacheManager) {
        DefaultWebSecurityManager dwsm = new DefaultWebSecurityManager();

        // 用自己的Factory實現替換默認
        // 用於關閉session功能
        dwsm.setSubjectFactory(new StatelessSubjectFactory());
        dwsm.setSessionManager(defaultSessionManager());
        // 關閉session存儲
        ((DefaultSessionStorageEvaluator) ((DefaultSubjectDAO)dwsm.getSubjectDAO()).getSessionStorageEvaluator()).setSessionStorageEnabled(false);

//      <!-- 用戶授權/認證信息Cache, 采用EhCache 緩存 -->
        dwsm.setCacheManager(shiroCacheManager);

        SecurityUtils.setSecurityManager(dwsm);
        return dwsm;
	}
 
開發者ID:wanghongfei,項目名稱:shiro-spring-boot-starter,代碼行數:19,代碼來源:ShiroManager.java

示例2: ApiKeyRealm

import org.apache.shiro.cache.CacheManager; //導入依賴的package包/類
public ApiKeyRealm(String name, CacheManager cacheManager, AuthIdentityReader<ApiKey> authIdentityReader,
                   PermissionReader permissionReader, @Nullable String anonymousId) {
    super(null, AnonymousCredentialsMatcher.anonymousOrMatchUsing(new SimpleCredentialsMatcher()));


    _authIdentityReader = checkNotNull(authIdentityReader, "authIdentityReader");
    _permissionReader = checkNotNull(permissionReader, "permissionReader");
    _anonymousId = anonymousId;

    setName(checkNotNull(name, "name"));
    setAuthenticationTokenClass(ApiKeyAuthenticationToken.class);
    setPermissionResolver(permissionReader.getPermissionResolver());
    setRolePermissionResolver(createRolePermissionResolver());
    setCacheManager(prepareCacheManager(cacheManager));
    setAuthenticationCachingEnabled(true);
    setAuthorizationCachingEnabled(true);

    // By default Shiro calls clearCache() for each user when they are logged out in order to prevent stale
    // credentials from being cached.  However, if the cache manager implements InvalidatingCacheManager then it has
    // its own internal listeners that will invalidate the cache on any updates, making this behavior unnecessarily
    // expensive.
    _clearCaches = cacheManager != null && !(cacheManager instanceof InvalidatableCacheManager);
    _log.debug("Clearing of caches for realm {} is {}", name, _clearCaches ? "enabled" : "disabled");
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:25,代碼來源:ApiKeyRealm.java

示例3: getAuthorizationCacheLazy

import org.apache.shiro.cache.CacheManager; //導入依賴的package包/類
/**
 * 因為{@link AuthorizingRealm#getAuthorizationCacheLazy()}方法為 private,當前類的{@link #getAuthorizationInfo}
 * 方法不能沒權限訪問,所以把{@link AuthorizingRealm#getAuthorizationCacheLazy()}方法Copy一份
 * @return
 */
private Cache<Object, AuthorizationInfo> getAuthorizationCacheLazy() {
	if (getAuthorizationCache() == null) {
		if (log.isDebugEnabled()) {
			log.debug("No authorizationCache instance set.  Checking for a cacheManager...");
		}
		
		CacheManager cacheManager = getCacheManager();
		if (cacheManager != null) {
			String cacheName = getAuthorizationCacheName();
			if (log.isDebugEnabled()) {
				log.debug("CacheManager [{}] has been configured.  Building authorization cache named [{}]",
						cacheManager, cacheName);
			}
			setAuthorizationCache(cacheManager.getCache(cacheName));
		} else {
			if (log.isInfoEnabled()) {
				log.info("No cache or cacheManager properties have been set.  Authorization cache cannot be obtained.");
			}
		}
	}
	return getAuthorizationCache();
}
 
開發者ID:easycodebox,項目名稱:easycode,代碼行數:28,代碼來源:DefaultCasRealm.java

示例4: AuthenticatingRealm

import org.apache.shiro.cache.CacheManager; //導入依賴的package包/類
public AuthenticatingRealm(CacheManager cacheManager, CredentialsMatcher matcher) {
    authenticationTokenClass = UsernamePasswordToken.class;

    //retain backwards compatibility for Shiro 1.1 and earlier.  Setting to true by default will probably cause
    //unexpected results for existing applications:
    this.authenticationCachingEnabled = false;

    int instanceNumber = INSTANCE_COUNT.getAndIncrement();
    this.authenticationCacheName = getClass().getName() + DEFAULT_AUTHORIZATION_CACHE_SUFFIX;
    if (instanceNumber > 0) {
        this.authenticationCacheName = this.authenticationCacheName + "." + instanceNumber;
    }

    if (cacheManager != null) {
        setCacheManager(cacheManager);
    }
    if (matcher != null) {
        setCredentialsMatcher(matcher);
    }
}
 
開發者ID:xuegongzi,項目名稱:rabbitframework,代碼行數:21,代碼來源:AuthenticatingRealm.java

示例5: getAuthenticationCacheLazy

import org.apache.shiro.cache.CacheManager; //導入依賴的package包/類
/**
 * Checks to see if the authenticationCache class attribute is null, and if so, attempts to acquire one from
 * any configured {@link #getCacheManager() cacheManager}.  If one is acquired, it is set as the class attribute.
 * The class attribute is then returned.
 *
 * @return an available cache instance to be used for authentication caching or {@code null} if one is not available.
 * @since 1.2
 */
private Cache<Object, AuthenticationInfo> getAuthenticationCacheLazy() {

    if (this.authenticationCache == null) {

        log.trace("No authenticationCache instance set.  Checking for a cacheManager...");

        CacheManager cacheManager = getCacheManager();

        if (cacheManager != null) {
            String cacheName = getAuthenticationCacheName();
            log.debug("CacheManager [{}] configured.  Building authentication cache '{}'", cacheManager, cacheName);
            this.authenticationCache = cacheManager.getCache(cacheName);
        }
    }

    return this.authenticationCache;
}
 
開發者ID:xuegongzi,項目名稱:rabbitframework,代碼行數:26,代碼來源:AuthenticatingRealm.java

示例6: ensureCacheManager

import org.apache.shiro.cache.CacheManager; //導入依賴的package包/類
private net.sf.ehcache.CacheManager ensureCacheManager() {
    try {
        if (this.manager == null) {
            if (log.isDebugEnabled()) {
                log.debug("cacheManager property not set.  Constructing CacheManager instance... ");
            }
            //using the CacheManager constructor, the resulting instance is _not_ a VM singleton
            //(as would be the case by calling CacheManager.getInstance().  We do not use the getInstance here
            //because we need to know if we need to destroy the CacheManager instance - using the static call,
            //we don't know which component is responsible for shutting it down.  By using a single EhCacheManager,
            //it will always know to shut down the instance if it was responsible for creating it.
            this.manager = new net.sf.ehcache.CacheManager(getCacheManagerConfigFileInputStream());
            if (log.isTraceEnabled()) {
                log.trace("instantiated Ehcache CacheManager instance.");
            }
            cacheManagerImplicitlyCreated = true;
            if (log.isDebugEnabled()) {
                log.debug("implicit cacheManager created successfully.");
            }
        }
        return this.manager;
    } catch (Exception e) {
        throw new CacheException(e);
    }
}
 
開發者ID:xuegongzi,項目名稱:rabbitframework,代碼行數:26,代碼來源:EhCacheManager.java

示例7: destroy

import org.apache.shiro.cache.CacheManager; //導入依賴的package包/類
/**
 * Shuts-down the wrapped Ehcache CacheManager <b>only if implicitly created</b>.
 * <p/>
 * If another component injected
 * a non-null CacheManager into this instace before calling {@link #init() init}, this instance expects that same
 * component to also destroy the CacheManager instance, and it will not attempt to do so.
 */
public void destroy() {
    if (cacheManagerImplicitlyCreated) {
        try {
            net.sf.ehcache.CacheManager cacheMgr = getCacheManager();
            cacheMgr.shutdown();
        } catch (Throwable t) {
            if (log.isWarnEnabled()) {
                log.warn("Unable to cleanly shutdown implicitly created CacheManager instance.  " +
                        "Ignoring (shutting down)...", t);
            }
        } finally {
            this.manager = null;
            this.cacheManagerImplicitlyCreated = false;
        }
    }
}
 
開發者ID:xuegongzi,項目名稱:rabbitframework,代碼行數:24,代碼來源:EhCacheManager.java

示例8: provideSecurityManager

import org.apache.shiro.cache.CacheManager; //導入依賴的package包/類
@Provides @Singleton SecurityManager provideSecurityManager(KhaRealm khaRealm,
                                                            OAuth2Realm oauth2Realm,
                                                            CacheManager cacheManager) {
    Factory<SecurityManager> factory = new AbstractFactory<SecurityManager>() {
        @Override
        protected SecurityManager createInstance() {
            DefaultSecurityManager manager = new DefaultSecurityManager();
            manager.setRealms(Arrays.asList(khaRealm, oauth2Realm));
            manager.setCacheManager(cacheManager);
            return manager;
        }
    };
    SecurityManager securityManager = factory.getInstance();
    SecurityUtils.setSecurityManager(securityManager);
    return securityManager;
}
 
開發者ID:kalixia,項目名稱:kha,代碼行數:17,代碼來源:SecurityModule.java

示例9: securitManager

import org.apache.shiro.cache.CacheManager; //導入依賴的package包/類
@Bean(name="securityManager")
public SecurityManager securitManager(@Qualifier("systemRealm")SystemRealm systemRealm, @Qualifier("sessionManager")SessionManager sessionManager, @Qualifier("ehcacheManager")CacheManager cacheManager){
	DefaultWebSecurityManager manager = new DefaultWebSecurityManager();
	manager.setSessionManager(sessionManager);
	//-- 兩種緩存方式: 第一,使用ehcache(shiro自帶的本地內存緩存機製); 第二,使用redis服務進行緩存操作
	manager.setCacheManager(redisCacheManager());
	manager.setRealm(systemRealm);
	return manager;
}
 
開發者ID:ranji1221,項目名稱:lemcloud,代碼行數:10,代碼來源:ShiroConfig.java

示例10: cacheManager

import org.apache.shiro.cache.CacheManager; //導入依賴的package包/類
/**
 * (基於內存的)用戶授權信息Cache
 */
@Bean(name = "cacheManager")
@ConditionalOnMissingBean(name = "cacheManager")
@ConditionalOnMissingClass(value = {"org.apache.shiro.cache.ehcache.EhCacheManager"})
public CacheManager cacheManager() {
    return new MemoryConstrainedCacheManager();
}
 
開發者ID:johntostring,項目名稱:spring-boot-shiro,代碼行數:10,代碼來源:ShiroConfiguration.java

示例11: securityManager

import org.apache.shiro.cache.CacheManager; //導入依賴的package包/類
@Bean(name = "securityManager")
@DependsOn(value = {"cacheManager", "rememberMeManager", "mainRealm"})
public DefaultSecurityManager securityManager(Realm realm, RememberMeManager rememberMeManager,
                                              CacheManager cacheManager, SessionManager sessionManager) {
    DefaultSecurityManager sm = new DefaultWebSecurityManager();
    sm.setRealm(realm);
    sm.setCacheManager(cacheManager);
    sm.setSessionManager(sessionManager);
    sm.setRememberMeManager(rememberMeManager);
    return sm;
}
 
開發者ID:johntostring,項目名稱:spring-boot-shiro,代碼行數:12,代碼來源:ShiroConfiguration.java

示例12: ehcacheManager

import org.apache.shiro.cache.CacheManager; //導入依賴的package包/類
@Bean(name = "cacheManager")
@ConditionalOnClass(name = {"org.apache.shiro.cache.ehcache.EhCacheManager"})
@ConditionalOnMissingBean(name = "cacheManager")
public CacheManager ehcacheManager() {
    EhCacheManager ehCacheManager = new EhCacheManager();
    ShiroProperties.Ehcache ehcache = properties.getEhcache();
    if (ehcache.getCacheManagerConfigFile() != null) {
        ehCacheManager.setCacheManagerConfigFile(ehcache.getCacheManagerConfigFile());
    }
    return ehCacheManager;
}
 
開發者ID:johntostring,項目名稱:spring-boot-shiro,代碼行數:12,代碼來源:ShiroAutoConfiguration.java

示例13: setCacheManager

import org.apache.shiro.cache.CacheManager; //導入依賴的package包/類
/**
 * Sets the wrapped {@link org.ehcache.CacheManager} instance
 *
 * @param cacheManager the {@link org.ehcache.CacheManager} to be used
 */
public void setCacheManager(org.ehcache.CacheManager cacheManager) {
  try {
    destroy();
  } catch (Exception e) {
    log.warn("The Shiro managed CacheManager threw an Exception while closing", e);
  }
  manager = cacheManager;
  cacheManagerImplicitlyCreated = false;
}
 
開發者ID:ehcache,項目名稱:ehcache-shiro,代碼行數:15,代碼來源:EhcacheShiroManager.java

示例14: ensureCacheManager

import org.apache.shiro.cache.CacheManager; //導入依賴的package包/類
private org.ehcache.CacheManager ensureCacheManager() throws MalformedURLException {
  if (manager == null) {
    manager = CacheManagerBuilder.newCacheManager(getConfiguration());
    manager.init();

    cacheManagerImplicitlyCreated = true;
  }

  return manager;
}
 
開發者ID:ehcache,項目名稱:ehcache-shiro,代碼行數:11,代碼來源:EhcacheShiroManager.java

示例15: securityManager

import org.apache.shiro.cache.CacheManager; //導入依賴的package包/類
@Bean(name = "securityManager")
@DependsOn(value = {"cacheManager", "rememberMeManager", "mainRealm"})
public DefaultSecurityManager securityManager(Realm realm, RememberMeManager rememberMeManager, CacheManager cacheManager, SessionManager sessionManager) {
    DefaultSecurityManager sm = new DefaultWebSecurityManager();
    sm.setRealm(realm);
    sm.setCacheManager(cacheManager);
    sm.setSessionManager(sessionManager);
    sm.setRememberMeManager(rememberMeManager);

    return sm;
}
 
開發者ID:storezhang,項目名稱:utils,代碼行數:12,代碼來源:ShiroConfiguration.java


注:本文中的org.apache.shiro.cache.CacheManager類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。