-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: 기존에 한 클래스에서 사용하던 기능 분리 작업 진행 * feat: 로그아웃 기능 추가 * refactor: 쿠키 헤더 설정 변경 * feat: AdminAuthService 로직 수정 및 로그아웃 기능 구현 * feat: 관리자 RT가 유효하지 않을 때 발생시킬 예외 클래스 추가 * feat: 관리자 리프레쉬 토큰의 정보를 저장하고 관리하는 도메인 클래스 생성 * feat: 관리자 리프레쉬 토큰을 저장하기 위한 Repository 구현 * refactor: TokenProvider의 기능 분리로 인한 코드 수정 * remove: 불필요한 클래스 제거 - AdminTokenProvider. * feat: redis를 추가하기 위한 설정파일 추가 * test: AdminRedisRefreshTokenRepository를 테스트하기 위한 Fake Repository 구현 * test: AdminRedisRefreshTokenRepository 테스트 클래스 작성 * test: 관리자 RT를 테스트에서 쉽게 사용하기 위해 Fixture 작성 * test: 관리자 로그아웃 기능 테스트 추가 * test: 프로덕션 코드 수정으로 인한 테스트 수정 * docs: build.gradle에 redis 설정 추가 * docs: application.yml에 redis 설정 추가 * test: application.yml에 redis 설정 추가 * docs: 관리자 명세서 최신화 * docs: 토큰 저장시간 암호화 * docs: CI 구성에 레디스 추가 * refactor: 메서드명 변경 login -> logout * refactor: admin 생성하는 로직 메서드 분리 * refactor: 도메인 객체에 불필요하게 존재했던 @id 어노테이션 제거 * refactor: 공백 제거 * refactor: 클래스명 변경 AdminJwtAccessTokenProvider -> AdminJwtTokenProvider * refactor: AdminRefreshToken 키 값에 @id 추가
- Loading branch information
1 parent
6245b56
commit 8f51049
Showing
27 changed files
with
440 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/java/com/atwoz/admin/application/auth/AdminAccessTokenProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.atwoz.admin.application.auth; | ||
|
||
public interface AdminAccessTokenProvider { | ||
|
||
String createAccessToken(Long id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/com/atwoz/admin/domain/admin/AdminRefreshToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.atwoz.admin.domain.admin; | ||
|
||
import com.atwoz.admin.domain.admin.service.AdminRefreshTokenProvider; | ||
import lombok.Builder; | ||
import org.springframework.data.annotation.Id; | ||
|
||
@Builder | ||
public record AdminRefreshToken( | ||
@Id String refreshToken, | ||
Long memberId | ||
) { | ||
|
||
public static AdminRefreshToken createWith(final AdminRefreshTokenProvider adminRefreshTokenProvider, | ||
final String email, | ||
final Long memberId) { | ||
return AdminRefreshToken.builder() | ||
.refreshToken(adminRefreshTokenProvider.createRefreshToken(email)) | ||
.memberId(memberId) | ||
.build(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/atwoz/admin/domain/admin/AdminRefreshTokenRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.atwoz.admin.domain.admin; | ||
|
||
import java.util.Optional; | ||
|
||
public interface AdminRefreshTokenRepository { | ||
|
||
void save(AdminRefreshToken adminRefreshToken); | ||
|
||
Optional<AdminRefreshToken> findById(String refreshToken); | ||
|
||
void delete(String refreshToken); | ||
} |
10 changes: 0 additions & 10 deletions
10
src/main/java/com/atwoz/admin/domain/admin/AdminTokenProvider.java
This file was deleted.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
src/main/java/com/atwoz/admin/domain/admin/service/AdminRefreshTokenProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.atwoz.admin.domain.admin.service; | ||
|
||
public interface AdminRefreshTokenProvider { | ||
|
||
String createRefreshToken(String email); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/com/atwoz/admin/exception/exceptions/InvalidRefreshTokenException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.atwoz.admin.exception.exceptions; | ||
|
||
public class InvalidRefreshTokenException extends RuntimeException { | ||
|
||
public InvalidRefreshTokenException() { | ||
super("리프레쉬 토큰이 유효하지 않습니다"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/com/atwoz/admin/infrastructure/auth/AdminRedisRefreshTokenRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.atwoz.admin.infrastructure.auth; | ||
|
||
import com.atwoz.admin.domain.admin.AdminRefreshToken; | ||
import com.atwoz.admin.domain.admin.AdminRefreshTokenRepository; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.concurrent.TimeUnit; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.core.ValueOperations; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@RequiredArgsConstructor | ||
@Repository | ||
public class AdminRedisRefreshTokenRepository implements AdminRefreshTokenRepository { | ||
|
||
@Value("${redis.expiration-period}") | ||
private int expirationPeriod; | ||
|
||
private final RedisTemplate<String, Long> redisTemplate; | ||
|
||
@Override | ||
public void save(final AdminRefreshToken adminRefreshToken) { | ||
ValueOperations<String, Long> valueOperations = redisTemplate.opsForValue(); | ||
valueOperations.set(adminRefreshToken.refreshToken(), adminRefreshToken.memberId()); | ||
redisTemplate.expire(adminRefreshToken.refreshToken(), expirationPeriod, TimeUnit.DAYS); | ||
} | ||
|
||
@Override | ||
public Optional<AdminRefreshToken> findById(final String refreshToken) { | ||
ValueOperations<String, Long> valueOperations = redisTemplate.opsForValue(); | ||
Long memberId = valueOperations.get(refreshToken); | ||
if (Objects.isNull(memberId)) { | ||
return Optional.empty(); | ||
} | ||
|
||
return Optional.of(new AdminRefreshToken(refreshToken, memberId)); | ||
} | ||
|
||
@Override | ||
public void delete(final String refreshToken) { | ||
redisTemplate.delete(refreshToken); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.