|
|
@@ -3,6 +3,7 @@ package org.dromara.common.satoken.handler;
|
|
|
import cn.dev33.satoken.exception.NotLoginException;
|
|
|
import cn.dev33.satoken.exception.NotPermissionException;
|
|
|
import cn.dev33.satoken.exception.NotRoleException;
|
|
|
+import cn.dev33.satoken.jwt.exception.SaJwtException;
|
|
|
import cn.hutool.http.HttpStatus;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -49,4 +50,14 @@ public class SaTokenExceptionHandler {
|
|
|
return R.fail(HttpStatus.HTTP_UNAUTHORIZED, "认证失败,无法访问系统资源");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * JWT 签名无效/解析失败(常见于密钥变更后残留旧 token)
|
|
|
+ */
|
|
|
+ @ExceptionHandler(SaJwtException.class)
|
|
|
+ public R<Void> handleSaJwtException(SaJwtException e, HttpServletRequest request) {
|
|
|
+ String requestURI = request.getRequestURI();
|
|
|
+ log.error("请求地址'{}',JWT校验失败'{}',无法访问系统资源", requestURI, e.getMessage());
|
|
|
+ return R.fail(HttpStatus.HTTP_UNAUTHORIZED, "登录状态已失效,请重新登录");
|
|
|
+ }
|
|
|
+
|
|
|
}
|