diff --git a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/security/starter/filter/TokenAuthenticationFilter.java b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/security/starter/filter/TokenAuthenticationFilter.java index 1230702..f56b35e 100644 --- a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/security/starter/filter/TokenAuthenticationFilter.java +++ b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/security/starter/filter/TokenAuthenticationFilter.java @@ -8,7 +8,6 @@ import com.chinaunicom.mall.ebtp.cloud.security.starter.entity.AuthAllows; import com.chinaunicom.mall.ebtp.cloud.security.starter.entity.ExternalAllows; import com.chinaunicom.mall.ebtp.cloud.security.starter.entity.RoleCodeAuthority; import com.chinaunicom.mall.ebtp.cloud.security.starter.entity.SecurityUser; -import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.client.EbtpUserInfoClient; import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.entity.CheckTokenVo; import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.service.UserInfoService; import com.chinaunicom.mall.ebtp.common.base.entity.BaseCacheUser; @@ -45,7 +44,7 @@ import static com.chinaunicom.mall.ebtp.cloud.security.starter.common.Constants. * @author Ajaxfan */ @Slf4j -@Component +//@Component public class TokenAuthenticationFilter extends OncePerRequestFilter { @Autowired private UserInfoService client; @@ -55,9 +54,6 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter { @Autowired private ExternalAllows eAllows; - @Autowired - private EbtpUserInfoClient ebtpClient; - @Autowired(required = false) @Qualifier("userinfoRedisTemplate") private RedisTemplate redisTemplate; diff --git a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/userinfo/starter/UserinfoStarterConfiguration.java b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/userinfo/starter/UserinfoStarterConfiguration.java index aa6c610..d60f2a3 100644 --- a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/userinfo/starter/UserinfoStarterConfiguration.java +++ b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/userinfo/starter/UserinfoStarterConfiguration.java @@ -17,9 +17,9 @@ import org.springframework.web.client.RestTemplate; @ComponentScan(basePackages = "com.chinaunicom.mall.ebtp.cloud.userinfo.starter") public class UserinfoStarterConfiguration { - @Bean - public RestTemplate restTemplate() { - return new RestTemplate(); - } +// @Bean +// public RestTemplate restTemplate() { +// return new RestTemplate(); +// } } diff --git a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/userinfo/starter/client/EbtpUserInfoClient.java b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/userinfo/starter/client/EbtpUserInfoClient.java deleted file mode 100644 index 49b4af6..0000000 --- a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/userinfo/starter/client/EbtpUserInfoClient.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.chinaunicom.mall.ebtp.cloud.userinfo.starter.client; - -import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.entity.CheckTokenVo; -import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.fallback.EbtpUserInfoClientFallbackFactory; -import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse; -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Service; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestParam; - -/** - * 文档中心数据服务客户端 - * - * @author Ajaxfan - */ -@FeignClient(value = "sys-manager-ebtp-project") -public interface EbtpUserInfoClient { - - /** - * 刷新redis缓存的信息 - * - * @return - */ - @PostMapping("/v1/userinfo/refresh") - public ResponseEntity refreshToken(); - - /** - * 获取配置信息 - * @return - */ - @GetMapping("/v1/checkToken/getCheckTokenVo") - public BaseResponse getCheckTokenVo(@RequestParam("ps") String ps); -} diff --git a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/userinfo/starter/client/UnifastOAuthClient.java b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/userinfo/starter/client/UnifastOAuthClient.java index 42d5007..202802b 100644 --- a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/userinfo/starter/client/UnifastOAuthClient.java +++ b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/userinfo/starter/client/UnifastOAuthClient.java @@ -1,18 +1,21 @@ package com.chinaunicom.mall.ebtp.cloud.userinfo.starter.client; import com.chinaunicom.mall.ebtp.cloud.security.starter.entity.SecurityEntity; +import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.entity.CheckTokenVo; import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.fallback.UnifastOAuthClientFallbackFactory; +import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse; import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; /** * 文档中心数据服务客户端 - * + * * @author Ajaxfan */ -@FeignClient(value = "${user.auth.resource.serviceId:sys-manager-ebtp-project}", +@FeignClient(value = "sys-manager-ebtp-project", fallbackFactory = UnifastOAuthClientFallbackFactory.class) public interface UnifastOAuthClient { @@ -22,4 +25,19 @@ public interface UnifastOAuthClient { @PostMapping("/v1/userinfo/oauth/check_token") SecurityEntity getPost(@RequestParam("token") String token); + /** + * 刷新redis缓存的信息 + * + * @return + */ + @PostMapping("/v1/userinfo/refresh") + public ResponseEntity refreshToken(); + + /** + * 获取配置信息 + * @return + */ + @GetMapping("/v1/checkToken/getCheckTokenVo") + public BaseResponse getCheckTokenVo(@RequestParam("ps") String ps); + } diff --git a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/userinfo/starter/fallback/EbtpUserInfoClientFallback.java b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/userinfo/starter/fallback/EbtpUserInfoClientFallback.java deleted file mode 100644 index 9f919e6..0000000 --- a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/userinfo/starter/fallback/EbtpUserInfoClientFallback.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.chinaunicom.mall.ebtp.cloud.userinfo.starter.fallback; - -import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.client.EbtpUserInfoClient; -import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.entity.CheckTokenVo; -import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Component; - -@Component -public class EbtpUserInfoClientFallback implements EbtpUserInfoClient { - - - @Override - public ResponseEntity refreshToken() { - return null; - } - - @Override - public BaseResponse getCheckTokenVo(String ps) { - return null; - } -} diff --git a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/userinfo/starter/fallback/EbtpUserInfoClientFallbackFactory.java b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/userinfo/starter/fallback/EbtpUserInfoClientFallbackFactory.java deleted file mode 100644 index f9c77e0..0000000 --- a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/userinfo/starter/fallback/EbtpUserInfoClientFallbackFactory.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.chinaunicom.mall.ebtp.cloud.userinfo.starter.fallback; - -import com.chinaunicom.mall.ebtp.cloud.security.starter.entity.SecurityEntity; -import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.client.EbtpUserInfoClient; -import feign.hystrix.FallbackFactory; -import lombok.extern.slf4j.Slf4j; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Component; - -@Slf4j -@Component -public class EbtpUserInfoClientFallbackFactory implements FallbackFactory { - @Override - public EbtpUserInfoClient create(Throwable throwable) { - log.error("EbtpUserInfoClient error : " + throwable.getMessage()); - return new EbtpUserInfoClientFallback(); - } - -// @Override -// public EbtpUserInfoClient create(Throwable throwable) { -// log.error("EbtpUserInfoClient error : " + throwable.getMessage()); -// return () -> ResponseEntity.ok(null); -// } - -} diff --git a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/userinfo/starter/fallback/UnifastOAuthClientFallback.java b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/userinfo/starter/fallback/UnifastOAuthClientFallback.java index d02c2a3..3b70cc9 100644 --- a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/userinfo/starter/fallback/UnifastOAuthClientFallback.java +++ b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/userinfo/starter/fallback/UnifastOAuthClientFallback.java @@ -2,6 +2,9 @@ package com.chinaunicom.mall.ebtp.cloud.userinfo.starter.fallback; import com.chinaunicom.mall.ebtp.cloud.security.starter.entity.SecurityEntity; import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.client.UnifastOAuthClient; +import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.entity.CheckTokenVo; +import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; @Component @@ -17,4 +20,14 @@ public class UnifastOAuthClientFallback implements UnifastOAuthClient { return null; } + @Override + public ResponseEntity refreshToken() { + return null; + } + + @Override + public BaseResponse getCheckTokenVo(String ps) { + return null; + } + } diff --git a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/userinfo/starter/service/impl/UserInfoServiceImpl.java b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/userinfo/starter/service/impl/UserInfoServiceImpl.java index 3a99a48..79fc3c1 100644 --- a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/userinfo/starter/service/impl/UserInfoServiceImpl.java +++ b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/cloud/userinfo/starter/service/impl/UserInfoServiceImpl.java @@ -22,7 +22,6 @@ import org.springframework.stereotype.Service; import com.chinaunicom.mall.ebtp.cloud.security.starter.entity.AuthorityEntity; import com.chinaunicom.mall.ebtp.cloud.security.starter.entity.SecurityEntity; -import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.client.EbtpUserInfoClient; import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.client.UnifastOAuthClient; import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.entity.CheckTokenVo; import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.service.UserInfoService; @@ -44,9 +43,6 @@ private Integer valid_time_limit; @Qualifier("userinfoRedisTemplate") private RedisTemplate redisTemplate; - @Autowired - private EbtpUserInfoClient ebtpClient; - @Override public BaseCacheUser getUserInfo(String token) { token = token.replaceAll(TOKEN_PREFIX, ""); @@ -213,7 +209,7 @@ private Integer valid_time_limit; if (o != null) { return (CheckTokenVo)o; }else{ - BaseResponse baseResponse = ebtpClient.getCheckTokenVo("eshop@2024"); + BaseResponse baseResponse = client.getCheckTokenVo("eshop@2024"); //log.info("responseEntity:" + baseResponse); if (baseResponse.getData() != null) { //log.info("responseEntity.getBody():" + baseResponse.getData()); diff --git a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/config/AsyncConfig.java b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/config/AsyncConfig.java index 18276ec..74060ac 100644 --- a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/config/AsyncConfig.java +++ b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/config/AsyncConfig.java @@ -4,6 +4,7 @@ import com.chinaunicom.mall.ebtp.common.util.JsonUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.AsyncConfigurer; @@ -21,6 +22,7 @@ import java.util.concurrent.Executor; @Configuration @EnableAsync @EnableConfigurationProperties(AsyncProperties.class) +@ConditionalOnProperty(prefix = "async.thead.pool", name = "core-size", matchIfMissing = false) @Slf4j public class AsyncConfig implements AsyncConfigurer { diff --git a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/config/RedisLettuceConfig.java b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/config/RedisLettuceConfig.java index fe6f043..58d4995 100644 --- a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/config/RedisLettuceConfig.java +++ b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/config/RedisLettuceConfig.java @@ -15,8 +15,10 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.connection.RedisClusterConfiguration; import org.springframework.data.redis.connection.RedisNode; import org.springframework.data.redis.connection.RedisSentinelConfiguration; +import org.springframework.data.redis.connection.RedisStandaloneConfiguration; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.core.RedisOperations; import org.springframework.data.redis.core.RedisTemplate; @@ -69,10 +71,26 @@ public class RedisLettuceConfig { } private LettuceConnectionFactory getLettuceConnectionFactory(Integer db) { - LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(this.sentinelConfig()); - lettuceConnectionFactory.setDatabase(db); - lettuceConnectionFactory.afterPropertiesSet(); - return lettuceConnectionFactory; + LettuceConnectionFactory factory; + if (redisProperties.getCluster() != null && redisProperties.getCluster().getNodes() != null && !redisProperties.getCluster().getNodes().isEmpty()) { + // 集群模式 + RedisClusterConfiguration clusterConfig = new RedisClusterConfiguration(redisProperties.getCluster().getNodes()); + clusterConfig.setPassword(redisProperties.getPassword()); + factory = new LettuceConnectionFactory(clusterConfig); + } else if (redisProperties.getSentinel() != null && redisProperties.getSentinel().getNodes() != null && !redisProperties.getSentinel().getNodes().isEmpty()) { + // 哨兵模式 + factory = new LettuceConnectionFactory(this.sentinelConfig()); + } else { + // 单机模式 + RedisStandaloneConfiguration standaloneConfig = new RedisStandaloneConfiguration(); + standaloneConfig.setHostName(redisProperties.getHost()); + standaloneConfig.setPort(redisProperties.getPort()); + standaloneConfig.setPassword(redisProperties.getPassword()); + factory = new LettuceConnectionFactory(standaloneConfig); + } + factory.setDatabase(db); + factory.afterPropertiesSet(); + return factory; } private RedisSentinelConfiguration sentinelConfig() { diff --git a/uboot-common/src/main/resources/application-common.yml b/uboot-common/src/main/resources/application-common.yml index fa6c82a..fe3ab36 100644 --- a/uboot-common/src/main/resources/application-common.yml +++ b/uboot-common/src/main/resources/application-common.yml @@ -75,24 +75,6 @@ spring: sasl.mechanism: SCRAM-SHA-256 sasl.jaas.config: org.apache.kafka.common.security.scram.ScramLoginModule required username="jltest" password="Unicom#123"; - # 天宫 redis 需要使用哨兵进行访问 - redis: - sentinel: - master: eshop-redis - nodes: 10.125.164.124:32718, 10.125.164.118:32716, 10.125.164.121:32716 - password: Unicom#135 - -# 天宫Eureka配置 -eureka: - client: - service-url: - defaultZone: http://10.242.37.148:5001/eureka - instance: - prefer-ip-address: true - ip-address: 125.32.114.204 - hostname: 125.32.114.204 - instance-ip: 125.32.114.204:${server.port} - mybatis-plus: configuration: # 是否开启自动驼峰命名规则映射:从数据库列名到Java属性驼峰命名的类似映射 @@ -123,6 +105,8 @@ hystrix: forceClosed: true ribbon: + eureka: + enabled: false ReadTimeout: 20000 #请求处理的超时时间 ConnectTimeout: 20000 #请求连接超时时间 MaxAutoRetries: 0 #对当前实例的重试次数