Skip to content

Commit

Permalink
refactor: 코드 스타일 개선 및 불필요 코드 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
Zepelown committed Dec 7, 2024
1 parent 2bc8db3 commit ae9544e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -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<AdminRefreshToken, Long> {
Optional<AdminRefreshToken> findAdminRefreshTokenByAdminNameAndReissueCountLessThan(String name, long count);

Optional<AdminRefreshToken> findAdminRefreshTokenByAdminName(String name);
}
19 changes: 0 additions & 19 deletions wabi/src/main/kotlin/com/wap/wabi/auth/jwt/JwtTokenProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit ae9544e

Please sign in to comment.