-
Notifications
You must be signed in to change notification settings - Fork 1
[FEATURE] 액세스 토큰 클레임 추가 (역할 아이디) #309
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
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.
빌드에 실패했습니다.
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.
빌드에 실패했습니다.
ayoung-dev
left a comment
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.
수고하셨습니다아
|
|
||
| throw new InvalidAuthenticationException(INVALID_PRINCIPAL_TYPE); | ||
| } | ||
| } No newline at end of file |
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.
수정해씁니다!
| throw new InvalidAuthenticationException(AUTHENTICATION_MISSING); | ||
| } | ||
|
|
||
| if (authentication.getPrincipal() instanceof UserIdentity principal) { |
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.
authentication == null를 통과하면
authentication.getPrincipal()도 통과가 가능한건지 여쭤보고 싶습니다
Principal이 비어 있는 경우는 없겠죠?
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.
-
authentication == null를 통과하면, authentication.getPrincipal()은 NPE 없이 호출 가능합니다. 또한, principal이 null이거나 비어 있는 값으로 설정될 가능성은 없습니다.
-
authentication은 Spring Security의 인증 과정에서 생성되며, principal은 생성자에서 초기화됩니다.
인증이 성공하면 authentication은 항상 principal, credentials, authorities를 포함한 상태로 SecurityContext에 저장됩니다.
따라서 authentication이 null이 아닌 경우, principal 또한 초기화된 상태입니다. -
null instanceof UserIdentity
authentication.getPrincipal()이 null이라면, instanceof 연산에서 항상 false를 반환하므로, 안전하게 처리됩니다. -
Spring Security는 필터 체인에서 인증 객체를 생성한 후 SecurityContext에 저장합니다.
컨트롤러 레벨에서 접근하는 경우, 이미 인증 객체가 완전히 구성된 상태입니다.
만약 authentication이 제대로 초기화되지 않았다면, 컨트롤러까지 요청이 도달하지 못합니다.
사실 상 로직에서는 NPE 방어를 진행했고, 인증 객체가 올바르게 구성되지 않는 상황이나 익명 유저(토큰X)는 @Secured로 필터에서 처리되어 예외가 발생할 것 같습니다~
|
|
||
| return new InvalidAuthenticationException(INVALID_PRINCIPAL_TYPE); | ||
| } | ||
| } No newline at end of file |
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.
수정해씁니다!
| throw new InvalidAuthenticationException(AUTHENTICATION_MISSING); | ||
| } | ||
|
|
||
| if (authentication.getPrincipal() instanceof UserIdentity principal) { |
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.
이 부분도 RoleId 에서 리뷰 남긴 부분이라 코멘트 달아두겠습니다!
|
머리 아픈 부분들이 많으셨을거 같아요 감사합니다 고생하셨습니다! |
leebs0521
left a comment
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 claims에서 UUID 추출이 불가능해서 String으로 추출 후, UUID로 변경
6d76494 to
feb62fd
Compare
|



resolved :
📌 과제 설명
JWT의
accessToken클레임에roleId를 추가했습니다.roleId는volunteerId(pk)또는centerId(pk)의 역할을 합니다.이를 위해서 전체적인 로직 수정과 가독성을 위한 리팩토링을 진행했습니다.
또한 기존의 @currentuser로 처리할 수 있던 Spring Security의 인증 객체의 principal이 변경됨에 따라서 userId와 roleId 각각을 위한 어노테이션을 추가했습니다.
👩💻 요구 사항과 구현 내용
액세스 토큰 클레임 추가
어노테이션 추가
✅ PR 포인트 & 궁금한 점
인증이나 인가 관련 수정은 프레임워크 플로우를 따라가며 확인을 거치는 부분들이 많아서 수정마다 머리가 지끈지끈하네요.
눈에 띄는 실수가 없는지 가볍게 확인 부탁드리겠습니다!
어노테이션 사용법