Skip to content

Commit

Permalink
[Refactor] #272 - 토큰 파싱 과정에서의 예외처리 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
mjKim1229 committed Jun 20, 2023
1 parent 163da58 commit 203113b
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/main/java/shop/cazait/global/config/encrypt/JwtService.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,20 @@ public JwtBuilder makeCommonTokenSource(Date now, Date expirationDate) {
.setIssuedAt(now)
.setExpiration(expirationDate)
.signWith(key);

}

//accessToken 발행 함수
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 발행 함수
Expand Down Expand Up @@ -106,17 +108,16 @@ public Jws<Claims> parseTokenWithAllException(String token) throws UserException
try {
Jws<Claims> 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<Claims> parseRefreshTokenWithAllException(String token) throws UserException {
Expand Down

0 comments on commit 203113b

Please # to comment.