|
|
@@ -1,8 +1,9 @@
|
|
|
package com.uas.eis.controller;
|
|
|
|
|
|
import com.uas.eis.core.support.TokenProperties;
|
|
|
-import com.uas.eis.entity.ErrorMsg;
|
|
|
-import com.uas.eis.exception.SystemException;
|
|
|
+import com.uas.eis.entity.ErrorMessage;
|
|
|
+import com.uas.eis.exception.ApiSystemException;
|
|
|
+import com.uas.eis.sdk.entity.ApiResult;
|
|
|
import com.uas.eis.utils.MD5Util;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -36,27 +37,47 @@ public class ApiSignLoginInterceptor extends HandlerInterceptorAdapter {
|
|
|
String accessSecret = tokenConfig.get(accessKey);
|
|
|
|
|
|
if (!StringUtils.isNumeric(timestamp)) {
|
|
|
- throw new SystemException(ErrorMsg.TIMESTAMP_ILLEGAL);
|
|
|
+ ApiResult apiResult = new ApiResult();
|
|
|
+ apiResult.setCode(ErrorMessage.TIMESTAMP_ILLEGAL.getCode());
|
|
|
+ apiResult.setMessage(ErrorMessage.TIMESTAMP_ILLEGAL.getMessage());
|
|
|
+ apiResult.setRequestId(requestId);
|
|
|
+ throw new ApiSystemException(apiResult);
|
|
|
}
|
|
|
|
|
|
// 检查KEY是否合理
|
|
|
if (StringUtils.isEmpty(accessKey) || StringUtils.isEmpty(accessSecret)) {
|
|
|
- throw new SystemException(ErrorMsg.ACCESSKEY_ILLEGAL);
|
|
|
+ ApiResult apiResult = new ApiResult();
|
|
|
+ apiResult.setCode(ErrorMessage.ACCESSKEY_ILLEGAL.getCode());
|
|
|
+ apiResult.setMessage(ErrorMessage.ACCESSKEY_ILLEGAL.getMessage());
|
|
|
+ apiResult.setRequestId(requestId);
|
|
|
+ throw new ApiSystemException(apiResult);
|
|
|
}
|
|
|
|
|
|
Long ts = Long.valueOf(timestamp);
|
|
|
// 禁止超时签名
|
|
|
if (System.currentTimeMillis() - ts > SIGN_EXPIRED_TIME) {
|
|
|
- throw new SystemException(ErrorMsg.TIMEOUT_ILLEGAL);
|
|
|
+ ApiResult apiResult = new ApiResult();
|
|
|
+ apiResult.setCode(ErrorMessage.TIMEOUT_ILLEGAL.getCode());
|
|
|
+ apiResult.setMessage(ErrorMessage.TIMEOUT_ILLEGAL.getMessage());
|
|
|
+ apiResult.setRequestId(requestId);
|
|
|
+ throw new ApiSystemException(apiResult);
|
|
|
}
|
|
|
|
|
|
String regex = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
|
|
|
if (!requestId.matches(regex)) {
|
|
|
- throw new SystemException(ErrorMsg.REQUESTID_ILLEGAL);
|
|
|
+ ApiResult apiResult = new ApiResult();
|
|
|
+ apiResult.setCode(ErrorMessage.REQUESTID_ILLEGAL.getCode());
|
|
|
+ apiResult.setMessage(ErrorMessage.REQUESTID_ILLEGAL.getMessage());
|
|
|
+ apiResult.setRequestId(requestId);
|
|
|
+ throw new ApiSystemException(apiResult);
|
|
|
}
|
|
|
|
|
|
if (!verificationSign(request, accessKey, accessSecret)) {
|
|
|
- throw new SystemException(ErrorMsg.SIGNATURE_ILLEGAL);
|
|
|
+ ApiResult apiResult = new ApiResult();
|
|
|
+ apiResult.setCode(ErrorMessage.SIGNATURE_ILLEGAL.getCode());
|
|
|
+ apiResult.setMessage(ErrorMessage.SIGNATURE_ILLEGAL.getMessage());
|
|
|
+ apiResult.setRequestId(requestId);
|
|
|
+ throw new ApiSystemException(apiResult);
|
|
|
}
|
|
|
return true;
|
|
|
}
|