From 8fbbfe5da7cc81e124cd3103e90bb76b0053fc97 Mon Sep 17 00:00:00 2001 From: codepzj Date: Fri, 31 Jan 2025 14:01:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=94=9F=E4=BA=A7=E7=8E=AF=E5=A2=83toke?= =?UTF-8?q?n=E4=B8=BA=E7=A9=BA=EF=BC=8C=E8=B7=B3=E8=BF=87=E6=9D=83?= =?UTF-8?q?=E9=99=90=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/liuyuyang/net/aspect/PremNameAspect.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/blog/src/main/java/liuyuyang/net/aspect/PremNameAspect.java b/blog/src/main/java/liuyuyang/net/aspect/PremNameAspect.java index 498c75d..1723fe4 100644 --- a/blog/src/main/java/liuyuyang/net/aspect/PremNameAspect.java +++ b/blog/src/main/java/liuyuyang/net/aspect/PremNameAspect.java @@ -65,8 +65,14 @@ public void before(JoinPoint joinPoint) { String token = request.getHeader("Authorization"); log.debug("Authorization Header: {}", token); + // 如果 token 为 null,跳过权限校验 + if (token == null) { + log.info("Token为空,跳过权限校验"); + return; // 跳过权限校验 + } + // 去掉 Bearer 前缀 - if (token != null && token.startsWith("Bearer ")) { + if (token.startsWith("Bearer ")) { token = token.substring(7); } @@ -116,7 +122,7 @@ public void before(JoinPoint joinPoint) { // 获取当前方法上的 @PremName 注解 private Optional getMethodAnnotation(JoinPoint joinPoint) { return Optional.ofNullable(getCurrentMethod(joinPoint)) - .map(method -> method.getAnnotation(PremName.class)); + .map(method -> method.getAnnotation(PremName.class)); } // 获取当前执行的方法对象 @@ -135,4 +141,4 @@ private Method getCurrentMethod(JoinPoint joinPoint) { } return null; } -} \ No newline at end of file +}