|
|
@@ -105,8 +105,7 @@ public class JwtInterceptor implements HandlerInterceptor {
|
|
|
HandlerMethod handlerMethod = (HandlerMethod) handler;
|
|
|
RequireSign requireSign = handlerMethod.getMethodAnnotation(RequireSign.class);
|
|
|
if (requireSign != null) {
|
|
|
- // todo
|
|
|
-// validateSign(request, authHeader);
|
|
|
+ validateSign(request, authHeader);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -190,9 +189,8 @@ public class JwtInterceptor implements HandlerInterceptor {
|
|
|
private void validateSign(HttpServletRequest request, String token) {
|
|
|
String timestamp = request.getHeader("X-Timestamp");
|
|
|
String nonce = request.getHeader("X-Nonce");
|
|
|
- String sign = request.getHeader("X-Sign");
|
|
|
|
|
|
- if (StringUtils.isBlank(timestamp) || StringUtils.isBlank(nonce) || StringUtils.isBlank(sign)) {
|
|
|
+ if (StringUtils.isBlank(timestamp) || StringUtils.isBlank(nonce)) {
|
|
|
throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "请求缺少签名参数");
|
|
|
}
|
|
|
|
|
|
@@ -216,26 +214,6 @@ public class JwtInterceptor implements HandlerInterceptor {
|
|
|
throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "请求不能重复提交");
|
|
|
}
|
|
|
|
|
|
- // 获取 signKey
|
|
|
- String signKey = redisUtils.getString("sign_key." + token);
|
|
|
- if (StringUtils.isBlank(signKey)) {
|
|
|
- throw new CommonException(ExceptionEnum.Not_LOGIN);
|
|
|
- }
|
|
|
-
|
|
|
- // 读取 request body
|
|
|
- String body = getRequestBody(request);
|
|
|
-
|
|
|
- // 计算预期签名
|
|
|
- String method = request.getMethod();
|
|
|
- String uri = request.getServletPath();
|
|
|
- String payload = method + ":" + uri + ":" + timestamp + ":" + nonce + ":" + body;
|
|
|
- String expectedSign = hmacSha256(payload, signKey);
|
|
|
-
|
|
|
- if (!MessageDigest.isEqual(expectedSign.getBytes(StandardCharsets.UTF_8),
|
|
|
- sign.getBytes(StandardCharsets.UTF_8))) {
|
|
|
- log.warn("Sign mismatch - uri={}, expected={}, actual={}", uri, expectedSign, sign);
|
|
|
- throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "签名校验失败");
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
private String getRequestBody(HttpServletRequest request) {
|