升级了@JwtVerify的能力,现在被修饰的方法的任意一个参数是继承于JwtRequest的对象即可,不再强制为第一个参
This commit is contained in:
parent
6c36552c2f
commit
a5aac1199d
@ -1,5 +1,6 @@
|
|||||||
package org.cmh.backend.Utils;
|
package org.cmh.backend.Utils;
|
||||||
|
|
||||||
|
import org.aspectj.lang.JoinPoint;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.annotation.Before;
|
import org.aspectj.lang.annotation.Before;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@ -7,14 +8,18 @@ import org.springframework.stereotype.Component;
|
|||||||
@Aspect
|
@Aspect
|
||||||
@Component
|
@Component
|
||||||
public class JwtVerifyAspect {
|
public class JwtVerifyAspect {
|
||||||
@Before("@annotation(JwtVerify) && args(request,..)")
|
@Before("@annotation(JwtVerify)")
|
||||||
public void verifyJwtToken(Object request) throws JwtValidationException {
|
public void verifyJwtToken(JoinPoint joinPoint) throws JwtValidationException {
|
||||||
if (request instanceof JwtRequest) {
|
Object[] args = joinPoint.getArgs();
|
||||||
String token = ((JwtRequest) request).getToken();
|
for (Object arg : args) {
|
||||||
|
if (arg instanceof JwtRequest jwtRequest) {
|
||||||
|
String token = jwtRequest.getToken();
|
||||||
if (!JwtUtil.isTokenValid(token)) {
|
if (!JwtUtil.isTokenValid(token)) {
|
||||||
throw new JwtValidationException("JWT token is invalid");
|
throw new JwtValidationException("JWT token is invalid");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user