Skip to content

MOSU-204 feat: 메서드에 따른 토큰 검증 절차 변경#206

Merged
wlgns12370 merged 4 commits intodevelopfrom
feature/mosu-204
Aug 5, 2025
Merged

MOSU-204 feat: 메서드에 따른 토큰 검증 절차 변경#206
wlgns12370 merged 4 commits intodevelopfrom
feature/mosu-204

Conversation

@wlgns12370
Copy link
Contributor

@wlgns12370 wlgns12370 commented Aug 5, 2025

✨ 구현한 기능

  • 메서드에 따른 토큰 검증 절차 변경
  • Whitelist 구현

📢 논의하고 싶은 내용

  • x

🎸 기타

  • x

Summary by CodeRabbit

  • New Features

    • Introduced a centralized whitelist system for API endpoints, allowing specific paths and HTTP methods to bypass token authentication.
  • Refactor

    • Renamed authentication filter classes and fields for improved clarity.
    • Updated authentication logic to utilize the new whitelist system for exemption checks.

@coderabbitai
Copy link

coderabbitai bot commented Aug 5, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Caution

Review failed

The pull request is closed.

Walkthrough

The changes introduce a new whitelist mechanism for API endpoint filtering by adding Whitelist and WhitelistMethod enums. The AccessTokenFilter is renamed to TokenFilter, and its logic is refactored to use the new whitelist for determining which requests bypass token validation. The security configuration is updated to reflect these renamings and new logic.

Changes

Cohort / File(s) Change Summary
Security Configuration Refactor
src/main/java/life/mosu/mosuserver/global/config/SecurityConfig.java
Renamed field from accessTokenFilter to tokenFilter; updated filter references and import statements to match new naming and logic.
Token Filter Logic Update
src/main/java/life/mosu/mosuserver/global/filter/TokenFilter.java
Renamed class from AccessTokenFilter to TokenFilter; removed hardcoded skip list; now uses Whitelist.isWhitelisted(request) for filtering decisions; removed obsolete method and adjusted logging.
Whitelist Mechanism Addition
src/main/java/life/mosu/mosuserver/global/filter/Whitelist.java, src/main/java/life/mosu/mosuserver/global/filter/WhitelistMethod.java
Added new enums: Whitelist (defines whitelisted paths/methods and matching logic) and WhitelistMethod (HTTP methods and ALL).

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant SecurityConfig
    participant TokenFilter
    participant Whitelist

    Client->>SecurityConfig: Sends HTTP request
    SecurityConfig->>TokenFilter: Passes request through filter
    TokenFilter->>Whitelist: Calls isWhitelisted(request)
    Whitelist-->>TokenFilter: Returns true/false
    alt Request is whitelisted
        TokenFilter-->>SecurityConfig: Skips token validation
    else Request is not whitelisted
        TokenFilter->>TokenFilter: Performs token validation
    end
    SecurityConfig-->>Client: Returns response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

Poem

In the warren of code, a new path appears,
Whitelists and methods, the logic now clears.
Tokens are filtered with purpose and care,
Old names are retired, new enums declare.
With hops and with skips, requests now align—
A rabbit’s delight in security’s design!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 444c446 and a6d4237.

