-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Redis를 통한 Refresh Token 도입 (#131)
* feat: redis를 활용한 리프레시 토큰 로직 구현 * fix: 필드명 수정 * feat: 로그인 인터셉터 accessToken 검증 로직 수정 * style: 줄바꿈 * test: 테스트 코드 리프레시 토큰 검증 코드 추가 * feat: OAuth 리프레시 토큰 로직 코드 추가 * test: OAuth 테스트 코드 리프레시 토큰 검증 코드 추가 * fix: 토큰 검증 메서드 분리 * test: 테스트 환경변수 추가 * test: 리프레시 토큰 검증 테스트 코드 추가 * fix: 액세스 토큰과 리프레시 토큰 만료기간 분리 * feat: oauth 로그인 시 redis에 토큰 저장 로직 추가 * fix: 리프레시 토큰 로직 수정 * fix: 인증 토큰 관련 예외 수정 * test: 리프레시 서비스 테스트 코드 작성 * style: 액세스 토큰 재발급 메서드 명 변경 * test: 액세스 토큰 재발급 관련 테스트 코드 추가 * feat: 액세스 토큰 재발급 관련 인수 테스트 코드 추가 * style: 줄바꿈 적용 및 주석 삭제 * fix: ReissueTokenResponse 추가 * style: 한 줄 띄기 추가 * style: 한 줄 띄기 추가 * style: 사용하지 않는 메서드 제거 * fix: Refresh Token UUID 생성 로직으로 변경 * test: application.yml * fix: 리프레시 토큰 로직 수정 * refact: 코드 인라인으로 수정 * delete: 사용하지 않는 예외 파일 삭제 * test: 리프레시 토큰 검증 테스트 코드 수정 * test: 테스트 코드 삭제 * style: 사용하지 않는 로깅 삭제 * style: 리프레시 토큰 정보 추출 메서드 명 수정 * style: 함수 인자 변경 * refact: response 신고 필드 제거 * refactor: delete unused code * refactor: configure refresh token validity period using @value from yml * refact: move createRefreshToken method to Token * feat: add handling for NPE in findTokenByRefreshToken * feat: add updateToken method in RefreshTokenService * style: remove redundant null check logic * test: add reissueAccessToken test * refact: refact reissue token logic and test code * style: remove @transactional * style: remove @Sl4fj in AuthServiceTest * feat: change access-key-expire-length for test * style: remove unused reportesCount field --------- Co-authored-by: 임지수 <[email protected]>
- Loading branch information
Showing
37 changed files
with
501 additions
and
123 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package mocacong.server.domain; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.data.redis.core.TimeToLive; | ||
|
||
import javax.persistence.Id; | ||
import java.util.UUID; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class Token { | ||
|
||
@Id | ||
private Long id; | ||
|
||
private String refreshToken; | ||
|
||
private String accessToken; | ||
|
||
@TimeToLive(unit = TimeUnit.MILLISECONDS) | ||
private long expiration; | ||
|
||
public void setAccessToken(String newAccessToken) { | ||
this.accessToken = newAccessToken; | ||
} | ||
|
||
public static String createRefreshToken() { | ||
return UUID.randomUUID().toString(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/mocacong/server/dto/request/RefreshTokenRequest.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,15 @@ | ||
package mocacong.server.dto.request; | ||
|
||
import lombok.*; | ||
|
||
import javax.validation.constraints.NotBlank; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
@Getter | ||
@ToString | ||
public class RefreshTokenRequest { | ||
|
||
@NotBlank(message = "1012:공백일 수 없습니다.") | ||
private String 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,4 @@ | |
public class CafeImageReportResponse { | ||
|
||
private int cafeImageReportCount; | ||
|
||
private int userReportCount; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,4 @@ | |
public class CommentReportResponse { | ||
|
||
private int commentReportCount; | ||
|
||
private int userReportCount; | ||
} |
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 |
---|---|---|
|
@@ -9,6 +9,4 @@ | |
public class CommentSaveResponse { | ||
|
||
private Long id; | ||
|
||
private int userReportCount; | ||
} |
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 |
---|---|---|
|
@@ -9,6 +9,4 @@ | |
public class FavoriteSaveResponse { | ||
|
||
private Long favoriteId; | ||
|
||
private int userReportCount; | ||
} |
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
20 changes: 20 additions & 0 deletions
20
src/main/java/mocacong/server/dto/response/ReissueTokenResponse.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,20 @@ | ||
package mocacong.server.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@ToString | ||
public class ReissueTokenResponse { | ||
private String accessToken; | ||
|
||
private int userReportCount; | ||
|
||
public static ReissueTokenResponse from(final String accessToken, int userReportCount) { | ||
return new ReissueTokenResponse(accessToken, userReportCount); | ||
} | ||
} |
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/mocacong/server/exception/badrequest/NotExpiredAccessTokenException.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 mocacong.server.exception.badrequest; | ||
|
||
public class NotExpiredAccessTokenException extends BadRequestException { | ||
|
||
public NotExpiredAccessTokenException() { | ||
super("아직 만료되지 않은 액세스 토큰입니다", 1022); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/mocacong/server/exception/unauthorized/AccessTokenExpiredException.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,15 @@ | ||
package mocacong.server.exception.unauthorized; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class AccessTokenExpiredException extends UnauthorizedException { | ||
|
||
public AccessTokenExpiredException() { | ||
super("Access Token 유효기간이 만료되었습니다.", 1014); | ||
} | ||
|
||
public AccessTokenExpiredException(String message) { | ||
super(message, 1014); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/mocacong/server/exception/unauthorized/InvalidAccessTokenException.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 mocacong.server.exception.unauthorized; | ||
|
||
public class InvalidAccessTokenException extends UnauthorizedException { | ||
|
||
public InvalidAccessTokenException() { | ||
super("올바르지 않은 Access Token 입니다. 다시 로그인해주세요.", 1015); | ||
} | ||
|
||
public InvalidAccessTokenException(String message) { | ||
super(message, 1015); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/mocacong/server/exception/unauthorized/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,11 @@ | ||
package mocacong.server.exception.unauthorized; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class InvalidRefreshTokenException extends UnauthorizedException { | ||
|
||
public InvalidRefreshTokenException() { | ||
super("올바르지 않은 Refresh Token 입니다. 다시 로그인해주세요.", 1021); | ||
} | ||
} |
12 changes: 0 additions & 12 deletions
12
src/main/java/mocacong/server/exception/unauthorized/InvalidTokenException.java
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
src/main/java/mocacong/server/exception/unauthorized/TokenExpiredException.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.