-
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.
[REFACTOR] JWT 처리 방식 변경 및 리팩토링 (#223)
* feat: JwtService에 인터페이스 적용 - JwtService에 interface 적용 및 구현 클래스 적용 - Cookie의 sameSite 옵션을 strict로 설정 * refactor: JWT 요청 API의 Request DTO 변경 - /api/auth JWT 요청 API의 Request DTO를 의도에 맞도록 수정(TokenRequest) * refactor: 필요없는 구문 삭제 * refactor: JwtService의 의존 관계 변경 - JwtService의 의존관계를 TokenRepository에서 TokenService로 변경 - TokenService에 필요한 메서드 추가 * refactor: tokenService를 활용하는 코드로 리팩토링 - tokenRepository를 활용하는 코드에서 tokenService를 활용하는 코드로 변경 * refactor: Facade 패턴 적용 * feat: Access token 처리 방식 변경 - Access token의 저장 위치를 Authorization header로 변경 - Access token의 생성/resolve 방식 변경 - Access token의 정상 작동 확인 - 불필요한 로직 제거 필요 - JWT 테스트 코드 변경 필요 * refactor: enum 이름 변경 - JWT 관련 enum 상수 이름 변경 * test: JWT 처리 방식 변경에 의한 테스트 코드 변경 - JWT 중 Access token을 Header에 저장하는 것으로 바꾸면서 Controller 및 JWT 관련 테스트 코드 정상 작동하도록 수정 * fix: JWT 에러 메세지 변경 및 버그 픽스 - JWT 관련 에러 메세지를 세부적으로 나눔 - Refresh token의 탈취 여부를 확인하는 로직 버그 픽스 - Access token 추출 시, 빈 문자열일 때에도 예외를 발생하도록 변경 * test: JwtFacade 테스트 코드에 DCI 패턴 적용 * test: TokenService 테스트 코드에 DCI 패턴 적용 - TokenService 테스트 코드에 DCI 패턴 적용 - JWT 관련 예외 메세지 추가 * feat: JWT 처리 도중 Exception 발생 시, logout하도록 처리 - JWT에서 예외 발생 시 처리하는 ExceptionHandlerFilter에서 JWT 관련 Exception 발생 시, Logout 로직이 실행되도록 처리 * fix: logout 처리 위치 변경 * fix: custom header가 전달되지 않는 버그 픽스 * fix: 브라우저에서 Authorization 헤더 접근이 안되는 버그 픽스 - CorsConfigurationSource에 .setExposedHeaders 옵션 설정 * feat: Access token 재발급 여부 관련 헤더 추가 - Access token 재발급 여부에 따라 token-reissued에 값 설정 * fix: 브라우저에서 token-reissued 헤더 접근이 안되는 버그 픽스 * refactor: 불필요한 로직 제거 - ExceptionHandlerFilter에서 불필요한 로직 제거 * refactor: Facade 구현체 이름 통일 - Facade 구현체 이름을 FacadeImpl에서 FacadeService로 통일
- Loading branch information
Showing
28 changed files
with
584 additions
and
453 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
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/genius/gitget/global/security/dto/TokenRequest.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.genius.gitget.global.security.dto; | ||
|
||
public record TokenRequest( | ||
String identifier | ||
) { | ||
} |
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
28 changes: 28 additions & 0 deletions
28
src/main/java/com/genius/gitget/global/security/service/JwtFacade.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,28 @@ | ||
package com.genius.gitget.global.security.service; | ||
|
||
import com.genius.gitget.challenge.user.domain.User; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.springframework.security.core.Authentication; | ||
|
||
public interface JwtFacade { | ||
String generateAccessToken(HttpServletResponse response, User user); | ||
|
||
String generateRefreshToken(HttpServletResponse response, User user); | ||
|
||
String resolveAccessToken(HttpServletRequest request); | ||
|
||
String resolveRefreshToken(HttpServletRequest request); | ||
|
||
String getIdentifierFromRefresh(String refreshToken); | ||
|
||
boolean validateAccessToken(String accessToken); | ||
|
||
boolean validateRefreshToken(String refreshToken, String identifier); | ||
|
||
void setReissuedHeader(HttpServletResponse response); | ||
|
||
void logout(HttpServletResponse response, String identifier); | ||
|
||
Authentication getAuthentication(String accessToken); | ||
} |
Oops, something went wrong.