Merge remote-tracking branch 'origin/master'

This commit is contained in:
efren
2025-07-18 08:35:38 +08:00
11 changed files with 65 additions and 120 deletions

View File

@ -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.ExternalAllows;
import com.chinaunicom.mall.ebtp.cloud.security.starter.entity.RoleCodeAuthority; 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.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.entity.CheckTokenVo;
import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.service.UserInfoService; import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.service.UserInfoService;
import com.chinaunicom.mall.ebtp.common.base.entity.BaseCacheUser; 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 * @author Ajaxfan
*/ */
@Slf4j @Slf4j
@Component //@Component
public class TokenAuthenticationFilter extends OncePerRequestFilter { public class TokenAuthenticationFilter extends OncePerRequestFilter {
@Autowired @Autowired
private UserInfoService client; private UserInfoService client;
@ -55,9 +54,6 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
@Autowired @Autowired
private ExternalAllows eAllows; private ExternalAllows eAllows;
@Autowired
private EbtpUserInfoClient ebtpClient;
@Autowired(required = false) @Autowired(required = false)
@Qualifier("userinfoRedisTemplate") @Qualifier("userinfoRedisTemplate")
private RedisTemplate<String, Object> redisTemplate; private RedisTemplate<String, Object> redisTemplate;

View File

@ -17,9 +17,9 @@ import org.springframework.web.client.RestTemplate;
@ComponentScan(basePackages = "com.chinaunicom.mall.ebtp.cloud.userinfo.starter") @ComponentScan(basePackages = "com.chinaunicom.mall.ebtp.cloud.userinfo.starter")
public class UserinfoStarterConfiguration { public class UserinfoStarterConfiguration {
@Bean // @Bean
public RestTemplate restTemplate() { // public RestTemplate restTemplate() {
return new RestTemplate(); // return new RestTemplate();
} // }
} }

View File

@ -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<Boolean> refreshToken();
/**
* 获取配置信息
* @return
*/
@GetMapping("/v1/checkToken/getCheckTokenVo")
public BaseResponse<CheckTokenVo> getCheckTokenVo(@RequestParam("ps") String ps);
}

View File

@ -1,8 +1,11 @@
package com.chinaunicom.mall.ebtp.cloud.userinfo.starter.client; 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.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.cloud.userinfo.starter.fallback.UnifastOAuthClientFallbackFactory;
import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@ -12,7 +15,7 @@ import org.springframework.web.bind.annotation.RequestParam;
* *
* @author Ajaxfan * @author Ajaxfan
*/ */
@FeignClient(value = "${user.auth.resource.serviceId:sys-manager-ebtp-project}", @FeignClient(value = "sys-manager-ebtp-project",
fallbackFactory = UnifastOAuthClientFallbackFactory.class) fallbackFactory = UnifastOAuthClientFallbackFactory.class)
public interface UnifastOAuthClient { public interface UnifastOAuthClient {
@ -22,4 +25,19 @@ public interface UnifastOAuthClient {
@PostMapping("/v1/userinfo/oauth/check_token") @PostMapping("/v1/userinfo/oauth/check_token")
SecurityEntity getPost(@RequestParam("token") String token); SecurityEntity getPost(@RequestParam("token") String token);
/**
* 刷新redis缓存的信息
*
* @return
*/
@PostMapping("/v1/userinfo/refresh")
public ResponseEntity<Boolean> refreshToken();
/**
* 获取配置信息
* @return
*/
@GetMapping("/v1/checkToken/getCheckTokenVo")
public BaseResponse<CheckTokenVo> getCheckTokenVo(@RequestParam("ps") String ps);
} }

View File

@ -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<Boolean> refreshToken() {
return null;
}
@Override
public BaseResponse<CheckTokenVo> getCheckTokenVo(String ps) {
return null;
}
}

View File

@ -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<EbtpUserInfoClient> {
@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);
// }
}

View File

@ -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.security.starter.entity.SecurityEntity;
import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.client.UnifastOAuthClient; 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; import org.springframework.stereotype.Component;
@Component @Component
@ -17,4 +20,14 @@ public class UnifastOAuthClientFallback implements UnifastOAuthClient {
return null; return null;
} }
@Override
public ResponseEntity<Boolean> refreshToken() {
return null;
}
@Override
public BaseResponse<CheckTokenVo> getCheckTokenVo(String ps) {
return null;
}
} }

