Skip to content

[FEAT] 마스터 JWT 발급 기능 구현 - #225

Merged
on1yoneprivate merged 6 commits into
developfrom
feat/#221-master-jwt
Aug 12, 2026
Merged

[FEAT] 마스터 JWT 발급 기능 구현#225
on1yoneprivate merged 6 commits into
developfrom
feat/#221-master-jwt

Conversation

@ownue

@ownue ownue commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

📍 개요

마스터 JWT 발급 기능 구현

⛓️‍💥 관련 이슈


🛠️ 작업 내용

  • MASTER_AUTH_ENABLED 기반 기능 활성화
  • MASTER_AUTH_USER_ID로 발급 대상 계정 고정
  • 기존 JwtTokenProvider를 활용한 Access Token 발급
  • 사용자 존재 여부 및 설정값 검증
  • Swagger 문서 및 관련 테스트 추가

🔥 리뷰 요청 사항

리뷰어가 중점적으로 확인해주었으면 하는 내용을 작성해주세요.

  • 운영 환경에서 마스터 인증 기능이 기본 비활성화되는지 확인 필요
  • 설정된 테스트 계정 외 사용자로 토큰을 발급할 수 없는지 확인 필요

✅ 체크리스트

  • 코드 컨벤션을 준수했습니다.
  • 불필요한 코드 및 import를 제거했습니다.
  • 예외 처리를 적용했습니다.
  • 테스트를 완료했습니다.
  • 관련 Issue를 연결했습니다.

📎 참고 사항

  • 활성화 시 MASTER_AUTH_ENABLED=true, MASTER_AUTH_USER_ID=27 설정이 필요

Summary by CodeRabbit

  • 새 기능

    • 설정으로 활성화할 수 있는 마스터 인증 기능을 추가했습니다.
    • 지정된 사용자에 대한 JWT Access Token 발급 API를 제공합니다.
    • 응답에 사용자 ID, Access Token, 토큰 만료 시간을 포함합니다.
    • 등록되지 않은 사용자의 요청은 오류로 처리합니다.
  • 테스트

    • 기능 활성화 조건, 토큰 발급, 사용자 검증 및 오류 처리를 검증하는 테스트를 추가했습니다.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@ownue, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 26 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 970d187c-5482-487c-bb62-33dc5e20757e

📥 Commits

Reviewing files that changed from the base of the PR and between b31a2d6 and 9b739c2.

📒 Files selected for processing (3)
  • src/main/java/com/mr/domain/auth/service/MasterAuthService.java
  • src/test/java/com/mr/domain/auth/controller/MasterAuthSecurityDisabledIntegrationTest.java
  • src/test/java/com/mr/domain/auth/controller/MasterAuthSecurityEnabledIntegrationTest.java
📝 Walkthrough

Walkthrough

마스터 인증 기능을 조건부로 추가했습니다. 활성화되면 POST /api/auth/master-token 요청을 허용하고, 설정된 사용자 ID의 존재를 확인한 뒤 기존 JWT 체계로 Access Token을 반환합니다. 비활성화와 설정 오류도 테스트합니다.

Changes

마스터 인증

Layer / File(s) Summary
토큰 발급 계약과 서비스
src/main/java/com/mr/domain/auth/dto/res/MasterAuthResponse.java, src/main/java/com/mr/domain/auth/service/MasterAuthService.java, src/test/java/com/mr/domain/auth/service/MasterAuthServiceTest.java
MasterAuthResponse가 사용자 ID, Access Token, 만료 시간을 정의합니다. MasterAuthService는 사용자 존재를 확인하고 JWT를 생성합니다. 미존재 사용자는 USER_NOT_FOUND 예외를 반환합니다.
조건부 엔드포인트와 보안 연결
src/main/java/com/mr/domain/auth/config/MasterAuthSecurityConfig.java, src/main/java/com/mr/domain/auth/controller/MasterAuthController.java, src/test/java/com/mr/domain/auth/controller/*
master-auth.enabled=true일 때 전용 SecurityFilterChain과 컨트롤러를 등록합니다. POST /api/auth/master-token 요청을 허용하고 설정된 양수 사용자 ID로 토큰을 발급합니다. 활성화 조건과 설정 오류를 검증합니다.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • Musereview/BE#2: 보안, API 응답, 전역 예외 처리 기반을 제공합니다.
  • Musereview/BE#41: JWT 인증과 Spring Security 설정을 다룹니다.
  • Musereview/BE#61: JwtTokenProvider의 Access Token 생성 기능을 제공합니다.

Poem

설정이 켜지면 토큰이 깨어나고
사용자 확인 뒤 JWT가 날아간다.
보안 필터는 길을 열고
서비스는 만료 시간을 새긴다.
마스터 키, 테스트의 작은 등불 ✨

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant MasterAuthSecurityConfig
  participant MasterAuthController
  participant MasterAuthService
  participant UserRepository
  participant JwtTokenProvider
  Client->>MasterAuthSecurityConfig: POST /api/auth/master-token
  MasterAuthSecurityConfig->>MasterAuthController: 요청 허용
  MasterAuthController->>MasterAuthService: issueAccessToken(userId)
  MasterAuthService->>UserRepository: 사용자 존재 확인
  MasterAuthService->>JwtTokenProvider: Access Token 생성 및 만료 시간 조회
  MasterAuthService-->>MasterAuthController: MasterAuthResponse
  MasterAuthController-->>Client: ApiResponse<MasterAuthResponse>
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 제목은 마스터 JWT 발급 기능이라는 PR의 핵심 변경을 정확하고 간결하게 설명합니다.
Linked Issues check ✅ Passed [#221] 활성화 제어, 사용자 검증, 기존 JwtTokenProvider 기반 토큰 발급, 비활성화 동작과 테스트를 구현했습니다.
Out of Scope Changes check ✅ Passed 설정, 컨트롤러, 서비스, 응답 DTO와 관련 테스트만 변경되어 연결 이슈의 범위를 벗어난 변경이 없습니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/#221-master-jwt

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/test/java/com/mr/domain/auth/controller/MasterAuthActivationTest.java (1)

13-15: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

실제 SecurityFilterChain을 사용하는 통합 테스트를 추가하세요.

MasterAuthActivationTestMasterAuthController만 등록하고, MasterAuthControllerTeststandaloneSetup을 사용합니다. 두 테스트 모두 MasterAuthSecurityConfigSecurityConfig의 필터 체인을 실행하지 않습니다. master-auth.enabled=true일 때 인증 없이 토큰을 반환하고, 비활성 또는 미설정 상태일 때 요청이 401 또는 403으로 차단되는지 @SpringBootTest@AutoConfigureMockMvc로 확인하세요. Spring Security MockMvc 통합 테스트 문서를 참고하세요.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/test/java/com/mr/domain/auth/controller/MasterAuthActivationTest.java`
around lines 13 - 15, The tests currently bypass the real Spring Security filter
chain. In
src/test/java/com/mr/domain/auth/controller/MasterAuthActivationTest.java:13-15,
replace the limited ApplicationContextRunner setup with a `@SpringBootTest` and
`@AutoConfigureMockMvc` integration setup that includes MasterAuthSecurityConfig
and SecurityConfig, then verify enabled master auth returns a token without
authentication while disabled or unset configuration returns 401 or 403. In
src/test/java/com/mr/domain/auth/controller/MasterAuthControllerTest.java:29-31,
replace standaloneSetup with MockMvc backed by the Spring application context
and exercise the same real-filter-chain behavior; no direct change is needed
beyond removing the standalone controller setup.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/test/java/com/mr/domain/auth/controller/MasterAuthActivationTest.java`:
- Around line 13-15: The tests currently bypass the real Spring Security filter
chain. In
src/test/java/com/mr/domain/auth/controller/MasterAuthActivationTest.java:13-15,
replace the limited ApplicationContextRunner setup with a `@SpringBootTest` and
`@AutoConfigureMockMvc` integration setup that includes MasterAuthSecurityConfig
and SecurityConfig, then verify enabled master auth returns a token without
authentication while disabled or unset configuration returns 401 or 403. In
src/test/java/com/mr/domain/auth/controller/MasterAuthControllerTest.java:29-31,
replace standaloneSetup with MockMvc backed by the Spring application context
and exercise the same real-filter-chain behavior; no direct change is needed
beyond removing the standalone controller setup.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3d10deb8-9d82-4ada-acd0-5d513d46eb85

📥 Commits

Reviewing files that changed from the base of the PR and between a6f84c4 and b31a2d6.

📒 Files selected for processing (7)
  • src/main/java/com/mr/domain/auth/config/MasterAuthSecurityConfig.java
  • src/main/java/com/mr/domain/auth/controller/MasterAuthController.java
  • src/main/java/com/mr/domain/auth/dto/res/MasterAuthResponse.java
  • src/main/java/com/mr/domain/auth/service/MasterAuthService.java
  • src/test/java/com/mr/domain/auth/controller/MasterAuthActivationTest.java
  • src/test/java/com/mr/domain/auth/controller/MasterAuthControllerTest.java
  • src/test/java/com/mr/domain/auth/service/MasterAuthServiceTest.java

@p1001q p1001q left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1은 없습니다~ 설계 자체는 이중 안전장치가 잘 갖춰져 있어서 P2(로깅) 하나만 보완하면 머지하셔도 될 거 같습니다! 승인 남겨드립니다~

Comment thread src/main/java/com/mr/domain/auth/service/MasterAuthService.java

@on1yoneprivate on1yoneprivate left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

수고하셨습니다~!!

@on1yoneprivate
on1yoneprivate merged commit b4b9d88 into develop Aug 12, 2026
2 checks passed
@on1yoneprivate
on1yoneprivate deleted the feat/#221-master-jwt branch August 12, 2026 12:12

public MasterAuthController(
MasterAuthService masterAuthService,
@Value("${master-auth.user-id}") Long masterAuthUserId

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P5] :#{null}을 덧붙여주시면, application.yml에 해당 설정값이 아예 적혀있지 않더라도 스프링이 에러를 뱉으며 뻗어버리는 대신 null을 안전하게 넣어준다고 하니, 고려해보는 것도 좋을 것 같습니다!

@rkdehdrbs7885-oss rkdehdrbs7885-oss left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

수고하셨습니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

✨ Feature - 마스터 JWT 발급 기능 구현

4 participants