Unverified 提交 1359a673 authored 作者: fit2cloud-chenyw's avatar fit2cloud-chenyw 提交者: GitHub

Merge pull request #1286 from dataease/pr@dev@fix_token_security

fix: token验签逻辑错误
package io.dataease.auth.filter; package io.dataease.auth.filter;
import com.auth0.jwt.algorithms.Algorithm;
import io.dataease.auth.entity.ASKToken; import io.dataease.auth.entity.ASKToken;
import io.dataease.auth.entity.JWTToken; import io.dataease.auth.entity.JWTToken;
import io.dataease.auth.entity.SysUserEntity; import io.dataease.auth.entity.SysUserEntity;
...@@ -115,9 +116,9 @@ public class JWTFilter extends BasicHttpAuthenticationFilter { ...@@ -115,9 +116,9 @@ public class JWTFilter extends BasicHttpAuthenticationFilter {
DataEaseException.throwException(Translator.get("i18n_not_find_user")); DataEaseException.throwException(Translator.get("i18n_not_find_user"));
} }
String password = user.getPassword(); String password = user.getPassword();
Algorithm algorithm = Algorithm.HMAC256(password);
JWTUtils.verifySign(algorithm, token);
String newToken = JWTUtils.sign(tokenInfo, password); String newToken = JWTUtils.sign(tokenInfo, password);
// 设置响应的Header头新Token // 设置响应的Header头新Token
HttpServletResponse httpServletResponse = (HttpServletResponse) response; HttpServletResponse httpServletResponse = (HttpServletResponse) response;
httpServletResponse.addHeader("Access-Control-Expose-Headers", "RefreshAuthorization"); httpServletResponse.addHeader("Access-Control-Expose-Headers", "RefreshAuthorization");
......
...@@ -35,15 +35,23 @@ public class JWTUtils { ...@@ -35,15 +35,23 @@ public class JWTUtils {
* @return 是否正确 * @return 是否正确
*/ */
public static boolean verify(String token, TokenInfo tokenInfo, String secret) { public static boolean verify(String token, TokenInfo tokenInfo, String secret) {
Algorithm algorithm = Algorithm.HMAC256(secret); Algorithm algorithm = Algorithm.HMAC256(secret);
Verification verification = JWT.require(algorithm) Verification verification = JWT.require(algorithm)
.withClaim("username", tokenInfo.getUsername()) .withClaim("username", tokenInfo.getUsername())
.withClaim("userId", tokenInfo.getUserId()); .withClaim("userId", tokenInfo.getUserId());
JWTVerifier verifier = verification.build(); JWTVerifier verifier = verification.build();
verifySign(algorithm, token);
verifier.verify(token); verifier.verify(token);
return true; return true;
} }
public static void verifySign(Algorithm algorithm, String token) {
DecodedJWT decode = JWT.decode(token);
algorithm.verify(decode);
}
/** /**
* 获得token中的信息无需secret解密也能获得 * 获得token中的信息无需secret解密也能获得
* *
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论