|
@@ -1,6 +1,8 @@
|
|
|
package com.fs.app.utils;
|
|
|
|
|
|
+import com.fs.app.exception.FSException;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
+import com.fs.common.utils.StringUtils;
|
|
|
import io.jsonwebtoken.Claims;
|
|
|
import io.jsonwebtoken.Jwts;
|
|
|
import io.jsonwebtoken.SignatureAlgorithm;
|
|
@@ -8,6 +10,7 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.Date;
|
|
@@ -44,6 +47,9 @@ public class JwtUtils {
|
|
|
}
|
|
|
|
|
|
public Claims getClaimByToken(String token) {
|
|
|
+ if (StringUtils.isEmpty(token)) {
|
|
|
+ throw new FSException("token不能为空", HttpStatus.UNAUTHORIZED.value());
|
|
|
+ }
|
|
|
try {
|
|
|
return Jwts.parser()
|
|
|
.setSigningKey(secret)
|
|
@@ -51,7 +57,9 @@ public class JwtUtils {
|
|
|
.getBody();
|
|
|
}catch (Exception e){
|
|
|
logger.debug("validate is token error ", e);
|
|
|
- return null;
|
|
|
+ logger.info("token异常,重新登录,token: {}",token);
|
|
|
+
|
|
|
+ throw new FSException("token 失效,请重新登录", HttpStatus.UNAUTHORIZED.value());
|
|
|
}
|
|
|
}
|
|
|
|