From 6edc03464e80fb63d61d578dde2d54a88283a5ec Mon Sep 17 00:00:00 2001 From: echo724 Date: Wed, 16 Aug 2023 14:12:58 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20develop=20=EB=A8=B8=EC=A7=80=20?= =?UTF-8?q?=EC=BB=A4=EB=B0=8B=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/donggle/backend/auth/JwtToken.java | 65 ------------------- .../donggle/backend/auth/JwtTokenService.java | 22 ------- .../EmptyAuthorizationHeaderException.java | 11 ---- .../InvalidAccessTokenException.java | 11 ---- .../auth/exception/NoSuchTokenException.java | 11 ---- .../backend/ui/KakaoOAuthController.java | 10 --- .../backend/auth/JwtTokenProviderTest.java | 39 ----------- 7 files changed, 169 deletions(-) delete mode 100644 backend/src/main/java/org/donggle/backend/auth/JwtToken.java delete mode 100644 backend/src/main/java/org/donggle/backend/auth/JwtTokenService.java delete mode 100644 backend/src/main/java/org/donggle/backend/auth/exception/EmptyAuthorizationHeaderException.java delete mode 100644 backend/src/main/java/org/donggle/backend/auth/exception/InvalidAccessTokenException.java delete mode 100644 backend/src/main/java/org/donggle/backend/auth/exception/NoSuchTokenException.java delete mode 100644 backend/src/test/java/org/donggle/backend/auth/JwtTokenProviderTest.java diff --git a/backend/src/main/java/org/donggle/backend/auth/JwtToken.java b/backend/src/main/java/org/donggle/backend/auth/JwtToken.java deleted file mode 100644 index d698be4f3..000000000 --- a/backend/src/main/java/org/donggle/backend/auth/JwtToken.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.donggle.backend.auth; - -import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.OneToOne; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; -import org.donggle.backend.domain.member.Member; - -import java.util.Objects; - -@Entity -@Getter -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class JwtToken { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - private String refreshToken; - @OneToOne(fetch = FetchType.LAZY) - private Member member; - - public JwtToken(final String token, final Member member) { - this.refreshToken = token; - this.member = member; - } - - public boolean isDifferentRefreshToken(final String refreshToken) { - return !this.refreshToken.equals(refreshToken); - } - - public void updateRefreshToken(final String refreshToken) { - this.refreshToken = refreshToken; - } - - @Override - public String toString() { - return "JwtToken{" + - "id=" + id + - ", token='" + refreshToken + '\'' + - ", member=" + member + - '}'; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - final JwtToken jwtToken = (JwtToken) o; - return Objects.equals(getId(), jwtToken.getId()); - } - - @Override - public int hashCode() { - return Objects.hash(getId()); - } -} diff --git a/backend/src/main/java/org/donggle/backend/auth/JwtTokenService.java b/backend/src/main/java/org/donggle/backend/auth/JwtTokenService.java deleted file mode 100644 index a560b6b23..000000000 --- a/backend/src/main/java/org/donggle/backend/auth/JwtTokenService.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.donggle.backend.auth; - -import jakarta.transaction.Transactional; -import lombok.RequiredArgsConstructor; -import org.donggle.backend.application.repository.TokenRepository; -import org.donggle.backend.domain.member.Member; -import org.springframework.stereotype.Service; - -@Service -@Transactional -@RequiredArgsConstructor -public class JwtTokenService { - private final TokenRepository tokenRepository; - - public void synchronizeRefreshToken(final Member member, final String refreshToken) { - tokenRepository.findByMemberId(member.getId()) - .ifPresentOrElse( - token -> token.updateRefreshToken(refreshToken), - () -> tokenRepository.save(new JwtToken(refreshToken, member)) - ); - } -} diff --git a/backend/src/main/java/org/donggle/backend/auth/exception/EmptyAuthorizationHeaderException.java b/backend/src/main/java/org/donggle/backend/auth/exception/EmptyAuthorizationHeaderException.java deleted file mode 100644 index 16827e98e..000000000 --- a/backend/src/main/java/org/donggle/backend/auth/exception/EmptyAuthorizationHeaderException.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.donggle.backend.auth.exception; - -import org.donggle.backend.exception.business.BusinessException; - -public class EmptyAuthorizationHeaderException extends BusinessException { - private static final String MESSAGE = "header에 Authorization이 존재하지 않습니다."; - - public EmptyAuthorizationHeaderException() { - super(MESSAGE); - } -} diff --git a/backend/src/main/java/org/donggle/backend/auth/exception/InvalidAccessTokenException.java b/backend/src/main/java/org/donggle/backend/auth/exception/InvalidAccessTokenException.java deleted file mode 100644 index f4260eb3d..000000000 --- a/backend/src/main/java/org/donggle/backend/auth/exception/InvalidAccessTokenException.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.donggle.backend.auth.exception; - -import org.donggle.backend.exception.business.BusinessException; - -public class InvalidAccessTokenException extends BusinessException { - private static final String MESSAGE = "유효하지 않은 토큰입니다."; - - public InvalidAccessTokenException() { - super(MESSAGE); - } -} diff --git a/backend/src/main/java/org/donggle/backend/auth/exception/NoSuchTokenException.java b/backend/src/main/java/org/donggle/backend/auth/exception/NoSuchTokenException.java deleted file mode 100644 index d6ec50c5c..000000000 --- a/backend/src/main/java/org/donggle/backend/auth/exception/NoSuchTokenException.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.donggle.backend.auth.exception; - -import org.donggle.backend.exception.business.BusinessException; - -public class NoSuchTokenException extends BusinessException { - private static final String MESSAGE = "존재하지 않는 토큰입니다."; - - public NoSuchTokenException() { - super(MESSAGE); - } -} diff --git a/backend/src/main/java/org/donggle/backend/ui/KakaoOAuthController.java b/backend/src/main/java/org/donggle/backend/ui/KakaoOAuthController.java index 8f20da78d..4548aad2f 100644 --- a/backend/src/main/java/org/donggle/backend/ui/KakaoOAuthController.java +++ b/backend/src/main/java/org/donggle/backend/ui/KakaoOAuthController.java @@ -21,16 +21,6 @@ public class KakaoOAuthController { private final int cookieTime; private final KakaoOAuthService kakaoOAuthService; - private final AuthService authService; - - public KakaoOAuthController(@Value("${security.jwt.token.refresh-token-expire-length}") final int cookieTime, - final KakaoOAuthService kakaoOAuthService, - final AuthService authService - ) { - this.cookieTime = cookieTime; - this.kakaoOAuthService = kakaoOAuthService; - this.authService = authService; - } public KakaoOAuthController(@Value("${security.jwt.token.refresh-token-expire-length}") final int cookieTime, final KakaoOAuthService kakaoOAuthService diff --git a/backend/src/test/java/org/donggle/backend/auth/JwtTokenProviderTest.java b/backend/src/test/java/org/donggle/backend/auth/JwtTokenProviderTest.java deleted file mode 100644 index 386aaea00..000000000 --- a/backend/src/test/java/org/donggle/backend/auth/JwtTokenProviderTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.donggle.backend.auth; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -class JwtTokenProviderTest { - - private final JwtTokenProvider jwtTokenProvider = new JwtTokenProvider( - "wjdgustmdwjdgustmdwjdgustmdwjsadasdgustmdwjdgustmdwjdgustmdwjdgustmdwjdgustmdwjdgustmdwjdgustmdwjdgustmdwjdgustmdwjdgustmd", - 600000, - 1200000 - ); - - @Test - @DisplayName("RefreshToken 발급 테스트") - void createRefreshToken() { - //given - //when - final String token = jwtTokenProvider.createRefreshToken(1234L); - final Long payload = jwtTokenProvider.getPayload(token); - - //then - assertThat(payload).isEqualTo(1234L); - } - - @Test - @DisplayName("AccessToken 발급 테스트") - void createAccessToken() { - //given - //when - final String token = jwtTokenProvider.createAccessToken(23L); - final Long payload = jwtTokenProvider.getPayload(token); - - //then - assertThat(payload).isEqualTo(23L); - } -} \ No newline at end of file