修改代码

This commit is contained in:
刘倡
2025-07-11 14:42:27 +08:00
parent f37496a351
commit da03c0f02a
9 changed files with 41 additions and 98 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 {