记得上下班打卡 | git大法好,push需谨慎

Commit 3b44432f authored by 张国柄's avatar 张国柄

fix token;

parent 7533ab39
......@@ -27,6 +27,15 @@ public class JwtValidator {
// private static final long EXPIRE_TIME = 15 * 60 * 1000;
// private static final String TOKEN_SECRET = "qZHglvNP0n0aOOckHiQXq5JMD468J4eG";
private SecretKey secretKey;
private SecretKey initSecretKey(String secret) {
if (null == this.secretKey) {
this.secretKey = new SecretKeySpec(secret.getBytes(), SignatureAlgorithm.HS256.getJcaName());
}
return this.secretKey;
}
/**
* 用户登录成功后生成Jwt token
* 使用Hs256算法
......@@ -42,7 +51,7 @@ public class JwtValidator {
.setClaims(claimsMap)
.setIssuedAt(new Date(nowMillis))
.setExpiration(new Date(expMillis))
.signWith(SignatureAlgorithm.HS256, new SecretKeySpec(secret.getBytes(), SignatureAlgorithm.HS256.getJcaName()));
.signWith(SignatureAlgorithm.HS256, this.initSecretKey(this.secret));
return builder.compact();
}
......@@ -54,7 +63,7 @@ public class JwtValidator {
*/
public Claims parse(String token) {
return Jwts.parser()
.setSigningKey(new SecretKeySpec(secret.getBytes(), SignatureAlgorithm.HS256.getJcaName()))
.setSigningKey(this.initSecretKey(this.secret))
.parseClaimsJws(token).getBody();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment