Skip to content

Feature/sec#31

Merged
sat7312 merged 14 commits into
devfrom
feature/sec
Apr 20, 2026
Merged

Feature/sec#31
sat7312 merged 14 commits into
devfrom
feature/sec

Conversation

@sat7312
Copy link
Copy Markdown
Collaborator

@sat7312 sat7312 commented Apr 17, 2026

📌 과제 설명

  • Spring Security를 도입하여 JWT 기반 Stateless 인증 구현
  • 로그인 시 발급된 Access Token을 Authorization 헤더에 담아 인증이 필요한 API에 접근
  • refreshToken은 HttpOnly 쿠키로 전달해 XSS 방지

👩‍💻 요구 사항과 구현 내용

  • CustomAuthenticationFilter
    • 요청마다 Authorization: Bearer {token} 헤더를 추출해 JWT 검증 후 SecurityContext에 저장
  • CustomUserDetailsService
    • username으로 DB 조회 후 SecurityUser 반환
  • SecurityUser
    • id, nickname 필드를 추가한 커스텀 UserDetails
  • SecurityConfig
    • CSRF 비활성화, Stateless 세션, URL별 인증 규칙, 401/403 JSON 응답, CORS 통합
  • HttpOnly 쿠키 방식 전환
    • 로그인 시 refreshToken을 Set-Cookie 헤더로 전달, 토큰 재발급/로그아웃 시 @CookieValue로 쿠키에서 읽음
    • TokenReq제거, UsersRes에서 refreshToken 필드 제거
  • AssetController 인증 방식 변경
    • @PathVariable Long userId 제거, @AuthenticationPrincipal SecurityUser로 교체

✅ PR 포인트 & 궁금한 점

  • CustomAuthenticationFilter에서 JWT가 유효하지 않을 때 그냥 통과시키는 방식을 사용했습니다.
  • CorsConfig를 삭제하고 SecurityConfigUrlBasedCorsConfigurationSource로 통합했습니다. Spring Security 필터 체인을 거치기 전에 CORS 처리가 되도록 했습니다.
  • 실습 때와 마찬가지로 리프레시 토큰 쿠키에 Secure=true 설정을 적용했습니다. 따라서 로컬에서 쿠키가 전송되지 않을 수도 있습니다. 배포환경(HTTPS) 기준으로 설정 했습니다.

@sat7312 sat7312 self-assigned this Apr 17, 2026
@sat7312 sat7312 linked an issue Apr 18, 2026 that may be closed by this pull request
@sat7312 sat7312 linked an issue Apr 18, 2026 that may be closed by this pull request
Copy link
Copy Markdown
Collaborator

@zioJioh zioJioh left a comment

Choose a reason for hiding this comment

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

크게 문제 없는 것 같습니다.

Comment thread src/main/java/com/back/together02be/global/springDoc/SpringDoc.java
@sat7312 sat7312 merged commit 0e27ec3 into dev Apr 20, 2026
@sat7312 sat7312 deleted the feature/sec branch April 20, 2026 05:28
gmltmdu pushed a commit that referenced this pull request Apr 20, 2026
* feat: Spring Security JWT 인증 필터 및 Security 설정 추가

* refactor: TradeController userId를 @AuthenticationPrincipal로 교체

* 로그인 입력값 검증 추가

* fix: BaseInitData 초기 데이터 비밀번호 BCrypt 적용 및 유효성 조건

* fix: Users 엔터티 password 컬럼 길이 255로 확장

* feat: Swagger JWT Bearer 인증 스키마 추가

* feat: 회원가입 시 예수금 5천만원 계좌 자동 생성

* refactor: AssetController userId를 @AuthenticationPrincipal로 교체 및 StockController @crossorigin 제거

* refactor: UserRes에서 refreshToken 필드 제거 (HttpOnly 쿠키 방식으로 전환 시작)

* refactor: TokenReq 삭제 (refreshToken을 바디 대신 쿠키로 수신)

* refactor: UsersService logout/reissueToken 파라미터를 String refreshToken으로 변경

* feat: refreshToken을 HttpOnly 쿠키 방식으로 전환

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature/sec-01 feature/sec

2 participants