-
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
Conversation
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.
변경하시느라 고생하셨습니다! 궁금한거 코멘트하나 남겼습니다 :)
guardService.deleteGuard(memberId); | ||
return ResponseEntity.ok("보호자가 삭제되었습니다."); | ||
} | ||
|
||
@Operation(summary = "모든 보호자 조회", description = "관리자용 API입니다.") | ||
@GetMapping("/all") | ||
public ResponseEntity<List<GuardResponse>> getAllGuards(@MemberId Long memberId) { | ||
public ResponseEntity<List<GuardResponse>> getAllGuards(@RequestAttribute("memberId") Long memberId) { |
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.
이 메서드에서는 memberId
가 안쓰이는데 필요한 이유가 있을까요? HelloCallController 에도 3개정도 안쓰이는 memberId
가있는데 사용 안하면 제거하는게 깔끔하지 않나 하는 생각입니다!
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.
관리자용은 나중에 따로 보안을 적용해서 제거하는게 옳다고 생각하지만, HelloCallController에 있는 memberId의 경우 제거했을 때 회원이 아니어도 조회가 가능하다고 생각되어 일단 남겨두겠습니다!
@Override | ||
public void addInterceptors(InterceptorRegistry registry) { | ||
registry.addInterceptor(jwtInterceptor).addPathPatterns("/api/**") | ||
.excludePathPatterns("/api/auth/**") | ||
.excludePathPatterns("/api/reviews") | ||
.excludePathPatterns("/api/members/sinitto") | ||
.excludePathPatterns("/api/members/guard") | ||
.excludePathPatterns("/api/reviews/all") | ||
.excludePathPatterns("/api/callbacks/twilio") | ||
.excludePathPatterns("/api/hellocalls/admin/reports"); | ||
} |
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.
콜백, 포인트 관련해서는 이상없이 잘 제외해주신거 같습니다!
@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 comment
The reason will be displayed to describe this comment to others. Learn more.
아 이해했습니다. 오 이런방식이 ㅎ.ㄷ
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.
인터셉터로 JWT 인증하는 방식으로 깔끔하게 잘 바꿔주신 것 같아요!
인증 제외한 path도 확인해봤는데 제가 맡은 부분은 문제없을 것 같습니다
수고많으셨어요 😄
if (paramType.equals(Long.class)) { | ||
String authorizationHeader = request.getHeader("Authorization"); | ||
if (authorizationHeader == null || !authorizationHeader.startsWith("Bearer ")) { | ||
throw new UnauthorizedException("토큰이 없거나, 헤더 형식에 맞지 않습니다."); | ||
} |
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.
👍
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.
효율적인 방법인것 같네요 👍
고생하셨습니다 ㅎㅎ
Class<?>[] parameterTypes = method.getParameterTypes(); | ||
|
||
for (Class<?> paramType : parameterTypes) { | ||
if (paramType.equals(Long.class)) { |
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.
오 ㅋㅋ 신박하네요 👍
#️⃣ 연관된 이슈
📝 작업 내용
스크린샷 (선택)
💬 리뷰 요구사항(선택)
⏰ 현재 버그
✏ Git Close