[feat/#11] jwt 인증 필터 구현 #14
Merged
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.
🌱 관련 이슈
📌 작업 내용 및 특이사항
저번에 구현한 이메일 패스워드 인증 후 인증 상태 유지를 위해 JwtAuthenticationFilter를 spring security에 추가하였습니다.
빨간 색으로 표시한 부분이 추가 필터 로직입니다.
저번에 구성하였던 AuthenticationManger에 AuthenticationProvider를 구현한 JwtTokenProvider를 추가하여 여러개의 인증 Provider 관리 책임은 Manger가 하도록 유지했습니다.
Jwt를 인증하는 책임은 JwtTokenProvider가 맡습니다.
Filter의 순서는 JwtAuthenticationFilter -> EmailPasswordAuthenticationFilter 순 입니다. 토큰이 없을 시 다음 이메일 패스워드 필터로 넘어가는 순서입니다. 아무 인증도 없을 시 예외가 발생하고 authenticationEntryPoint가 공통적으로 처리합니다.
📝 테스트사항
🎯 트러블 슈팅
원인1 : spring security 6.x.x 버전으로 올라오면서 AuthenticationManger 등록방식이 수정되어서 반영하였습니다.
원인2 : 기존 로그인 인증은 jwt토큰이 없는데 여기서 인증이 실패하게 되고 다음 필터로 넘어가야하는데 넘어가지 못하고 다시 jwt인증을 무한 방복하는 이슈가 있었습니다.
ProviderManager는 인증이 실패하면 부모 manger의 authenticate()를 호출하게 되는데 여기서 자기 자신이 부모로 초기화되어 있었습니다.
AuthenticationManger 등록 방식이 바뀌면서 명시적으로 AuthenticationManger의 parent를 null처리하지 않으면 자기 자신이 부모로 잡히게 됩니다. 명시적으로 null처리 하여 해결하였습니다.
📚 기타
해당 branch 위에서 작업 된 PR #16 이 존재합니다