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

修改shiroconfig

parent 98c2aa36
package com.gavel.kwell.config; package com.gavel.kwell.config;
import com.gavel.common.Constants; import java.util.LinkedHashMap;
import com.gavel.common.utils.StringUtils; import java.util.Map;
import com.gavel.framework.filter.GavelCommonLogoutFilter;
import com.gavel.framework.filter.ShiroAuthFilter; import javax.servlet.Filter;
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 org.apache.shiro.cache.CacheManager; import org.apache.shiro.cache.CacheManager;
import org.apache.shiro.cache.MemoryConstrainedCacheManager; import org.apache.shiro.cache.MemoryConstrainedCacheManager;
import org.apache.shiro.cas.CasSubjectFactory; import org.apache.shiro.cas.CasSubjectFactory;
...@@ -24,15 +20,24 @@ import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreato ...@@ -24,15 +20,24 @@ import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreato
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.DelegatingFilterProxy; import org.springframework.web.filter.DelegatingFilterProxy;
import javax.servlet.Filter; import com.gavel.common.Constants;
import java.util.LinkedHashMap; import com.gavel.common.utils.StringUtils;
import java.util.Map; 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 @Configuration
...@@ -169,13 +174,13 @@ public class ShiroConfig { ...@@ -169,13 +174,13 @@ public class ShiroConfig {
securityManager.setRealm(shiroRealm()); securityManager.setRealm(shiroRealm());
} }
// 注入缓存管理器; // 注入缓存管理器;
if (StringUtils.equals(cacheType, "redis")) if (StringUtils.equals(cacheType, "redis")){
securityManager.setCacheManager(redisCacheManager()); securityManager.setCacheManager(redisCacheManager());
securityManager.setSessionManager(sessionManager());
}
else else
securityManager.setCacheManager(cacheManager()); securityManager.setCacheManager(cacheManager());
securityManager.setSessionManager(sessionManager());
return securityManager; return securityManager;
} }
...@@ -224,7 +229,6 @@ public class ShiroConfig { ...@@ -224,7 +229,6 @@ public class ShiroConfig {
* @return * @return
*/ */
@Bean("redisManager") @Bean("redisManager")
// @ConditionalOnProperty(value="shiro.cache", havingValue="redis", matchIfMissing=false)
public RedisManager redisManager() { public RedisManager redisManager() {
RedisManager redisManager = new RedisManager(); RedisManager redisManager = new RedisManager();
redisManager.setHost(redisConfig.getHost()+":"+redisConfig.getPort()); redisManager.setHost(redisConfig.getHost()+":"+redisConfig.getPort());
...@@ -236,7 +240,6 @@ public class ShiroConfig { ...@@ -236,7 +240,6 @@ public class ShiroConfig {
* *
* @return * @return
*/ */
@ConditionalOnProperty(value="shiro.cache", havingValue="redis", matchIfMissing=false)
@Bean @Bean
public RedisCacheManager redisCacheManager() { public RedisCacheManager redisCacheManager() {
RedisCacheManager redisCacheManager = new RedisCacheManager(); RedisCacheManager redisCacheManager = new RedisCacheManager();
...@@ -247,25 +250,23 @@ public class ShiroConfig { ...@@ -247,25 +250,23 @@ public class ShiroConfig {
/** /**
* redisSessionDAO * redisSessionDAO
*/ */
// @ConditionalOnProperty(value="shiro.cache", havingValue="redis", matchIfMissing=false)
@Bean("redisSessionDAO") @Bean("redisSessionDAO")
public RedisSessionDAO redisSessionDAO() { public RedisSessionDAO redisSessionDAO() {
RedisSessionDAO redisSessionDAO = new RedisSessionDAO(); RedisSessionDAO redisSessionDAO = new RedisSessionDAO();
redisSessionDAO.setRedisManager(redisManager()); redisSessionDAO.setRedisManager(redisManager());
// redisSessionDAO.setSessionIdGenerator(new GavelSessionGenerator());
return redisSessionDAO; return redisSessionDAO;
} }
/** /**
* sessionManager * sessionManager
*/ */
// @ConditionalOnProperty(value="shiro.cache", havingValue="redis", matchIfMissing=false)
@Bean("sessionManager") @Bean("sessionManager")
public GavelSessionManager sessionManager() { public GavelSessionManager sessionManager() {
// DefaultWebSessionManager sessionManager = new DefaultWebSessionManager();
GavelSessionManager sessionManager = new GavelSessionManager(); GavelSessionManager sessionManager = new GavelSessionManager();
sessionManager.setGlobalSessionTimeout(Constants.liveMills); sessionManager.setGlobalSessionTimeout(Constants.liveMills);
sessionManager.setSessionDAO(redisSessionDAO()); if (StringUtils.equals(cacheType, "redis")){
sessionManager.setSessionDAO(redisSessionDAO());
}
return sessionManager; 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