Skip to content

Conversation

@bo-ram-bo-ram
Copy link
Member

@bo-ram-bo-ram bo-ram-bo-ram commented Apr 22, 2025

Pull request

Related issue

Motivation and context

  • spring cloud gateway는 webflux기반 비동기 방식으로 구현되어있지만 인증서버는 mvc로 구현되어 블로킹이 발생하고 있었습니다. 이를 해결하기 위해 인증 서버를 WebFlux 환경으로 변경했습니다.

  • 기존 Spring MVC 기반의 인증 서버에서 WebFlux 환경으로 전환하면서 발생하는 다양한 문제들을 해결했습니다.

  • 기존에 사용하던 @Transactional, JpaRepository, WebMvcConfigurer 등 MVC 전용 기능들이 WebFlux에서 지원되지 않아 동작하지 않음

  • Redis에 reactive repository를 사용하려 했지만, Spring Data Redis는 reactive를 지원하지 않음 → CrudRepository로 유지

  • Kakao 로그인 시 FeignClient를 사용하는 방식이 blocking이라 WebClient로 전환

  • 인증 관련 에러 응답을 Mono 흐름 안에서 처리할 수 있도록 커스텀 핸들러 구현 필요

Solution

WebFlux 기반으로 인증 서버 전반을 리팩토링했습니다:

1. WebClient 기반 Kakao 소셜 로그인 구현

  • 기존 FeignClient → WebClient로 전환
  • KakaoAuthWebClientServiceKakaoApiClient 생성
  • KakaoSocialService에서 Mono 체인으로 처리

2. 전반적인 reactive 환경 전환

  • Controller, Service, Repository 전반에서 Mono<T> 적용
  • UserRepositoryReactiveCrudRepository로 교체
  • 사용자 정보 저장/조회/닉네임 수정 등 비동기 처리

3. JWT 인증 필터 및 예외 처리

  • JwtAuthenticationFilter를 WebFilter로 재작성
  • ReactiveAuthenticationManager, ServerAuthenticationConverter 구현
  • CustomAccessDeniedHandler, CustomJwtAuthenticationEntryPoint 수정
  • GlobalExceptionHandler를 WebFlux에 맞게 Mono 기반으로 전환

4. 기타 변경 사항

  • application.yml 환경설정 WebFlux에 맞게 정리
  • Swagger 및 의존성 설정 정비
  • Spring Security 설정을 WebFlux 방식으로 전환

5. 추가 트러블슈팅

  • Gateway → Auth 서버로 passport 정보를 전달하고 @currentuser UserInfo로 주입받는 과정에서 WebFlux 환경에서 기존 MVC 방식의 HandlerMethodArgumentResolver가 동작하지 않는 이슈 발생
    • HandlerMethodArgumentResolver를 WebFlux 전용 인터페이스인 org.springframework.web.reactive.result.method.HandlerMethodArgumentResolver로 교체
    • resolveArgument() 내부 구현을 Mono 기반으로 수정하고, X-Passport-User 헤더 파싱 및 UserInfo 역직렬화 처리
    • 설정 클래스 또한 WebMvcConfigurer → WebFluxConfigurer로 교체하고, addArgumentResolvers()를 오버라이드하여 resolver 등록
    • common_module에 spring-boot-starter-webflux 의존성 추가하여 WebFluxConfigurer 사용 가능하도록 설정
    • How has this been tested

      • Postman으로 Kakao 로그인부터 JWT 발급, 유저 정보 조회, 닉네임 수정 등 전 흐름을 테스트
      • 유효하지 않은 JWT, 만료된 리프레시 토큰 등 케이스별 예외 응답 확인
      • Swagger UI에서 API 확인 가능 (/swagger-ui.html)

      Types of changes

      • Breaking change (기존 MVC 환경 → WebFlux로 완전 전환)
      • New feature (WebClient, JWT 인증 필터, Reactive repository 등)
      • Bug fix (JWT 검증 안되던 문제 해결, Redis repository 사용 오류 해결)

      Checklist

      • My code follows the code style of this project.
      • My change requires a change to the documentation.
      • I have updated the documentation accordingly.
      • I have read the docs/CONTRIBUTING.md document.
      • I have added tests to cover my changes.
      • All new and existing tests passed.

@netlify
Copy link

netlify bot commented Apr 22, 2025

Deploy Preview for jootalkpia canceled.

Name Link
🔨 Latest commit 5938c41
🔍 Latest deploy log https://app.netlify.com/sites/jootalkpia/deploys/6809f34d37c60b0008725bb1

@bo-ram-bo-ram bo-ram-bo-ram changed the base branch from main to dev April 22, 2025 13:56
@bo-ram-bo-ram bo-ram-bo-ram changed the title Be feat/auth webflux 인증서버 webflux로 전환 Apr 22, 2025
@bo-ram-bo-ram bo-ram-bo-ram added ✨ Feature 기능 추가 🎮 BE 백엔드 ♻️ Refactor 코드 리팩토링 and removed ✨ Feature 기능 추가 labels Apr 22, 2025
@bo-ram-bo-ram bo-ram-bo-ram self-assigned this Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🎮 BE 백엔드 ♻️ Refactor 코드 리팩토링

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants