Commit 7887fd98 by caiyt-byte

token key方式更改

parent 2f7f33fc
...@@ -18,7 +18,10 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -18,7 +18,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.crypto.spec.SecretKeySpec;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.security.Key;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -52,6 +55,13 @@ public class TokenService { ...@@ -52,6 +55,13 @@ public class TokenService {
@Autowired @Autowired
private RedisCache redisCache; private RedisCache redisCache;
private Key secretKey;
@PostConstruct
public void init() {
secretKey = new SecretKeySpec(secret.getBytes(), SignatureAlgorithm.HS512.getJcaName());
}
/** /**
* 获取用户身份信息 * 获取用户身份信息
* *
...@@ -162,7 +172,7 @@ public class TokenService { ...@@ -162,7 +172,7 @@ public class TokenService {
private String createToken(Map<String, Object> claims) { private String createToken(Map<String, Object> claims) {
String token = Jwts.builder() String token = Jwts.builder()
.setClaims(claims) .setClaims(claims)
.signWith(SignatureAlgorithm.HS512, secret).compact(); .signWith(SignatureAlgorithm.HS512, secretKey).compact();
return token; return token;
} }
...@@ -174,7 +184,7 @@ public class TokenService { ...@@ -174,7 +184,7 @@ public class TokenService {
*/ */
private Claims parseToken(String token) { private Claims parseToken(String token) {
return Jwts.parser() return Jwts.parser()
.setSigningKey(secret) .setSigningKey(secretKey)
.parseClaimsJws(token) .parseClaimsJws(token)
.getBody(); .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