Skip to content

Conversation

@sejoon00
Copy link
Contributor

@sejoon00 sejoon00 commented Jan 23, 2025

🌱 관련 이슈

📌 작업 내용 및 특이사항

  • 저번에 구현한 이메일 패스워드 인증 후 인증 상태 유지를 위해 JwtAuthenticationFilter를 spring security에 추가하였습니다.

  • image
  • 빨간 색으로 표시한 부분이 추가 필터 로직입니다.

  • 저번에 구성하였던 AuthenticationManger에 AuthenticationProvider를 구현한 JwtTokenProvider를 추가하여 여러개의 인증 Provider 관리 책임은 Manger가 하도록 유지했습니다.

  • Jwt를 인증하는 책임은 JwtTokenProvider가 맡습니다.

  • Filter의 순서는 JwtAuthenticationFilter -> EmailPasswordAuthenticationFilter 순 입니다. 토큰이 없을 시 다음 이메일 패스워드 필터로 넘어가는 순서입니다. 아무 인증도 없을 시 예외가 발생하고 authenticationEntryPoint가 공통적으로 처리합니다.

📝 테스트사항

image
  • jwt유효성 검사가 잘 이우러지는지 테스트를 추가했습니다.
  • 기존 로그인 방식의 인증 통합 테스트도 잘 이루어지는 것을 볼 수 있습니다.

🎯 트러블 슈팅

  • JwtAuthenticationFilter를 추가하며 기존 로그인 통합테스트가 실패했었습니다.
    • 원인1 : spring security 6.x.x 버전으로 올라오면서 AuthenticationManger 등록방식이 수정되어서 반영하였습니다.

    • 원인2 : 기존 로그인 인증은 jwt토큰이 없는데 여기서 인증이 실패하게 되고 다음 필터로 넘어가야하는데 넘어가지 못하고 다시 jwt인증을 무한 방복하는 이슈가 있었습니다.

    • image
    • ProviderManager는 인증이 실패하면 부모 manger의 authenticate()를 호출하게 되는데 여기서 자기 자신이 부모로 초기화되어 있었습니다.
      AuthenticationManger 등록 방식이 바뀌면서 명시적으로 AuthenticationManger의 parent를 null처리하지 않으면 자기 자신이 부모로 잡히게 됩니다. 명시적으로 null처리 하여 해결하였습니다.

📚 기타

해당 branch 위에서 작업 된 PR #16 이 존재합니다

@sejoon00 sejoon00 added Type: Feature [이슈 목적] 새로운 기능 추가 For: Utils [이슈 대상] API, 모델, 뷰를 제외한 백엔드 로직 labels Jan 23, 2025
@sejoon00 sejoon00 self-assigned this Jan 23, 2025
@sejoon00 sejoon00 requested a review from seokbeom00 January 23, 2025 08:18
Copy link
Contributor

@seokbeom00 seokbeom00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다!
트러블슈팅 부분 덕분에 배워갑니다~

@sejoon00 sejoon00 merged commit c5c4bc2 into develop Jan 28, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For: Utils [이슈 대상] API, 모델, 뷰를 제외한 백엔드 로직 Type: Feature [이슈 목적] 새로운 기능 추가

Projects

None yet

Development

Successfully merging this pull request may close these issues.

✨ spring security jwt 인증 구현

3 participants