|
@@ -33,12 +33,14 @@ 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
|
|
@@ -53,22 +55,27 @@ public final class EnterpriseAccessInterceptor implements HandlerInterceptor {
|
|
* @param redisClient
|
|
* @param redisClient
|
|
* @param commonCloudService
|
|
* @param commonCloudService
|
|
*/
|
|
*/
|
|
- public EnterpriseAccessInterceptor(RedisClient redisClient, CommonCloudService commonCloudService) {
|
|
|
|
|
|
+ public EnterpriseAccessInterceptor(RedisClient redisClient,
|
|
|
|
+ CommonCloudService commonCloudService) {
|
|
super();
|
|
super();
|
|
this.redisClient = redisClient;
|
|
this.redisClient = redisClient;
|
|
this.commonCloudService = commonCloudService;
|
|
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();
|
|
|
|
-
|
|
|
|
- if (!EnterpriseService.class.isAssignableFrom(ctrClass)) {
|
|
|
|
|
|
+ if (null != apiInfo) {
|
|
|
|
+ Class<?> ctrClass = apiInfo.getBeanType();
|
|
|
|
+ if (!EnterpriseService.class.isAssignableFrom(ctrClass)) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -79,7 +86,8 @@ 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;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -90,7 +98,8 @@ 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;
|
|
@@ -99,7 +108,9 @@ 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;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -110,7 +121,8 @@ 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;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -127,15 +139,18 @@ 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);
|
|
@@ -160,7 +175,8 @@ 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,8 +200,8 @@ 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... ...");
|
|
}
|
|
}
|
|
|
|
|