From c3947c766f99929bd5833054311fafcf854e0e91 Mon Sep 17 00:00:00 2001 From: "Dario G. Mori" Date: Wed, 7 Feb 2024 09:13:15 +0100 Subject: [PATCH] chore: used same logger as CustomControllerAdvice --- .../java/lab/en2b/quizapi/auth/jwt/JwtUtils.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/api/src/main/java/lab/en2b/quizapi/auth/jwt/JwtUtils.java b/api/src/main/java/lab/en2b/quizapi/auth/jwt/JwtUtils.java index bc782dfd..432b0813 100644 --- a/api/src/main/java/lab/en2b/quizapi/auth/jwt/JwtUtils.java +++ b/api/src/main/java/lab/en2b/quizapi/auth/jwt/JwtUtils.java @@ -5,8 +5,7 @@ import io.jsonwebtoken.security.Keys; import io.jsonwebtoken.security.SignatureException; import lab.en2b.quizapi.auth.config.UserDetailsImpl; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Value; import org.springframework.security.core.Authentication; import org.springframework.stereotype.Component; @@ -16,10 +15,9 @@ import java.util.function.Function; @Component +@Log4j2 public class JwtUtils { - private static final Logger logger = LoggerFactory.getLogger(JwtUtils.class); - //MUST BE SET AS ENVIRONMENT VARIABLE @Value("${JWT_SECRET}") private String JWT_SECRET; @@ -42,15 +40,15 @@ public boolean validateJwtToken(String authToken) { Jwts.parser().verifyWith(getSignInKey()).build().parseSignedClaims(authToken); return true; } catch (SignatureException e) { - logger.error("Invalid JWT signature: {}", e.getMessage()); + log.error("Invalid JWT signature: {}", e.getMessage()); } catch (MalformedJwtException e) { - logger.error("Invalid JWT token: {}", e.getMessage()); + log.error("Invalid JWT token: {}", e.getMessage()); } catch (ExpiredJwtException e) { - logger.error("JWT token is expired: {}", e.getMessage()); + log.error("JWT token is expired: {}", e.getMessage()); } catch (UnsupportedJwtException e) { - logger.error("JWT token is unsupported: {}", e.getMessage()); + log.error("JWT token is unsupported: {}", e.getMessage()); } catch (IllegalArgumentException e) { - logger.error("JWT claims string is empty: {}", e.getMessage()); + log.error("JWT claims string is empty: {}", e.getMessage()); } return false; }