zhangw 2018-05-05 22:26:57 +08:00
parent c71f832aaa
commit b2d628c4d9
2 changed files with 2 additions and 3 deletions

View File

@ -145,7 +145,7 @@ public class TokenServiceDbImpl implements TokenService {
private Key getKeyInstance() {
if (KEY == null) {
synchronized (TokenServiceJWTImpl.class) {
synchronized (TokenServiceDbImpl.class) {
if (KEY == null) {// 双重锁
byte[] apiKeySecretBytes = DatatypeConverter.parseBase64Binary(jwtSecret);
KEY = new SecretKeySpec(apiKeySecretBytes, SignatureAlgorithm.HS256.getJcaName());

View File

@ -152,9 +152,8 @@ public class TokenServiceJWTImpl implements TokenService {
return null;
}
Map<String, Object> jwtClaims = null;
try {
jwtClaims = Jwts.parser().setSigningKey(getKeyInstance()).parseClaimsJws(jwtToken).getBody();
Map<String, Object> jwtClaims = Jwts.parser().setSigningKey(getKeyInstance()).parseClaimsJws(jwtToken).getBody();
return MapUtils.getString(jwtClaims, LOGIN_USER_KEY);
} catch (ExpiredJwtException e) {
log.error("{}已过期", jwtToken);