Commit 09fecd78 by stylefeng

验证token是否过期,增加异常拦截

parent bcc8a459
...@@ -2,10 +2,7 @@ package com.stylefeng.guns.rest.modular.auth.util; ...@@ -2,10 +2,7 @@ package com.stylefeng.guns.rest.modular.auth.util;
import com.stylefeng.guns.core.util.ToolUtil; import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.rest.config.properties.JwtProperties; import com.stylefeng.guns.rest.config.properties.JwtProperties;
import io.jsonwebtoken.Claims; import io.jsonwebtoken.*;
import io.jsonwebtoken.JwtException;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -101,8 +98,12 @@ public class JwtTokenUtil { ...@@ -101,8 +98,12 @@ public class JwtTokenUtil {
* </pre> * </pre>
*/ */
public Boolean isTokenExpired(String token) { public Boolean isTokenExpired(String token) {
final Date expiration = getExpirationDateFromToken(token); try {
return expiration.before(new Date()); final Date expiration = getExpirationDateFromToken(token);
return expiration.before(new Date());
} catch (ExpiredJwtException expiredJwtException) {
return true;
}
} }
/** /**
......
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