From 203113b0fc0e07bd92e13a6a09aae36e6deeb45b Mon Sep 17 00:00:00 2001 From: minjun Date: Tue, 20 Jun 2023 20:34:24 +0900 Subject: [PATCH] =?UTF-8?q?[Refactor]=20#272=20-=20=ED=86=A0=ED=81=B0=20?= =?UTF-8?q?=ED=8C=8C=EC=8B=B1=20=EA=B3=BC=EC=A0=95=EC=97=90=EC=84=9C?= =?UTF-8?q?=EC=9D=98=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/config/encrypt/JwtService.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/shop/cazait/global/config/encrypt/JwtService.java b/src/main/java/shop/cazait/global/config/encrypt/JwtService.java index c86484b2..eda5fced 100644 --- a/src/main/java/shop/cazait/global/config/encrypt/JwtService.java +++ b/src/main/java/shop/cazait/global/config/encrypt/JwtService.java @@ -42,7 +42,6 @@ public JwtBuilder makeCommonTokenSource(Date now, Date expirationDate) { .setIssuedAt(now) .setExpiration(expirationDate) .signWith(key); - } //accessToken 발행 함수 @@ -50,10 +49,13 @@ public String createJwt(Long userIdx) { log.info("Created token userIdx = " + userIdx); Date now = new Date(); Date expirationDate = new Date(now.getTime() + ACCESS_TOKEN_VALID_TIME); - + System.out.println("key = " + key); return makeCommonTokenSource(now, expirationDate) .claim("userIdx", userIdx) .compact(); +// return makeCommonTokenSource(now, expirationDate) +// .setSubject(String.valueOf(userIdx)) +// .compact(); } //refreshToken 발행 함수 @@ -106,17 +108,16 @@ public Jws parseTokenWithAllException(String token) throws UserException try { Jws parsedToken = parseJwt(token); return parsedToken; - } catch (ExpiredJwtException exception) { - log.error("Token Expired UserID : " + exception.getClaims().get("userIdx")); - throw new UserException(EXPIRED_JWT); - } catch (JwtException exception) { - log.error("RefreshToken Tampered."); - throw new UserException(INVALID_JWT); - } catch (NullPointerException exception) { + } catch (NullPointerException e) { log.error("Token is null."); throw new UserException(EMPTY_JWT); + } catch (ExpiredJwtException e) { + log.error("Token Expired UserID : " + e.getClaims().get("userIdx")); + throw new UserException(EXPIRED_JWT); + } catch (JwtException | IllegalArgumentException e) { + log.error("Token tampered"); + throw new UserException(INVALID_JWT); } - } public Jws parseRefreshTokenWithAllException(String token) throws UserException {