Commit 85014ca2 authored by 周毅's avatar 周毅

修改shiroconfig

parent 98c2aa36
package com.gavel.kwell.config;
import com.gavel.common.Constants;
import com.gavel.common.utils.StringUtils;
import com.gavel.framework.filter.GavelCommonLogoutFilter;
import com.gavel.framework.filter.ShiroAuthFilter;
import com.gavel.kzzx.auth.cas.GavelAuthenticationFilter;
import com.gavel.kzzx.auth.cas.GavelCasFilter;
import com.gavel.kzzx.auth.cas.GavelCasRealm;
import com.gavel.kzzx.auth.cas.GavelLogoutFilter;
import com.gavel.kzzx.auth.shiro.*;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.servlet.Filter;
import org.apache.shiro.cache.CacheManager;
import org.apache.shiro.cache.MemoryConstrainedCacheManager;
import org.apache.shiro.cas.CasSubjectFactory;
......@@ -24,15 +20,24 @@ import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreato
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.DelegatingFilterProxy;
import javax.servlet.Filter;
import java.util.LinkedHashMap;
import java.util.Map;
import com.gavel.common.Constants;
import com.gavel.common.utils.StringUtils;
import com.gavel.framework.filter.GavelCommonLogoutFilter;
import com.gavel.framework.filter.ShiroAuthFilter;
import com.gavel.kzzx.auth.cas.GavelAuthenticationFilter;
import com.gavel.kzzx.auth.cas.GavelCasFilter;
import com.gavel.kzzx.auth.cas.GavelCasRealm;
import com.gavel.kzzx.auth.cas.GavelLogoutFilter;
import com.gavel.kzzx.auth.shiro.GavelAuthResource;
import com.gavel.kzzx.auth.shiro.GavelAuthorizationAttributeSourceAdvisor;
import com.gavel.kzzx.auth.shiro.GavelAuthorizingRealm;
import com.gavel.kzzx.auth.shiro.GavelHashedCredentialsMatcher;
import com.gavel.kzzx.auth.shiro.GavelSessionManager;
@Configuration
......@@ -169,13 +174,13 @@ public class ShiroConfig {
securityManager.setRealm(shiroRealm());
}
// 注入缓存管理器;
if (StringUtils.equals(cacheType, "redis"))
if (StringUtils.equals(cacheType, "redis")){
securityManager.setCacheManager(redisCacheManager());
securityManager.setSessionManager(sessionManager());
}
else
securityManager.setCacheManager(cacheManager());
securityManager.setSessionManager(sessionManager());
return securityManager;
}
......@@ -224,7 +229,6 @@ public class ShiroConfig {
* @return
*/
@Bean("redisManager")
// @ConditionalOnProperty(value="shiro.cache", havingValue="redis", matchIfMissing=false)
public RedisManager redisManager() {
RedisManager redisManager = new RedisManager();
redisManager.setHost(redisConfig.getHost()+":"+redisConfig.getPort());
......@@ -236,7 +240,6 @@ public class ShiroConfig {
*
* @return
*/
@ConditionalOnProperty(value="shiro.cache", havingValue="redis", matchIfMissing=false)
@Bean
public RedisCacheManager redisCacheManager() {
RedisCacheManager redisCacheManager = new RedisCacheManager();
......@@ -247,25 +250,23 @@ public class ShiroConfig {
/**
* redisSessionDAO
*/
// @ConditionalOnProperty(value="shiro.cache", havingValue="redis", matchIfMissing=false)
@Bean("redisSessionDAO")
public RedisSessionDAO redisSessionDAO() {
RedisSessionDAO redisSessionDAO = new RedisSessionDAO();
redisSessionDAO.setRedisManager(redisManager());
// redisSessionDAO.setSessionIdGenerator(new GavelSessionGenerator());
return redisSessionDAO;
}
/**
* sessionManager
*/
// @ConditionalOnProperty(value="shiro.cache", havingValue="redis", matchIfMissing=false)
@Bean("sessionManager")
public GavelSessionManager sessionManager() {
// DefaultWebSessionManager sessionManager = new DefaultWebSessionManager();
GavelSessionManager sessionManager = new GavelSessionManager();
sessionManager.setGlobalSessionTimeout(Constants.liveMills);
sessionManager.setSessionDAO(redisSessionDAO());
if (StringUtils.equals(cacheType, "redis")){
sessionManager.setSessionDAO(redisSessionDAO());
}
return sessionManager;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment