-
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
[43] AOP 를 사용한 권한 체크 #45
Conversation
|
||
private static final String AUTHORIZATION = "Authorization"; | ||
private static final String BEARER_PREFIX = "Bearer "; | ||
private final HttpServletRequest httpServletRequest; |
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.
이 request는 어디서 받아오나요?
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.
클라이언트가 서버에 요청을 보내면 tomcat 이 이를 수신하고 디스패쳐 서블릿으로 보냅니다.
디스패쳐 서블릿은 모든 http 요청을 가로채서 요청이 처리 되는 동안에 유효한 HttpServletRequest 객체를 만들고 스프링에서 이를 주입해줍니다.
return jwtDecoder.decode(token); | ||
} catch (JwtException e) { | ||
log.error(e.getMessage()); | ||
throw new JwtException(e.getMessage()); |
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.
헉 커스텀 예외처리해 500이 뜨도록 수정했습니다
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.
500은 서버가 에러난 상황인데, 지금은 어떤 에러코드가 좋을지 한번더 고민해보면 좋을 것 같습니다.
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 디코딩은 인증과 관련된 문제이므로 401 이 더 알맞을 것 같네요
@@ -16,6 +16,9 @@ public enum ErrorCode { | |||
INVALID_PARAM(HttpStatus.BAD_REQUEST, 400, "잘못된 parameter 입니다."), | |||
ACCESS_DENIED(HttpStatus.FORBIDDEN, 403, "권한이 부족합니다."), | |||
METHOD_NOT_ALLOWED(HttpStatus.METHOD_NOT_ALLOWED, 405, "허용되지 않은 메소드 입니다."), | |||
//auth | |||
JWT_DECODING_ERROR(HttpStatus.NOT_FOUND, 500, "JWT Decoding error"), |
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.
맞는 상태코드 내려주면 좋을 것 같습니다
@@ -17,7 +17,7 @@ public enum ErrorCode { | |||
ACCESS_DENIED(HttpStatus.FORBIDDEN, 403, "권한이 부족합니다."), | |||
METHOD_NOT_ALLOWED(HttpStatus.METHOD_NOT_ALLOWED, 405, "허용되지 않은 메소드 입니다."), | |||
//auth | |||
JWT_DECODING_ERROR(HttpStatus.NOT_FOUND, 500, "JWT Decoding error"), | |||
JWT_DECODING_ERROR(HttpStatus.NOT_FOUND, 401, "JWT Decoding error"), |
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.
httpStatus도 맞추면 좋을 것 같습니다. HttpStatus와 code를 각각 받아야할까요?
UserCheck, PartnerCheck 어노테이션을 만들어서, 어노테이션이 적용된 메서드에 토큰 권한을 체크하는 로직을 AOP로 만들었습니다.