📒 Files selected for processing (1)
  • src/main/java/life/mosu/mosuserver/global/filter/Whitelist.java (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/mosu-204

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @wlgns12370, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the token verification process within the application's security configuration. It introduces a dedicated Whitelist mechanism to explicitly define which API endpoints and HTTP methods can bypass token authentication, thereby improving the clarity, maintainability, and flexibility of the security filter chain.

Highlights

  • Refactored Token Filter: The AccessTokenFilter has been renamed to TokenFilter and its internal logic for skipping URLs has been removed and externalized. This change streamlines the filter's primary responsibility to token processing, delegating URL whitelisting to a dedicated component.
  • Introduced Whitelist Mechanism: A new Whitelist enum has been implemented to centralize and manage API endpoints and HTTP methods that are exempt from token validation. This provides a clear and configurable way to define paths that do not require authentication.
  • Method-Specific Token Validation: The new Whitelist allows for more granular control over token requirements by enabling whitelisting based on both the URI path and the HTTP method. This means certain paths might be accessible without a token only for specific HTTP verbs (e.g., GET requests).
  • Security Configuration Update: The SecurityConfig class has been updated to integrate the new TokenFilter and leverage the Whitelist for determining which requests bypass token authentication, ensuring the security chain correctly applies the new rules.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the token validation logic by introducing a Whitelist enum to manage authentication-exempt endpoints, which improves maintainability. The AccessTokenFilter is also renamed to TokenFilter to better reflect its broader responsibilities. The review focuses on improving performance, maintainability, and error handling.

String requestUri = request.getRequestURI();
String requestMethod = request.getMethod();

return Arrays.stream(values())

Choose a reason for hiding this comment

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

medium

The values() method on an enum creates a new array each time it's called. Since this check is in a filter that runs for every request, this can create unnecessary object allocations and affect performance. Caching the result of values() in a static final field can optimize this.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5135a87 and 444c446.

⛔ Files ignored due to path filters (1)
  • .DS_Store is excluded by !**/.DS_Store
📒 Files selected for processing (4)
  • src/main/java/life/mosu/mosuserver/global/config/SecurityConfig.java (3 hunks)
  • src/main/java/life/mosu/mosuserver/global/filter/TokenFilter.java (3 hunks)
  • src/main/java/life/mosu/mosuserver/global/filter/Whitelist.java (1 hunks)
  • src/main/java/life/mosu/mosuserver/global/filter/WhitelistMethod.java (1 hunks)
🔇 Additional comments (10)
src/main/java/life/mosu/mosuserver/global/filter/WhitelistMethod.java (1)

3-13: LGTM! Clean enum implementation.

The enum properly defines all standard HTTP methods plus the useful ALL constant for flexible whitelist configuration. The implementation follows Java conventions and serves its purpose effectively.

src/main/java/life/mosu/mosuserver/global/config/SecurityConfig.java (3)

7-14: LGTM! Import organization improved.

The import statements are better organized and the TokenFilter import correctly reflects the class rename from AccessTokenFilter.


68-68: LGTM! Field rename maintains consistency.

The field rename from accessTokenFilter to tokenFilter properly aligns with the class rename and maintains naming consistency.


146-147: LGTM! Filter chain properly updated.

The filter chain configuration correctly uses the renamed tokenFilter field and maintains the proper filter ordering.

src/main/java/life/mosu/mosuserver/global/filter/TokenFilter.java (4)

28-28: LGTM! Class rename reflects broader functionality.

The rename from AccessTokenFilter to TokenFilter better represents the filter's expanded role in handling multiple token types (access, signup, password tokens).


45-49: LGTM! Excellent whitelist integration.

The replacement of hardcoded URL skip logic with Whitelist.isWhitelisted(request) is a significant architectural improvement that:

  • Centralizes whitelist management
  • Makes the code more maintainable
  • Provides method-based filtering capabilities

The enhanced logging that includes both URI and HTTP method improves debugging visibility.


51-51: LGTM! Code optimization and formatting improvement.

Moving the requestUri extraction outside the conditional blocks eliminates duplication and improves code efficiency.


53-103: LGTM! Core token validation logic properly preserved.

The essential token validation logic for different token types (reissue, signup, password, access tokens) remains unchanged, ensuring backward compatibility while benefiting from the new whitelist functionality.

src/main/java/life/mosu/mosuserver/global/filter/Whitelist.java (2)

10-13: LGTM! Well-structured enum with appropriate annotations.

The Lombok annotations are correctly used - @RequiredArgsConstructor works well for enum constructors, and @Getter provides clean access to the fields.


46-59: LGTM! Efficient whitelist matching implementation.

The implementation correctly handles:

  • Prefix-based path matching using startsWith()
  • Method-specific and wildcard (ALL) matching
  • Clean use of streams and Optional

The logic flow from isWhitelisted() to findMatch() is clear and efficient.

Comment on lines 16 to 41
KMC("/api/v1/kmc", WhitelistMethod.ALL),
API_DOCS("/api/v1/api-docs", WhitelistMethod.ALL),
ACTUATOR("/api/v1/actuator", WhitelistMethod.ALL),
LOGIN("/api/v1/auth/login", WhitelistMethod.ALL),
SWAGGER("/api/v1/swagger", WhitelistMethod.ALL),
SWAGGER_UI("/api/v1/swagger-ui", WhitelistMethod.ALL),
VIRTUAL_ACCOUNT("/api/v1/virtual-account", WhitelistMethod.ALL),
ADMISSION_TICKET("/api/v1/admission-ticket", WhitelistMethod.ALL),

// 정적 리소스
CSS("/api/v1/css", WhitelistMethod.ALL),
JS("/api/v1/js", WhitelistMethod.ALL),
FONTS("/api/v1/fonts", WhitelistMethod.ALL),
IMAGES("/api/v1/images", WhitelistMethod.ALL),

// OAuth 관련
OAUTH2("/api/v1/oauth2", WhitelistMethod.ALL),
OAUTH("/api/v1/oauth", WhitelistMethod.ALL),

// 삭제 예정
MASTER("/api/v1/master", WhitelistMethod.ALL),

// 조회만 가능한 PATH
EVENT("/api/v1/event", WhitelistMethod.GET),
FAQ("/api/v1/faq", WhitelistMethod.GET),
NOTICE("/api/v1/notice", WhitelistMethod.GET);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Review whitelist entries for security considerations.

The whitelist structure is well-organized, but consider these security aspects:

  1. Line 18: ACTUATOR with ALL methods could expose sensitive endpoints. Consider restricting to GET only or implementing additional security.

  2. Lines 26-29: Static resources (CSS, JS, FONTS, IMAGES) typically only need GET method access, not ALL methods.

  3. Line 36: MASTER endpoint is marked for deletion but still active with ALL methods - ensure this is removed when appropriate.

The GET-only restrictions for EVENT, FAQ, and NOTICE endpoints are appropriate for read-only resources.

Consider this diff for static resources:

-    CSS("/api/v1/css", WhitelistMethod.ALL),
-    JS("/api/v1/js", WhitelistMethod.ALL),
-    FONTS("/api/v1/fonts", WhitelistMethod.ALL),
-    IMAGES("/api/v1/images", WhitelistMethod.ALL),
+    CSS("/api/v1/css", WhitelistMethod.GET),
+    JS("/api/v1/js", WhitelistMethod.GET),
+    FONTS("/api/v1/fonts", WhitelistMethod.GET),
+    IMAGES("/api/v1/images", WhitelistMethod.GET),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
KMC("/api/v1/kmc", WhitelistMethod.ALL),
API_DOCS("/api/v1/api-docs", WhitelistMethod.ALL),
ACTUATOR("/api/v1/actuator", WhitelistMethod.ALL),
LOGIN("/api/v1/auth/login", WhitelistMethod.ALL),
SWAGGER("/api/v1/swagger", WhitelistMethod.ALL),
SWAGGER_UI("/api/v1/swagger-ui", WhitelistMethod.ALL),
VIRTUAL_ACCOUNT("/api/v1/virtual-account", WhitelistMethod.ALL),
ADMISSION_TICKET("/api/v1/admission-ticket", WhitelistMethod.ALL),
// 정적 리소스
CSS("/api/v1/css", WhitelistMethod.ALL),
JS("/api/v1/js", WhitelistMethod.ALL),
FONTS("/api/v1/fonts", WhitelistMethod.ALL),
IMAGES("/api/v1/images", WhitelistMethod.ALL),
// OAuth 관련
OAUTH2("/api/v1/oauth2", WhitelistMethod.ALL),
OAUTH("/api/v1/oauth", WhitelistMethod.ALL),
// 삭제 예정
MASTER("/api/v1/master", WhitelistMethod.ALL),
// 조회만 가능한 PATH
EVENT("/api/v1/event", WhitelistMethod.GET),
FAQ("/api/v1/faq", WhitelistMethod.GET),
NOTICE("/api/v1/notice", WhitelistMethod.GET);
KMC("/api/v1/kmc", WhitelistMethod.ALL),
API_DOCS("/api/v1/api-docs", WhitelistMethod.ALL),
ACTUATOR("/api/v1/actuator", WhitelistMethod.ALL),
LOGIN("/api/v1/auth/login", WhitelistMethod.ALL),
SWAGGER("/api/v1/swagger", WhitelistMethod.ALL),
SWAGGER_UI("/api/v1/swagger-ui", WhitelistMethod.ALL),
VIRTUAL_ACCOUNT("/api/v1/virtual-account", WhitelistMethod.ALL),
ADMISSION_TICKET("/api/v1/admission-ticket", WhitelistMethod.ALL),
// 정적 리소스
- CSS("/api/v1/css", WhitelistMethod.ALL),
- JS("/api/v1/js", WhitelistMethod.ALL),
- FONTS("/api/v1/fonts", WhitelistMethod.ALL),
- IMAGES("/api/v1/images", WhitelistMethod.ALL),
+ CSS("/api/v1/css", WhitelistMethod.GET),
+ JS("/api/v1/js", WhitelistMethod.GET),
+ FONTS("/api/v1/fonts", WhitelistMethod.GET),
+ IMAGES("/api/v1/images", WhitelistMethod.GET),
// OAuth 관련
OAUTH2("/api/v1/oauth2", WhitelistMethod.ALL),
OAUTH("/api/v1/oauth", WhitelistMethod.ALL),
// 삭제 예정
MASTER("/api/v1/master", WhitelistMethod.ALL),
// 조회만 가능한 PATH
EVENT("/api/v1/event", WhitelistMethod.GET),
FAQ("/api/v1/faq", WhitelistMethod.GET),
NOTICE("/api/v1/notice", WhitelistMethod.GET);
🤖 Prompt for AI Agents
In src/main/java/life/mosu/mosuserver/global/filter/Whitelist.java between lines
16 and 41, update the whitelist entries for better security by changing the
ACTUATOR endpoint's allowed methods from ALL to GET only to prevent exposure of
sensitive operations, restrict the static resource endpoints CSS, JS, FONTS, and
IMAGES to GET methods instead of ALL, and ensure the MASTER endpoint marked for
deletion is removed entirely when no longer needed to avoid unintended access.

@wlgns12370 wlgns12370 merged commit d6cfa25 into develop Aug 5, 2025
2 of 3 checks passed
@wlgns12370 wlgns12370 deleted the feature/mosu-204 branch August 5, 2025 17:37
@mosu-dev mosu-dev deleted a comment from gemini-code-assist bot Aug 6, 2025
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.

1 participant