Skip to content

Commit

Permalink
chore: used same logger as CustomControllerAdvice
Browse files Browse the repository at this point in the history
  • Loading branch information
Toto-hitori committed Feb 7, 2024
1 parent 8dd1e5c commit c3947c7
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions api/src/main/java/lab/en2b/quizapi/auth/jwt/JwtUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit c3947c7

Please sign in to comment.