-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* chore: redis 의존성 추가 * refactor: OauthService 필드에 final 추가 * feat: refreshToken 엔티티 및 레포지토리 구현 * feat: JwtTokenProvider RefreshToken 발급 구현 * feat: 로그인 시 RefreshToken 발급 기능 구현 * feat: Auth 패키지 커스텀 예외 추가 * refactor: validate 메서드 리팩터링 * chore: refreshToken 만료 시간 추가 * test: Test를 위한 설정 변경 * feat: 액세스 토큰 재발급 및 로그아웃 기능 구현 * chore: Redis 의존성 제거 * test: TestTokenProvider 객체 구현 * refactor: /logout HttpMethod 변경, cookie 관련 cors설정 및 maxAge 설정, * test: DisplayName 추가 * feat: RTR 적용 및 OauthConntroller 제거, OauthService 및 TokenService 역할과 책임 재분배 * refactor : 피드백 반영 * refactor : 매직넘버 상수화 * refactor : 네이밍 수정 * feat: 쿠키 설정 추가
- Loading branch information
1 parent
3c358c3
commit 303a5fb
Showing
6 changed files
with
125 additions
and
43 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
backend/src/main/java/com/mapbefine/mapbefine/auth/exception/AuthErrorCode.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,22 @@ | ||
package com.mapbefine.mapbefine.auth.exception; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum AuthErrorCode { | ||
ILLEGAL_MEMBER_ID("01100", "로그인에 실패하였습니다."), | ||
ILLEGAL_TOKEN("01101", "로그인에 실패하였습니다."), | ||
FORBIDDEN_ADMIN_ACCESS("01102", "로그인에 실패하였습니다."), | ||
BLOCKING_MEMBER_ACCESS("01103", "로그인에 실패하였습니다."), | ||
EXPIRED_TOKEN("01104", "기간이 만료된 토큰입니다.") | ||
; | ||
|
||
private final String code; | ||
private final String message; | ||
|
||
AuthErrorCode(String code, String message) { | ||
this.code = code; | ||
this.message = message; | ||
} | ||
|
||
} |
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
70 changes: 70 additions & 0 deletions
70
backend/src/main/java/com/mapbefine/mapbefine/common/interceptor/AdminAuthInterceptor.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,70 @@ | ||
package com.mapbefine.mapbefine.common.interceptor; | ||
|
||
import com.mapbefine.mapbefine.auth.application.AuthService; | ||
import com.mapbefine.mapbefine.auth.dto.AuthInfo; | ||
import com.mapbefine.mapbefine.auth.exception.AuthErrorCode; | ||
import com.mapbefine.mapbefine.auth.exception.AuthException; | ||
import com.mapbefine.mapbefine.auth.infrastructure.AuthorizationExtractor; | ||
import com.mapbefine.mapbefine.auth.infrastructure.TokenProvider; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import java.util.Objects; | ||
import org.springframework.lang.NonNull; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.method.HandlerMethod; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
|
||
@Component | ||
public class AdminAuthInterceptor implements HandlerInterceptor { | ||
|
||
private final AuthorizationExtractor<AuthInfo> authorizationExtractor; | ||
private final AuthService authService; | ||
private final TokenProvider tokenProvider; | ||
|
||
public AdminAuthInterceptor( | ||
AuthorizationExtractor<AuthInfo> authorizationExtractor, | ||
AuthService authService, | ||
TokenProvider tokenProvider | ||
) { | ||
this.authorizationExtractor = authorizationExtractor; | ||
this.authService = authService; | ||
this.tokenProvider = tokenProvider; | ||
} | ||
|
||
@Override | ||
public boolean preHandle( | ||
@NonNull HttpServletRequest request, | ||
@NonNull HttpServletResponse response, | ||
@NonNull Object handler | ||
) { | ||
if (!(handler instanceof HandlerMethod)) { | ||
return true; | ||
} | ||
|
||
Long memberId = extractMemberIdFromToken(request); | ||
|
||
validateAdmin(memberId); | ||
request.setAttribute("memberId", memberId); | ||
|
||
return true; | ||
} | ||
|
||
private Long extractMemberIdFromToken(HttpServletRequest request) { | ||
AuthInfo authInfo = authorizationExtractor.extract(request); | ||
if (Objects.isNull(authInfo)) { | ||
return null; | ||
} | ||
tokenProvider.validateAccessToken(authInfo.accessToken()); | ||
|
||
return Long.parseLong(tokenProvider.getPayload(authInfo.accessToken())); | ||
} | ||
|
||
private void validateAdmin(Long memberId) { | ||
if (authService.isAdmin(memberId)) { | ||
return; | ||
} | ||
|
||
throw new AuthException.AuthForbiddenException(AuthErrorCode.FORBIDDEN_ADMIN_ACCESS); | ||
} | ||
|
||
} |
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