Skip to content

Commit

Permalink
refactor: PrivateClaims의 타입을 Long으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
apptie committed Aug 8, 2023
1 parent 867e4ea commit 92d4759
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ddang.ddang.authentication.domain;

public record PrivateClaims(String userId) {
public record PrivateClaims(Long userId) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class JwtDecoder implements TokenDecoder {
public Optional<PrivateClaims> decode(final TokenType tokenType, final String token) {
validateBearerToken(token);

return this.parseWithClaims(token, tokenType)
return this.parse(tokenType, token)
.map(this::convert);
}

Expand All @@ -48,8 +48,9 @@ private void validateTokenType(final String tokenType) {
}
}

private Optional<Claims> parseWithClaims(final String token, final TokenType tokenType) {
private Optional<Claims> parse(final TokenType tokenType, final String token) {
final String key = jwtConfigurationProperties.findTokenKey(tokenType);

try {
return Optional.of(
Jwts.parserBuilder()
Expand All @@ -64,7 +65,7 @@ private Optional<Claims> parseWithClaims(final String token, final TokenType tok
}

private PrivateClaims convert(Claims claims) {
return new PrivateClaims(claims.get(CLAIM_NAME, String.class));
return new PrivateClaims(claims.get(CLAIM_NAME, Long.class));
}

private String findPureToken(String token) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ class AuctionServiceTest {
List.of(thirdRegion.getId()),
main.getId(),
List.of(auctionImage),
1L
seller.getId()
);

// when & then
Expand Down Expand Up @@ -579,7 +579,7 @@ class AuctionServiceTest {
void 지정한_아이디에_해당하는_회원과_판매자가_일치하지_않는_경우_삭제시_예외가_발생한다() {
// given
final User seller = User.builder()
.name("회원")
.name("회원1")
.profileImage("profile.png")
.reliability(4.7d)
.oauthId("12345")
Expand All @@ -594,7 +594,7 @@ class AuctionServiceTest {
.seller(seller)
.build();
final User user = User.builder()
.name("회원")
.name("회원2")
.profileImage("profile.png")
.reliability(4.7d)
.oauthId("12346")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void setUp(
@Test
void refreshToken_전달하면_새로운_accessToken_반환한다() {
// given
final Map<String, Object> privateClaims = Map.of("userId", "12345");
final Map<String, Object> privateClaims = Map.of("userId", 1L);
final String refreshToken = "Bearer " + tokenEncoder.encode(
LocalDateTime.now(),
TokenType.REFRESH,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void setUp() {
@Test
void 유효한_토큰이면_해당_토큰의_본문을_반환한다() {
// given
final Map<String, Object> privateClaims = Map.of("userId", "12345");
final Map<String, Object> privateClaims = Map.of("userId", 1L);
final String accessToken = "Bearer " + jwtEncoder.encode(LocalDateTime.now(), TokenType.ACCESS, privateClaims);

// when
Expand Down

0 comments on commit 92d4759

Please sign in to comment.