|
@@ -33,14 +33,12 @@ import cn.com.qmth.examcloud.web.support.StatusResponse;
|
|
*/
|
|
*/
|
|
public final class EnterpriseAccessInterceptor implements HandlerInterceptor {
|
|
public final class EnterpriseAccessInterceptor implements HandlerInterceptor {
|
|
|
|
|
|
- private static final ExamCloudLog LOG = ExamCloudLogFactory
|
|
|
|
- .getLog(EnterpriseAccessInterceptor.class);
|
|
|
|
|
|
+ private static final ExamCloudLog LOG = ExamCloudLogFactory.getLog(EnterpriseAccessInterceptor.class);
|
|
|
|
|
|
/**
|
|
/**
|
|
* 接口日志
|
|
* 接口日志
|
|
*/
|
|
*/
|
|
- protected static final ExamCloudLog INTERFACE_LOG = ExamCloudLogFactory
|
|
|
|
- .getLog("INTERFACE_LOGGER");
|
|
|
|
|
|
+ protected static final ExamCloudLog INTERFACE_LOG = ExamCloudLogFactory.getLog("INTERFACE_LOGGER");
|
|
|
|
|
|
/**
|
|
/**
|
|
* redis client
|
|
* redis client
|
|
@@ -49,13 +47,24 @@ public final class EnterpriseAccessInterceptor implements HandlerInterceptor {
|
|
|
|
|
|
private CommonCloudService commonCloudService;
|
|
private CommonCloudService commonCloudService;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 构造函数
|
|
|
|
+ *
|
|
|
|
+ * @param redisClient
|
|
|
|
+ * @param commonCloudService
|
|
|
|
+ */
|
|
|
|
+ public EnterpriseAccessInterceptor(RedisClient redisClient, CommonCloudService commonCloudService) {
|
|
|
|
+ super();
|
|
|
|
+ this.redisClient = redisClient;
|
|
|
|
+ this.commonCloudService = commonCloudService;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
- public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
|
|
|
|
- Object handler) throws Exception {
|
|
|
|
|
|
+ public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
|
|
|
+ throws Exception {
|
|
LOG.debug("preHandle... ...");
|
|
LOG.debug("preHandle... ...");
|
|
|
|
|
|
- ApiInfo apiInfo = (ApiInfo) request
|
|
|
|
- .getAttribute(HttpServletRequestAttribute.$_API_INFO.name());
|
|
|
|
|
|
+ ApiInfo apiInfo = (ApiInfo) request.getAttribute(HttpServletRequestAttribute.$_API_INFO.name());
|
|
|
|
|
|
Class<?> ctrClass = apiInfo.getBeanType();
|
|
Class<?> ctrClass = apiInfo.getBeanType();
|
|
|
|
|
|
@@ -70,8 +79,7 @@ public final class EnterpriseAccessInterceptor implements HandlerInterceptor {
|
|
if (StringUtils.isBlank(appId)) {
|
|
if (StringUtils.isBlank(appId)) {
|
|
// 403
|
|
// 403
|
|
response.setStatus(HttpStatus.FORBIDDEN.value());
|
|
response.setStatus(HttpStatus.FORBIDDEN.value());
|
|
- ServletUtil.returnJson(new StatusResponse("403", "'App-Id'('appId') is blank"),
|
|
|
|
- response);
|
|
|
|
|
|
+ ServletUtil.returnJson(new StatusResponse("403", "'App-Id'('appId') is blank"), response);
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -82,8 +90,7 @@ public final class EnterpriseAccessInterceptor implements HandlerInterceptor {
|
|
if (StringUtils.isBlank(rootOrgId)) {
|
|
if (StringUtils.isBlank(rootOrgId)) {
|
|
// 403
|
|
// 403
|
|
response.setStatus(HttpStatus.FORBIDDEN.value());
|
|
response.setStatus(HttpStatus.FORBIDDEN.value());
|
|
- ServletUtil.returnJson(new StatusResponse("403", "'Root-Org-Id'('rootOrgId') is blank"),
|
|
|
|
- response);
|
|
|
|
|
|
+ ServletUtil.returnJson(new StatusResponse("403", "'Root-Org-Id'('rootOrgId') is blank"), response);
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
Long rootOrgIdLong = null;
|
|
Long rootOrgIdLong = null;
|
|
@@ -92,9 +99,7 @@ public final class EnterpriseAccessInterceptor implements HandlerInterceptor {
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
// 403
|
|
// 403
|
|
response.setStatus(HttpStatus.FORBIDDEN.value());
|
|
response.setStatus(HttpStatus.FORBIDDEN.value());
|
|
- ServletUtil.returnJson(
|
|
|
|
- new StatusResponse("403", "'Root-Org-Id'('rootOrgId') must be a long"),
|
|
|
|
- response);
|
|
|
|
|
|
+ ServletUtil.returnJson(new StatusResponse("403", "'Root-Org-Id'('rootOrgId') must be a long"), response);
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -105,8 +110,7 @@ public final class EnterpriseAccessInterceptor implements HandlerInterceptor {
|
|
if (StringUtils.isBlank(accessToken)) {
|
|
if (StringUtils.isBlank(accessToken)) {
|
|
// 403
|
|
// 403
|
|
response.setStatus(HttpStatus.FORBIDDEN.value());
|
|
response.setStatus(HttpStatus.FORBIDDEN.value());
|
|
- ServletUtil.returnJson(
|
|
|
|
- new StatusResponse("403", "'Access-Token'('access_token') is blank"), response);
|
|
|
|
|
|
+ ServletUtil.returnJson(new StatusResponse("403", "'Access-Token'('access_token') is blank"), response);
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -123,18 +127,15 @@ public final class EnterpriseAccessInterceptor implements HandlerInterceptor {
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
// 403
|
|
// 403
|
|
response.setStatus(HttpStatus.FORBIDDEN.value());
|
|
response.setStatus(HttpStatus.FORBIDDEN.value());
|
|
- ServletUtil.returnJson(new StatusResponse("403", "'timestamp' must be a long"),
|
|
|
|
- response);
|
|
|
|
|
|
+ ServletUtil.returnJson(new StatusResponse("403", "'timestamp' must be a long"), response);
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
- request.setAttribute(HttpServletRequestAttribute.$_ENTERPRISE_ROOT_ORG_ID.name(),
|
|
|
|
- rootOrgIdLong);
|
|
|
|
|
|
+ request.setAttribute(HttpServletRequestAttribute.$_ENTERPRISE_ROOT_ORG_ID.name(), rootOrgIdLong);
|
|
|
|
|
|
String key = "$_A_:" + rootOrgId + "_" + appId;
|
|
String key = "$_A_:" + rootOrgId + "_" + appId;
|
|
|
|
|
|
- ThirdPartyAccessBean thirdPartyAccessBean = redisClient.get(key,
|
|
|
|
- ThirdPartyAccessBean.class);
|
|
|
|
|
|
+ ThirdPartyAccessBean thirdPartyAccessBean = redisClient.get(key, ThirdPartyAccessBean.class);
|
|
|
|
|
|
if (null == thirdPartyAccessBean) {
|
|
if (null == thirdPartyAccessBean) {
|
|
thirdPartyAccessBean = getThirdPartyAccessInfo(rootOrgIdLong, appId);
|
|
thirdPartyAccessBean = getThirdPartyAccessInfo(rootOrgIdLong, appId);
|
|
@@ -159,8 +160,7 @@ public final class EnterpriseAccessInterceptor implements HandlerInterceptor {
|
|
if (!hexAscii.equalsIgnoreCase(accessToken)) {
|
|
if (!hexAscii.equalsIgnoreCase(accessToken)) {
|
|
// 403
|
|
// 403
|
|
response.setStatus(HttpStatus.FORBIDDEN.value());
|
|
response.setStatus(HttpStatus.FORBIDDEN.value());
|
|
- ServletUtil.returnJson(
|
|
|
|
- new StatusResponse("403", "'Access-Token'('access_token') is wrong"), response);
|
|
|
|
|
|
+ ServletUtil.returnJson(new StatusResponse("403", "'Access-Token'('access_token') is wrong"), response);
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -184,17 +184,9 @@ public final class EnterpriseAccessInterceptor implements HandlerInterceptor {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
|
|
|
|
- Object handler, Exception ex) throws Exception {
|
|
|
|
|
|
+ public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
|
|
|
|
+ throws Exception {
|
|
LOG.debug("afterCompletion... ...");
|
|
LOG.debug("afterCompletion... ...");
|
|
}
|
|
}
|
|
|
|
|
|
- public void setRedisClient(RedisClient redisClient) {
|
|
|
|
- this.redisClient = redisClient;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void setCommonCloudService(CommonCloudService commonCloudService) {
|
|
|
|
- this.commonCloudService = commonCloudService;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
}
|
|
}
|