-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor : ArgumentResolver -> Interceptor로 변경 #200
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
65f5ad7
feat : JwtInterceptor 클래스 추가
2iedo cff9f6a
refactor : 순환 참조 방지를 위해 메소드 분리
2iedo 4c5dca7
feat : JwtInterceptor 적용
2iedo 97f1368
refactor : 순환 참조 방지를 위해 메소드 분리
2iedo 40b151a
refactor : 리뷰 조회 경로 변경
2iedo 45578cf
feat : memberId 수정
2iedo c144376
refactor : 테스트 코드 수정
2iedo aca9fa0
refactor : review 경로 변경
2iedo 4b53de1
feat : 메소드의 파라미터에 Long 타입이 있을 때(memberId가 있을 때) jwt 검증하도록 수정
2iedo cb4de56
refactor : 수정했던 경로 복구
2iedo 3ea9b00
merge
2iedo 849c308
refactor : 관리자용 메소드의 memberId 파라미터 삭제
2iedo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -5,8 +5,11 @@ | |
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.method.HandlerMethod; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
@Component | ||
public class JwtInterceptor implements HandlerInterceptor { | ||
private final MemberTokenService memberTokenService; | ||
|
@@ -16,14 +19,26 @@ public JwtInterceptor(MemberTokenService memberTokenService){ | |
} | ||
@Override | ||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler){ | ||
String authorizationHeader = request.getHeader("Authorization"); | ||
if (authorizationHeader == null || !authorizationHeader.startsWith("Bearer ")) { | ||
throw new UnauthorizedException("토큰이 없거나, 헤더 형식에 맞지 않습니다."); | ||
} | ||
if (handler instanceof HandlerMethod) { | ||
HandlerMethod handlerMethod = (HandlerMethod) handler; | ||
Method method = handlerMethod.getMethod(); | ||
|
||
Class<?>[] parameterTypes = method.getParameterTypes(); | ||
|
||
String token = authorizationHeader.substring(7); | ||
for (Class<?> paramType : parameterTypes) { | ||
if (paramType.equals(Long.class)) { | ||
String authorizationHeader = request.getHeader("Authorization"); | ||
if (authorizationHeader == null || !authorizationHeader.startsWith("Bearer ")) { | ||
throw new UnauthorizedException("토큰이 없거나, 헤더 형식에 맞지 않습니다."); | ||
} | ||
|
||
request.setAttribute("memberId", memberTokenService.getMemberIdByToken(token)); | ||
String token = authorizationHeader.substring(7); | ||
|
||
request.setAttribute("memberId", memberTokenService.getMemberIdByToken(token)); | ||
return true; | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아 이해했습니다. 오 이런방식이 ㅎ.ㄷ |
||
|
||
return true; | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