Skip to content

Commit

Permalink
accessToken과 refreshToken을 추출하는 메서드 분리 (#13)
Browse files Browse the repository at this point in the history
refreshToken을 추출하는 메서드를 추가했습니다.
기존에는 accessToken만 추출을 하였는데, refreshToken 또한 추출하여서 내부 값을 확인해야하므로 메서드를 추가하였습니다.

추가적으로 formatter를 제거하고, 전반적인 코드의 format을 변경하였습니다.
버전 업을 할 때 한꺼번에 하고 싶었습니다.
  • Loading branch information
seong-wooo authored Sep 10, 2023
1 parent 591b5f3 commit bba7e02
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 47 deletions.
17 changes: 0 additions & 17 deletions .github/workflows/reformat-java.yml

This file was deleted.

4 changes: 3 additions & 1 deletion src/main/java/online/partyrun/jwtmanager/JwtExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
import online.partyrun.jwtmanager.dto.JwtPayload;

public interface JwtExtractor {
JwtPayload extract(String accessToken);
JwtPayload extractAccessToken(String accessToken);

JwtPayload extractRefreshToken(String refreshToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import lombok.extern.slf4j.Slf4j;

import online.partyrun.jwtmanager.manager.JwtManager;
import online.partyrun.jwtmanager.manager.TokenManager;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
Expand All @@ -22,9 +20,8 @@ public class JwtConfig {
public JwtManager jwtManager(
@Value("${jwt.access-secret-key}") String accessKey,
@Value("${jwt.access-expire-second:#{'1'}}") Long accessExpireSecond,
@Value(
"${jwt.refresh-secret-key:#{'DefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefault'}}")
String refreshKey,
@Value("${jwt.refresh-secret-key:#{'DefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefaultDefault'}}")
String refreshKey,
@Value("${jwt.refresh-expire-second:#{'1'}}") Long refreshExpireSecond) {
log.info("Starting JwtManager");
return new JwtManager(
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/online/partyrun/jwtmanager/dto/JwtPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
import java.time.LocalDateTime;
import java.util.List;

public record JwtPayload(String id, List<String> roles, LocalDateTime expireAt) {}
public record JwtPayload(String id, List<String> roles, LocalDateTime expireAt) {
}
3 changes: 2 additions & 1 deletion src/main/java/online/partyrun/jwtmanager/dto/JwtToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
import lombok.Builder;

@Builder
public record JwtToken(String accessToken, String refreshToken) {}
public record JwtToken(String accessToken, String refreshToken) {
}
16 changes: 10 additions & 6 deletions src/main/java/online/partyrun/jwtmanager/manager/JwtManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;

import online.partyrun.jwtmanager.JwtExtractor;
import online.partyrun.jwtmanager.JwtGenerator;
import online.partyrun.jwtmanager.dto.JwtPayload;
Expand All @@ -26,11 +25,6 @@ public JwtToken generate(String id, Set<String> roles) {
.build();
}

@Override
public JwtPayload extract(String accessToken) {
return accessTokenManager.extract(accessToken);
}

@Override
public JwtToken refresh(String refreshToken) {
final JwtPayload jwtPayload = refreshTokenManager.extract(refreshToken);
Expand All @@ -39,4 +33,14 @@ public JwtToken refresh(String refreshToken) {
.refreshToken(refreshTokenManager.generate(jwtPayload.id(), jwtPayload.roles()))
.build();
}

@Override
public JwtPayload extractAccessToken(String accessToken) {
return accessTokenManager.extract(accessToken);
}

@Override
public JwtPayload extractRefreshToken(String refreshToken) {
return refreshTokenManager.extract(refreshToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.io.Decoders;
import io.jsonwebtoken.security.Keys;

import lombok.AccessLevel;
import lombok.experimental.FieldDefaults;

import online.partyrun.jwtmanager.dto.JwtPayload;

import org.springframework.util.StringUtils;

import java.security.Key;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
public class TokenManager {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package online.partyrun.jwtmanager.manager;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;

import lombok.AccessLevel;
import lombok.experimental.FieldDefaults;

import online.partyrun.jwtmanager.dto.JwtToken;

import org.junit.jupiter.api.*;

import java.util.Set;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;

@DisplayName("JwtManagerTest 클래스")
@FieldDefaults(level = AccessLevel.PRIVATE)
class JwtManagerTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
package online.partyrun.jwtmanager.manager;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertAll;

import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.MalformedJwtException;

import lombok.AccessLevel;
import lombok.experimental.FieldDefaults;

import online.partyrun.jwtmanager.dto.JwtPayload;

import org.junit.jupiter.api.*;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EmptySource;
Expand All @@ -22,6 +15,10 @@
import java.time.temporal.ChronoUnit;
import java.util.Set;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertAll;

@DisplayName("TokenManager 클래스")
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
class TokenManagerTest {
Expand Down

0 comments on commit bba7e02

Please sign in to comment.