【fix sonar】ShiroConfig文件
This commit is contained in:
+14
-11
@@ -1,5 +1,9 @@
|
||||
package com.jero.config.shiro;
|
||||
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.config.shiro.filters.CustomShiroFilterFactoryBean;
|
||||
import com.jero.config.shiro.filters.JwtFilter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
import org.apache.shiro.mgt.DefaultSessionStorageEvaluator;
|
||||
@@ -13,17 +17,13 @@ import org.crazycake.shiro.IRedisManager;
|
||||
import org.crazycake.shiro.RedisCacheManager;
|
||||
import org.crazycake.shiro.RedisClusterManager;
|
||||
import org.crazycake.shiro.RedisManager;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.config.shiro.filters.CustomShiroFilterFactoryBean;
|
||||
import com.jero.config.shiro.filters.JwtFilter;
|
||||
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.data.redis.connection.RedisClusterConfiguration;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.util.StringUtils;
|
||||
import redis.clients.jedis.HostAndPort;
|
||||
@@ -47,7 +47,7 @@ public class ShiroConfig {
|
||||
private String excludeUrls;
|
||||
@Resource
|
||||
LettuceConnectionFactory lettuceConnectionFactory;
|
||||
@Autowired
|
||||
@Resource
|
||||
private Environment env;
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ public class ShiroConfig {
|
||||
CustomShiroFilterFactoryBean shiroFilterFactoryBean = new CustomShiroFilterFactoryBean();
|
||||
shiroFilterFactoryBean.setSecurityManager(securityManager);
|
||||
// 拦截器
|
||||
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>();
|
||||
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
|
||||
if(oConvertUtils.isNotEmpty(excludeUrls)){
|
||||
String[] permissionUrl = excludeUrls.split(",");
|
||||
for(String url : permissionUrl){
|
||||
@@ -134,7 +134,7 @@ public class ShiroConfig {
|
||||
filterChainDefinitionMap.put("/actuator/**", "anon");
|
||||
|
||||
// 添加自己的过滤器并且取名为jwt
|
||||
Map<String, Filter> filterMap = new HashMap<String, Filter>(1);
|
||||
Map<String, Filter> filterMap = new HashMap<>(1);
|
||||
//如果cloudServer为空 则说明是单体 需要加载跨域配置【微服务跨域切换】
|
||||
Object cloudServer = env.getProperty(CommonConstant.CLOUD_SERVER_KEY);
|
||||
filterMap.put("jwt", new JwtFilter(cloudServer==null));
|
||||
@@ -227,7 +227,8 @@ public class ShiroConfig {
|
||||
log.info("===============(2)创建RedisManager,连接Redis..");
|
||||
IRedisManager manager;
|
||||
// redis 单机支持,在集群为空,或者集群无机器时候使用 add by jzyadmin@163.com
|
||||
if (lettuceConnectionFactory.getClusterConfiguration() == null || lettuceConnectionFactory.getClusterConfiguration().getClusterNodes().isEmpty()) {
|
||||
RedisClusterConfiguration redisClusterConfiguration = lettuceConnectionFactory.getClusterConfiguration();
|
||||
if (lettuceConnectionFactory.getClusterConfiguration() == null || (!Objects.isNull(redisClusterConfiguration) && redisClusterConfiguration.getClusterNodes().isEmpty())) {
|
||||
RedisManager redisManager = new RedisManager();
|
||||
redisManager.setHost(lettuceConnectionFactory.getHostName());
|
||||
redisManager.setPort(lettuceConnectionFactory.getPort());
|
||||
@@ -241,11 +242,13 @@ public class ShiroConfig {
|
||||
// redis集群支持,优先使用集群配置
|
||||
RedisClusterManager redisManager = new RedisClusterManager();
|
||||
Set<HostAndPort> portSet = new HashSet<>();
|
||||
lettuceConnectionFactory.getClusterConfiguration().getClusterNodes().forEach(node -> portSet.add(new HostAndPort(node.getHost() , node.getPort())));
|
||||
if(!Objects.isNull(redisClusterConfiguration)){
|
||||
redisClusterConfiguration.getClusterNodes().forEach(node -> portSet.add(new HostAndPort(node.getHost() , node.getPort())));
|
||||
}
|
||||
//update-begin--Author:scott Date:20210531 for:修改集群模式下未设置redis密码的bug issues/I3QNIC
|
||||
if (oConvertUtils.isNotEmpty(lettuceConnectionFactory.getPassword())) {
|
||||
JedisCluster jedisCluster = new JedisCluster(portSet, 2000, 2000, 5,
|
||||
lettuceConnectionFactory.getPassword(), new GenericObjectPoolConfig());
|
||||
lettuceConnectionFactory.getPassword(), new GenericObjectPoolConfig<>());
|
||||
redisManager.setPassword(lettuceConnectionFactory.getPassword());
|
||||
redisManager.setJedisCluster(jedisCluster);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user