WANG 5 年之前
父節點
當前提交
62e851a67b

+ 8 - 47
examcloud-exchange-starter/src/main/java/cn/com/qmth/examcloud/exchange/config/EnterpriseAccessInterceptor.java

@@ -15,12 +15,9 @@ import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
 import cn.com.qmth.examcloud.commons.util.ByteUtil;
 import cn.com.qmth.examcloud.commons.util.SHA256;
 import cn.com.qmth.examcloud.commons.util.StringUtil;
-import cn.com.qmth.examcloud.core.basic.api.CommonCloudService;
-import cn.com.qmth.examcloud.core.basic.api.bean.ThirdPartyAccessBean;
-import cn.com.qmth.examcloud.core.basic.api.request.GetThirdPartyAccessInfoReq;
-import cn.com.qmth.examcloud.core.basic.api.response.GetThirdPartyAccessInfoResp;
+import cn.com.qmth.examcloud.support.cache.CacheHelper;
+import cn.com.qmth.examcloud.support.cache.bean.ThirdPartyAccessCacheBean;
 import cn.com.qmth.examcloud.web.enums.HttpServletRequestAttribute;
-import cn.com.qmth.examcloud.web.redis.RedisClient;
 import cn.com.qmth.examcloud.web.support.ApiInfo;
 import cn.com.qmth.examcloud.web.support.ServletUtil;
 import cn.com.qmth.examcloud.web.support.StatusResponse;
@@ -43,26 +40,6 @@ public final class EnterpriseAccessInterceptor implements HandlerInterceptor {
 	protected static final ExamCloudLog INTERFACE_LOG = ExamCloudLogFactory
 			.getLog("INTERFACE_LOGGER");
 
-	/**
-	 * redis client
-	 */
-	private RedisClient redisClient;
-
-	private CommonCloudService commonCloudService;
-
-	/**
-	 * 构造函数
-	 * 
-	 * @param redisClient
-	 * @param commonCloudService
-	 */
-	public EnterpriseAccessInterceptor(RedisClient redisClient,
-			CommonCloudService commonCloudService) {
-		super();
-		this.redisClient = redisClient;
-		this.commonCloudService = commonCloudService;
-	}
-
 	@Override
 	public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
 			Object handler) throws Exception {
@@ -148,19 +125,13 @@ public final class EnterpriseAccessInterceptor implements HandlerInterceptor {
 		request.setAttribute(HttpServletRequestAttribute.$_ENTERPRISE_ROOT_ORG_ID.name(),
 				rootOrgIdLong);
 
-		String key = "$_A_:" + rootOrgId + "_" + appId;
-
-		ThirdPartyAccessBean thirdPartyAccessBean = redisClient.get(key,
-				ThirdPartyAccessBean.class);
-
-		if (null == thirdPartyAccessBean) {
-			thirdPartyAccessBean = getThirdPartyAccessInfo(rootOrgIdLong, appId);
-			redisClient.set(key, thirdPartyAccessBean, 60 * 5);
-		}
+		ThirdPartyAccessCacheBean thirdPartyAccessCacheBean = CacheHelper
+				.getThirdPartyAccess(rootOrgIdLong, appId);
 
-		if (null != thirdPartyAccessBean.getTimeRange()) {
+		if (null != thirdPartyAccessCacheBean.getTimeRange()) {
 			long currentTimeMillis = System.currentTimeMillis();
-			if (Math.abs(currentTimeMillis - timestampLong) > thirdPartyAccessBean.getTimeRange()) {
+			if (Math.abs(currentTimeMillis - timestampLong) > thirdPartyAccessCacheBean
+					.getTimeRange()) {
 				// 403
 				response.setStatus(HttpStatus.FORBIDDEN.value());
 				ServletUtil.returnJson(new StatusResponse("403", "timestamp is out"), response);
@@ -168,7 +139,7 @@ public final class EnterpriseAccessInterceptor implements HandlerInterceptor {
 			}
 		}
 
-		String secretKey = thirdPartyAccessBean.getSecretKey();
+		String secretKey = thirdPartyAccessCacheBean.getSecretKey();
 		String joinStr = StringUtil.join(rootOrgId, appId, timestamp, secretKey);
 		byte[] bytes = SHA256.encode(joinStr);
 		String hexAscii = ByteUtil.toHexAscii(bytes);
@@ -186,16 +157,6 @@ public final class EnterpriseAccessInterceptor implements HandlerInterceptor {
 		return true;
 	}
 
-	private ThirdPartyAccessBean getThirdPartyAccessInfo(Long rootOrgId, String appId) {
-		ThirdPartyAccessBean thirdPartyAccessBean;
-		GetThirdPartyAccessInfoReq req = new GetThirdPartyAccessInfoReq();
-		req.setAppId(appId);
-		req.setRootOrgId(rootOrgId);
-		GetThirdPartyAccessInfoResp resp = commonCloudService.getThirdPartyAccessInfo(req);
-		thirdPartyAccessBean = resp.getThirdPartyAccessBean();
-		return thirdPartyAccessBean;
-	}
-
 	@Override
 	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
 			ModelAndView modelAndView) throws Exception {

+ 1 - 6
examcloud-exchange-starter/src/main/java/cn/com/qmth/examcloud/exchange/config/ExamCloudWebMvcConfigurer.java

@@ -6,7 +6,6 @@ import org.springframework.web.servlet.config.annotation.CorsRegistry;
 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
-import cn.com.qmth.examcloud.core.basic.api.CommonCloudService;
 import cn.com.qmth.examcloud.web.interceptor.ApiStatisticInterceptor;
 import cn.com.qmth.examcloud.web.interceptor.FirstInterceptor;
 import cn.com.qmth.examcloud.web.interceptor.SeqlockInterceptor;
@@ -28,17 +27,13 @@ public class ExamCloudWebMvcConfigurer implements WebMvcConfigurer {
 	@Autowired
 	ResourceManager resourceManager;
 
-	@Autowired
-	CommonCloudService commonCloudService;
-
 	@Autowired
 	RedisClient redisClient;
 
 	@Override
 	public void addInterceptors(InterceptorRegistry registry) {
 		registry.addInterceptor(new FirstInterceptor()).addPathPatterns("/**");
-		registry.addInterceptor(new EnterpriseAccessInterceptor(redisClient, commonCloudService))
-				.addPathPatterns("/**");
+		registry.addInterceptor(new EnterpriseAccessInterceptor()).addPathPatterns("/**");
 		registry.addInterceptor(new RpcInterceptor(resourceManager)).addPathPatterns("/**");
 
 		RequestPermissionInterceptor permissionInterceptor = new RequestPermissionInterceptor(