forked from RyanGoodwill/backend
升级了@JwtVerify的能力,现在被修饰的方法的任意一个参数是继承于JwtRequest的对象即可,不再强制为第一个参
This commit is contained in:
parent
6beeb110c2
commit
df6686fc19
@ -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,14 +8,18 @@ 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();
|
||||
@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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user