|
@@ -2,6 +2,7 @@ package com.railway.framework.security.advice;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.railway.common.core.domain.AjaxResult;
|
|
import com.railway.common.core.domain.AjaxResult;
|
|
|
|
|
+import com.railway.common.core.domain.dto.ReturnCode;
|
|
|
import com.railway.common.exception.sign.SignException;
|
|
import com.railway.common.exception.sign.SignException;
|
|
|
import com.railway.common.utils.JsonUtil;
|
|
import com.railway.common.utils.JsonUtil;
|
|
|
import com.railway.common.utils.StringUtils;
|
|
import com.railway.common.utils.StringUtils;
|
|
@@ -49,10 +50,10 @@ public class SecretRequestAdvice extends RequestBodyAdviceAdapter {
|
|
|
@Override
|
|
@Override
|
|
|
public boolean supports(@NonNull MethodParameter methodParameter, @NonNull Type targetType,
|
|
public boolean supports(@NonNull MethodParameter methodParameter, @NonNull Type targetType,
|
|
|
@NonNull Class<? extends HttpMessageConverter<?>> converterType) {
|
|
@NonNull Class<? extends HttpMessageConverter<?>> converterType) {
|
|
|
- String[] servletPath = methodParameter.getContainingClass().getAnnotation(RequestMapping.class)
|
|
|
|
|
|
|
+ String[] ignorePath = methodParameter.getContainingClass().getAnnotation(RequestMapping.class)
|
|
|
.value();
|
|
.value();
|
|
|
- return !StringUtils.isNotEmpty(servletPath)
|
|
|
|
|
- || !INeedSignCheck.SIGN_IGNORE_URLS.contains(servletPath[0]);
|
|
|
|
|
|
|
+ return StringUtils.isEmpty(ignorePath)
|
|
|
|
|
+ || !INeedSignCheck.SIGN_IGNORE_URLS.contains(ignorePath[0]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -113,23 +114,26 @@ public class SecretRequestAdvice extends RequestBodyAdviceAdapter {
|
|
|
JSONObject json = JSONObject.parseObject(requestData);
|
|
JSONObject json = JSONObject.parseObject(requestData);
|
|
|
Map<String, String> requestMap = JsonUtil.json2Map(json);
|
|
Map<String, String> requestMap = JsonUtil.json2Map(json);
|
|
|
String requestId = UUID.randomUUID().toString();
|
|
String requestId = UUID.randomUUID().toString();
|
|
|
|
|
+ // 验证时间戳
|
|
|
AjaxResult ajaxResult = SignatureUtil.checkTimestamp(requestId, userTimestamp);
|
|
AjaxResult ajaxResult = SignatureUtil.checkTimestamp(requestId, userTimestamp);
|
|
|
if (!ajaxResult.isSuccess()) {
|
|
if (!ajaxResult.isSuccess()) {
|
|
|
- return false;
|
|
|
|
|
|
|
+ throw new SignException(ajaxResult.getMsg());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ // 组装签名参数
|
|
|
|
|
+ String strToSign;
|
|
|
try {
|
|
try {
|
|
|
- String strToSign = SignatureUtil.getParamString(requestMap);
|
|
|
|
|
- AjaxResult ret = SignatureUtil.checkSignature(requestId, strToSign, userSignature, aesKey);
|
|
|
|
|
- if (ret.isSuccess()) {
|
|
|
|
|
- return true;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ strToSign = SignatureUtil.getParamString(requestMap);
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
log.debug("checkSignature, unsupported encoding exception {}, {}, {}", requestId,
|
|
log.debug("checkSignature, unsupported encoding exception {}, {}, {}", requestId,
|
|
|
e.getMessage(), e.getStackTrace());
|
|
e.getMessage(), e.getStackTrace());
|
|
|
- return false;
|
|
|
|
|
|
|
+ throw new SignException(ReturnCode.SIGN_CALC_FAIL.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ // 验证签名
|
|
|
|
|
+ ajaxResult = SignatureUtil.checkSignature(requestId, strToSign, userSignature, aesKey);
|
|
|
|
|
+ if (!ajaxResult.isSuccess()) {
|
|
|
|
|
+ throw new SignException(ajaxResult.getMsg());
|
|
|
}
|
|
}
|
|
|
- return false;
|
|
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|