View File

@ -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.AuthorityEntity;
import com.chinaunicom.mall.ebtp.cloud.security.starter.entity.SecurityEntity; 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.client.UnifastOAuthClient;
import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.entity.CheckTokenVo; 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.cloud.userinfo.starter.service.UserInfoService;
@ -44,9 +43,6 @@ private Integer valid_time_limit;
@Qualifier("userinfoRedisTemplate") @Qualifier("userinfoRedisTemplate")
private RedisTemplate<String, Object> redisTemplate; private RedisTemplate<String, Object> redisTemplate;
@Autowired
private EbtpUserInfoClient ebtpClient;
@Override @Override
public BaseCacheUser getUserInfo(String token) { public BaseCacheUser getUserInfo(String token) {
token = token.replaceAll(TOKEN_PREFIX, ""); token = token.replaceAll(TOKEN_PREFIX, "");
@ -213,7 +209,7 @@ private Integer valid_time_limit;
if (o != null) { if (o != null) {
return (CheckTokenVo)o; return (CheckTokenVo)o;
}else{ }else{
BaseResponse<CheckTokenVo> baseResponse = ebtpClient.getCheckTokenVo("eshop@2024"); BaseResponse<CheckTokenVo> baseResponse = client.getCheckTokenVo("eshop@2024");
//log.info("responseEntity:" + baseResponse); //log.info("responseEntity:" + baseResponse);
if (baseResponse.getData() != null) { if (baseResponse.getData() != null) {
//log.info("responseEntity.getBody():" + baseResponse.getData()); //log.info("responseEntity.getBody():" + baseResponse.getData());

View File

@ -4,6 +4,7 @@ import com.chinaunicom.mall.ebtp.common.util.JsonUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer; import org.springframework.scheduling.annotation.AsyncConfigurer;
@ -21,6 +22,7 @@ import java.util.concurrent.Executor;
@Configuration @Configuration
@EnableAsync @EnableAsync
@EnableConfigurationProperties(AsyncProperties.class) @EnableConfigurationProperties(AsyncProperties.class)
@ConditionalOnProperty(prefix = "async.thead.pool", name = "core-size", matchIfMissing = false)
@Slf4j @Slf4j
public class AsyncConfig implements AsyncConfigurer { public class AsyncConfig implements AsyncConfigurer {

View File

@ -15,8 +15,10 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
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.data.redis.connection.RedisConnectionFactory; 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.RedisNode;
import org.springframework.data.redis.connection.RedisSentinelConfiguration; 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.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisOperations; import org.springframework.data.redis.core.RedisOperations;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
@ -69,10 +71,26 @@ public class RedisLettuceConfig {
} }
private LettuceConnectionFactory getLettuceConnectionFactory(Integer db) { private LettuceConnectionFactory getLettuceConnectionFactory(Integer db) {
LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(this.sentinelConfig()); LettuceConnectionFactory factory;
lettuceConnectionFactory.setDatabase(db); if (redisProperties.getCluster() != null && redisProperties.getCluster().getNodes() != null && !redisProperties.getCluster().getNodes().isEmpty()) {
lettuceConnectionFactory.afterPropertiesSet(); // 集群模式
return lettuceConnectionFactory; 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() { private RedisSentinelConfiguration sentinelConfig() {

View File

@ -75,24 +75,6 @@ spring:
sasl.mechanism: SCRAM-SHA-256 sasl.mechanism: SCRAM-SHA-256
sasl.jaas.config: org.apache.kafka.common.security.scram.ScramLoginModule required username="jltest" password="Unicom#123"; 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: mybatis-plus:
configuration: configuration:
# 是否开启自动驼峰命名规则映射:从数据库列名到Java属性驼峰命名的类似映射 # 是否开启自动驼峰命名规则映射:从数据库列名到Java属性驼峰命名的类似映射
@ -123,6 +105,8 @@ hystrix:
forceClosed: true forceClosed: true
ribbon: ribbon:
eureka:
enabled: false
ReadTimeout: 20000 #请求处理的超时时间 ReadTimeout: 20000 #请求处理的超时时间
ConnectTimeout: 20000 #请求连接超时时间 ConnectTimeout: 20000 #请求连接超时时间
MaxAutoRetries: 0 #对当前实例的重试次数 MaxAutoRetries: 0 #对当前实例的重试次数