Skip to content

Commit

Permalink
fix: 긴급 예외 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
kimminkyeu committed Jan 3, 2025
1 parent 2557544 commit b261018
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import baguni.entity.model.user.Role;
import baguni.entity.model.util.IDToken;
import baguni.entity.model.util.IdTokenConversionException;
import baguni.security.config.JwtProperties;
import baguni.security.exception.ApiAuthException;
import io.jsonwebtoken.Claims;
Expand Down Expand Up @@ -38,7 +39,11 @@ public Role getUserRole() {

public IDToken getUserIdToken() {
var raw = getClaims().get("id", String.class);
return IDToken.fromString(raw);
try {
return IDToken.fromString(raw);
} catch (IdTokenConversionException e) {
throw ApiAuthException.INVALID_AUTHENTICATION();
}
}

public UsernamePasswordAuthenticationToken toAuthenticationToken() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ public class IDToken {

private final UUID uuid;

public static IDToken fromString(String raw) {
return new IDToken(UUID.fromString(raw));
public static IDToken fromString(String raw) throws IdTokenConversionException {
try {
var uuid = UUID.fromString(raw);
return new IDToken(uuid);
} catch (Exception e) {
throw new IdTokenConversionException("ID 토큰의 값이 UUID 가 아닙니다!");
}
}

public static IDToken makeNew() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package baguni.entity.model.util;

public class IdTokenConversionException extends RuntimeException {

public IdTokenConversionException(String message) {
super(message);
}
}

0 comments on commit b261018

Please sign in to comment.