public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object object) {
String jwt = request.getHeader("auth");
String payloadKey = "apitest";
HandlerMethod handlerMethod=(HandlerMethod)object;
Class type = handlerMethod.getBeanType();
if (type.isAnnotationPresent(Auth.class)) {
try {
if (jwt == null || !Objects.equals(payloadKey, JwtUtil.parseJWT(jwt).get("info", String.class))) {
return false;
}
}catch (ExpiredJwtException | SignatureException | MalformedJwtException e){
return false;
}
}
log.info("1");
return true;
}
when jwt is true, but i see log.info("1") run 3 times, why it run 3 times?
my interceptorConfig:
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(authenticationInterceptor())
.addPathPatterns("/**");
}
@Bean
public AuthenticationInterceptor authenticationInterceptor() {
return new AuthenticationInterceptor();
}
i set @Auth on my controller class: @Auth public class ApiController
And when i clear my preHandle exclude "log.info("1") return true" that run 3 times
Updated
You can debug into AuthenticationInterceptor
, to confirm somethings:
if the handlerMethod
point different object in total 3 times?
if the AuthenticationInterceptor
, that is this
variable, is different or not?
If there has some redirect for your request?
I tried use some code like yours, it has correct behavior. Can you show more code or a simply way to reproduce the issue?
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments