Commit 5926990e by jianan

idP

parent aa98e103
...@@ -138,22 +138,19 @@ public class JwtTokenProvider { ...@@ -138,22 +138,19 @@ public class JwtTokenProvider {
} }
/** /**
* 验证令牌有效性 * 验证令牌有效性。
*
* <p>语义:true=有效;false=无效(签名不符/过期/格式错等)。无效 token 不在此抛异常,
* 由调用过滤器按"未认证"处理——受保护资源经授权层返回 401、白名单路径正常放行。
* 避免一个坏 token 抛异常中断整条请求(旧实现会把 permitAll 路径也打成 401/500)。</p>
*/ */
public boolean validateToken(String token) { public boolean validateToken(String token) {
try { try {
Jwts.parserBuilder().setSigningKey(getSigningKey()).build().parseClaimsJws(token); Jwts.parserBuilder().setSigningKey(getSigningKey()).build().parseClaimsJws(token);
return true; return true;
} catch (SecurityException | MalformedJwtException e) {
throw new JwtAuthenticationException("无效的JWT签名");
} catch (ExpiredJwtException e) {
throw new JwtAuthenticationException("JWT令牌已过期");
} catch (UnsupportedJwtException e) {
throw new JwtAuthenticationException("不支持的JWT令牌");
} catch (IllegalArgumentException e) {
throw new JwtAuthenticationException("JWT令牌无效");
} catch (Exception e) { } catch (Exception e) {
throw new JwtAuthenticationException("无效的JWT令牌: " + e.getMessage()); log.debug("JWT 校验未通过,按未认证处理:{}", e.getMessage());
return false;
} }
} }
......
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