From a5aac1199d9c963269efbfc7b8116bf42da0d0e5 Mon Sep 17 00:00:00 2001 From: heshunme Date: Wed, 3 Jul 2024 13:58:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E4=BA=86@JwtVerify=E7=9A=84?= =?UTF-8?q?=E8=83=BD=E5=8A=9B=EF=BC=8C=E7=8E=B0=E5=9C=A8=E8=A2=AB=E4=BF=AE?= =?UTF-8?q?=E9=A5=B0=E7=9A=84=E6=96=B9=E6=B3=95=E7=9A=84=E4=BB=BB=E6=84=8F?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=8F=82=E6=95=B0=E6=98=AF=E7=BB=A7=E6=89=BF?= =?UTF-8?q?=E4=BA=8EJwtRequest=E7=9A=84=E5=AF=B9=E8=B1=A1=E5=8D=B3?= =?UTF-8?q?=E5=8F=AF=EF=BC=8C=E4=B8=8D=E5=86=8D=E5=BC=BA=E5=88=B6=E4=B8=BA?= =?UTF-8?q?=E7=AC=AC=E4=B8=80=E4=B8=AA=E5=8F=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/cmh/backend/Utils/JwtVerifyAspect.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/cmh/backend/Utils/JwtVerifyAspect.java b/src/main/java/org/cmh/backend/Utils/JwtVerifyAspect.java index 42408c9..26cee34 100644 --- a/src/main/java/org/cmh/backend/Utils/JwtVerifyAspect.java +++ b/src/main/java/org/cmh/backend/Utils/JwtVerifyAspect.java @@ -1,5 +1,6 @@ package org.cmh.backend.Utils; +import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.springframework.stereotype.Component; @@ -7,13 +8,17 @@ import org.springframework.stereotype.Component; @Aspect @Component public class JwtVerifyAspect { - @Before("@annotation(JwtVerify) && args(request,..)") - public void verifyJwtToken(Object request) throws JwtValidationException { - if (request instanceof JwtRequest) { - String token = ((JwtRequest) request).getToken(); - if (!JwtUtil.isTokenValid(token)) { - throw new JwtValidationException("JWT token is invalid"); + @Before("@annotation(JwtVerify)") + public void verifyJwtToken(JoinPoint joinPoint) throws JwtValidationException { + Object[] args = joinPoint.getArgs(); + for (Object arg : args) { + if (arg instanceof JwtRequest jwtRequest) { + String token = jwtRequest.getToken(); + if (!JwtUtil.isTokenValid(token)) { + throw new JwtValidationException("JWT token is invalid"); + } } + break; } } }