From ae9544e390a32f81fc517d1ff22b95dd1c614a1d Mon Sep 17 00:00:00 2001 From: Zepelown Date: Sat, 7 Dec 2024 13:53:21 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=BD=94=EB=93=9C=20=EC=8A=A4?= =?UTF-8?q?=ED=83=80=EC=9D=BC=20=EA=B0=9C=EC=84=A0=20=EB=B0=8F=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=20=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdminRefreshTokenRepository.java | 3 ++- .../com/wap/wabi/auth/jwt/JwtTokenProvider.kt | 19 ------------------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/wabi/src/main/kotlin/com/wap/wabi/auth/admin/repository/AdminRefreshTokenRepository.java b/wabi/src/main/kotlin/com/wap/wabi/auth/admin/repository/AdminRefreshTokenRepository.java index c83fc5a..6e9b2f7 100644 --- a/wabi/src/main/kotlin/com/wap/wabi/auth/admin/repository/AdminRefreshTokenRepository.java +++ b/wabi/src/main/kotlin/com/wap/wabi/auth/admin/repository/AdminRefreshTokenRepository.java @@ -1,13 +1,14 @@ package com.wap.wabi.auth.admin.repository; import com.wap.wabi.auth.admin.entity.AdminRefreshToken; -import org.apache.poi.sl.draw.geom.GuideIf; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import java.util.Optional; + @Repository public interface AdminRefreshTokenRepository extends JpaRepository { Optional findAdminRefreshTokenByAdminNameAndReissueCountLessThan(String name, long count); + Optional findAdminRefreshTokenByAdminName(String name); } diff --git a/wabi/src/main/kotlin/com/wap/wabi/auth/jwt/JwtTokenProvider.kt b/wabi/src/main/kotlin/com/wap/wabi/auth/jwt/JwtTokenProvider.kt index b2df493..80c73b8 100644 --- a/wabi/src/main/kotlin/com/wap/wabi/auth/jwt/JwtTokenProvider.kt +++ b/wabi/src/main/kotlin/com/wap/wabi/auth/jwt/JwtTokenProvider.kt @@ -92,25 +92,6 @@ class JwtTokenProvider( .build() .parseClaimsJws(token)!! - @Transactional - fun reissueAccessToken(refreshToken: String, oldAccessToken: String): String { - // 리프레시 토큰과 기존 액세스 토큰의 유효성 검사 - validateAndParseToken(refreshToken) - val subject = decodeJwtPayloadSubject(oldAccessToken) - val adminName = subject.split(':')[0] - - adminRefreshTokenRepository.findAdminRefreshTokenByAdminNameAndReissueCountLessThan(adminName, reissueLimit) - .ifPresentOrElse( - { it.validateRefreshToken(refreshToken) - it.increaseReissueCount() - }, - { throw ExpiredJwtException(null, null, "Refresh token expired or invalid.") } - ) - - // 새로운 액세스 토큰 발급 - return createAccessToken(subject) - } - private fun decodeJwtPayloadSubject(oldAccessToken: String) = objectMapper.readValue( Base64.getUrlDecoder().decode(oldAccessToken.split('.')[1]).decodeToString(),