Skip to content

Conversation

@sunohkim
Copy link
Collaborator

@sunohkim sunohkim commented Feb 27, 2025

[BE] 학생과 교수의 access token이 겹치는 문제 해결

#️⃣ 연관된 이슈

#272

📝 작업 내용

학생과 교수 사용자가 같은 브라우저 내에서 동시 접속 시 403 에러 발생하는 문제 해결

  • 학생의 쿠키 이름을 다르게 지정함으로써, 쿠키 이름 겹침으로 인해 발생한 문제 해결

💬 리뷰 요구사항(선택)

Summary by CodeRabbit

  • New Features

    • Enhanced the authentication system to distinctly handle access for professors and students.
    • Updated course registration to use refined access credentials for improved verification.
  • Refactor

    • Streamlined the token handling process with clear separation for user roles, leading to better clarity in logging and security management.

@sunohkim sunohkim added 🐞 Fix 버그 수정 (기능 오류 및 예외 처리 등) 🌱 BE 백엔드 관련 labels Feb 27, 2025
@sunohkim sunohkim requested a review from uri010 February 27, 2025 07:15
@sunohkim sunohkim self-assigned this Feb 27, 2025
@coderabbitai
Copy link

coderabbitai bot commented Feb 27, 2025

Walkthrough

This pull request refines JWT token handling by separating logic for professors and students. In the JwtAuthenticationFilter class, the token retrieval is split into distinct methods for each user role, and new constants for cookie names are introduced. Additionally, the StudentCourseController now creates a student token cookie with a dedicated name. These updates improve the clarity and specificity of token processing without changing the underlying business logic.

Changes

File(s) Change Summary
.../global/jwt/JwtAuthenticationFilter.java (reacton & reacton-classroom) - Replaced a single token constant with PROFESSOR_COOKIE_NAME and STUDENT_COOKIE_NAME.
- Renamed getJwtFromCookie to getProfessorJwtFromCookie and added getStudentJwtFromCookie.
- Updated filterStudent (no token parameter) and added new filterProfessor method.
- Adjusted debug logs for clarity.
.../domain/course/StudentCourseController.java - Updated the cookie name in the registerCourse method from "access_token" to "student_access_token" while preserving other cookie properties.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant Filter as JwtAuthenticationFilter
    Client->>Filter: HTTP Request
    alt Request from Professor
        Filter->>Filter: getProfessorJwtFromCookie()
        Filter->>Filter: filterProfessor()
        Filter->>Filter: Validate professor token
    else Request from Student
        Filter->>Filter: getStudentJwtFromCookie()
        Filter->>Filter: filterStudent()
        Filter->>Filter: Validate student token
    end
    Filter-->>Client: Forward Request / Return Error
Loading

Suggested reviewers

  • uri010

Poem

In my warren, I tap my feet,
A rabbit's joy in tokens sweet.
Professors, students hop in line,
With filters clear and cookies fine.
Code leaps forth with charm and grace,
Hoppy changes in this coding space!
🐇🌟


📜 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 4dee165 and fbb80e2.

📒 Files selected for processing (3)
  • back-end/reacton-classroom/src/main/java/com/softeer/reacton_classroom/global/jwt/JwtAuthenticationFilter.java (3 hunks)
  • back-end/reacton/src/main/java/com/softeer/reacton/domain/course/StudentCourseController.java (1 hunks)
  • back-end/reacton/src/main/java/com/softeer/reacton/global/jwt/JwtAuthenticationFilter.java (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • back-end/reacton/src/main/java/com/softeer/reacton/domain/course/StudentCourseController.java
🧰 Additional context used
🧠 Learnings (1)
back-end/reacton-classroom/src/main/java/com/softeer/reacton_classroom/global/jwt/JwtAuthenticationFilter.java (2)
Learnt from: uri010
PR: softeer5th/Team3-PowerPenguin#69
File: back-end/reacton/src/main/java/com/softeer/reacton/domain/course/ProfessorCourseController.java:33-33
Timestamp: 2025-02-07T04:19:36.690Z
Learning: In the PowerPenguin project, JwtAuthenticationFilter (extending OncePerRequestFilter) validates JWT tokens and sets oauthId in HttpServletRequest attributes. Only /auth/google/* endpoints are whitelisted. For all other endpoints including /professors/**, requests are guaranteed to have gone through JWT validation, ensuring a non-null oauthId attribute is present when reaching the controllers.
Learnt from: uri010
PR: softeer5th/Team3-PowerPenguin#69
File: back-end/reacton/src/main/java/com/softeer/reacton/domain/course/ProfessorCourseController.java:33-33
Timestamp: 2025-02-07T04:19:36.690Z
Learning: In the PowerPenguin project, JwtAuthenticationFilter validates JWT tokens and sets oauthId in the HttpServletRequest. Requests reaching controllers with @RequestMapping("/professors/**") are guaranteed to have a non-null oauthId attribute, making null checks unnecessary.
🔇 Additional comments (11)
back-end/reacton/src/main/java/com/softeer/reacton/global/jwt/JwtAuthenticationFilter.java (5)

28-29: Well-structured separation of cookie names.

Creating distinct constants for professor and student tokens effectively resolves the token overlap issue mentioned in the PR objective. This change allows both user types to access the application simultaneously without conflicts.


81-82: Good implementation of student token retrieval.

Using the dedicated getStudentJwtFromCookie method provides better clarity and aligns with the new cookie naming approach.


92-93: Proper implementation of professor token retrieval.

Using the dedicated getProfessorJwtFromCookie method keeps the authentication flow consistent with the new cookie name structure.


107-118: Clean implementation of professor token retrieval.

The method correctly handles null cookies and uses appropriate filtering to find the professor's token based on the new cookie name.


120-131: Well-implemented student token retrieval.

The method follows the same pattern as the professor token retrieval, providing consistency in the implementation while using the student-specific cookie name.

back-end/reacton-classroom/src/main/java/com/softeer/reacton_classroom/global/jwt/JwtAuthenticationFilter.java (6)

28-29: Consistent cookie naming across modules.

The cookie name constants match those in the main reacton module, ensuring a consistent approach throughout the application.


57-62: Clear separation of authentication flows.

The conditional logic correctly routes requests to either the student or professor filter method based on the request URI, improving code organization.


70-79: Improved student filtering implementation.

The method now retrieves the token internally using the student-specific method, which is cleaner than passing the token as a parameter.


81-86: Good addition of professor filtering.

The new professor filter method completes the separation of authentication flows and properly validates the professor's token.


92-103: Well-implemented professor token retrieval.

The method correctly follows the same pattern as in the main module, providing consistency across the codebase.


105-116: Consistent student token implementation.

This implementation matches the pattern used throughout the authentication flow and correctly filters for the student-specific cookie name.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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 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
Collaborator

@uri010 uri010 left a comment

Choose a reason for hiding this comment

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

수고하셨습니다

@sunohkim sunohkim merged commit 0a35fef into dev Feb 27, 2025
2 checks passed
@sunohkim sunohkim deleted the fix/be/cookie-name branch February 27, 2025 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🌱 BE 백엔드 관련 🐞 Fix 버그 수정 (기능 오류 및 예외 처리 등)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants