Skip to content

[hotfix] #143 매칭 상세조회 시 본인 소유 매칭만 조회 가능하도록 검증 로직 추가#144

Merged
2hyunjinn merged 4 commits intomainfrom
fix/#143
Jun 12, 2025
Merged

[hotfix] #143 매칭 상세조회 시 본인 소유 매칭만 조회 가능하도록 검증 로직 추가#144
2hyunjinn merged 4 commits intomainfrom
fix/#143

Conversation

@2hyunjinn
Copy link
Member

@2hyunjinn 2hyunjinn commented Jun 12, 2025

📌 PR 제목

[hotfix] #143 매칭 상세조회 시 본인 소유 매칭만 조회 가능하도록 검증 로직 추가

📌 PR 내용

  • 매칭 상세조회 API에서 로그인 사용자가 자신의 매칭이 아닌 다른 사람의 매칭을 URL 조작으로 조회할 수 있는 문제를 수정했습니다.
  • 이를 위해 MatchingValidator에 검증 로직을 추가하고, 해당 로직을 서비스 로직에서 호출하도록 리팩토링했습니다.
  • 검증 로직이 잘 동작하는지 확인하는 테스트 코드도 함께 작성했습니다.

🛠 작업 내용

  • 본인 소유의 매칭만 조회할 수 있도록 검증 로직 추가
  • MatchingValidator에 책임 분리 및 리팩토링
  • 검증 실패 시 예외 발생 테스트 코드 작성

🔍 관련 이슈

Closes #143

📸 스크린샷 (Optional)

image

📚 레퍼런스 (Optional)

N/A

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced validation to confirm participant and festival consistency when accessing matching details.
  • Tests
    • Added a test to verify that unauthorized access to matching details is correctly blocked.

@2hyunjinn 2hyunjinn self-assigned this Jun 12, 2025
@2hyunjinn 2hyunjinn added the fix Further information is requested label Jun 12, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jun 12, 2025

"""

Walkthrough

The changes introduce centralized validation methods for participant and festival matching in the MatchingValidator class. The MatchingServiceImpl now uses these methods for access control in the matching detail retrieval, and applies a class-level read-only transaction annotation. A new test verifies forbidden access when the applicant participant does not match.

Changes

File(s) Change Summary
src/main/java/org/festimate/team/domain/matching/service/impl/MatchingServiceImpl.java Refactored to use new validator methods for participant/festival checks; added class-level read-only transaction annotation; removed redundant method-level annotations.
src/main/java/org/festimate/team/domain/matching/validator/MatchingValidator.java Added static methods: isApplicantParticipantValid and isFestivalMatchValid for centralized validation.
src/test/java/org/festimate/team/domain/matching/service/impl/MatchingServiceImplTest.java Added test for forbidden access when applicant participant does not match.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MatchingServiceImpl
    participant MatchingValidator

    User->>MatchingServiceImpl: getMatchingDetail(matchingId, festival, participant)
    MatchingServiceImpl->>MatchingValidator: isFestivalMatchValid(matching, festival)
    MatchingValidator-->>MatchingServiceImpl: (throws if invalid)
    MatchingServiceImpl->>MatchingValidator: isApplicantParticipantValid(matching, participant)
    MatchingValidator-->>MatchingServiceImpl: (throws if invalid)
    MatchingServiceImpl-->>User: matching detail or error
Loading

Assessment against linked issues

Objective Addressed Explanation
Add access control to matching detail retrieval: block access if applicant participant ≠ logged-in user's participant (#143)
Return 403 Forbidden error if access is invalid (#143)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Possibly related PRs

Poem

A rabbit hops through code so neat,
Guarding matchings none can cheat.
If you’re not the rightful friend,
Forbidden errors we shall send!
With validators set in place,
Only true applicants win the race.
🐇✨
"""


📜 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 2b755c8 and 2a315f0.

📒 Files selected for processing (1)
  • src/main/java/org/festimate/team/domain/matching/validator/MatchingValidator.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/org/festimate/team/domain/matching/validator/MatchingValidator.java
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test
  • GitHub Check: Build Test
✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • @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 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@github-actions
Copy link

github-actions bot commented Jun 12, 2025

Test Results

46 tests   46 ✅  1s ⏱️
10 suites   0 💤
10 files     0 ❌

Results for commit 2a315f0.

♻️ This comment has been updated with latest results.

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

🧹 Nitpick comments (4)
src/main/java/org/festimate/team/domain/matching/validator/MatchingValidator.java (1)

34-38: Minor: Null-safety guard

matching.getFestival() or matching.getFestival().getFestivalId() can be null for corrupt data.
Consider short-circuiting to avoid NullPointerException:

if (matching.getFestival() == null
        || !Objects.equals(matching.getFestival().getFestivalId(), festival.getFestivalId())) {
    throw new FestimateException(ResponseError.FORBIDDEN_RESOURCE);
}
src/main/java/org/festimate/team/domain/matching/service/impl/MatchingServiceImpl.java (2)

30-31: Wildcard static import hurts traceability

import static …MatchingValidator.*; obscures the origin of static calls.
Import only the used methods (isMatchingDateValid, isFestivalMatchValid, isApplicantParticipantValid) for readability.


90-96: findBestCandidateByPriority opens a read/write transaction unnecessarily

The method only performs SELECTs; yet the explicit @Transactional here overrides the class-level readOnly=true, creating a read-write transaction.

-    @Transactional
+    @Transactional(readOnly = true)

This avoids superfluous flush checks and improves performance.

src/test/java/org/festimate/team/domain/matching/service/impl/MatchingServiceImplTest.java (1)

276-306: Assertion couples to message string – prefer enum check

hasMessage(ResponseError.FORBIDDEN_RESOURCE.getMessage()) ties the test to text that may change during localisation.
Use the enum itself:

assertThatThrownBy(() -> ...)
        .isInstanceOf(FestimateException.class)
        .extracting("error")          // assuming FestimateException exposes the enum
        .isEqualTo(ResponseError.FORBIDDEN_RESOURCE);

Reduces brittle tests.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cbce273 and 2b755c8.

📒 Files selected for processing (3)
  • src/main/java/org/festimate/team/domain/matching/service/impl/MatchingServiceImpl.java (2 hunks)
  • src/main/java/org/festimate/team/domain/matching/validator/MatchingValidator.java (2 hunks)
  • src/test/java/org/festimate/team/domain/matching/service/impl/MatchingServiceImplTest.java (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build Test
  • GitHub Check: test

Comment on lines 28 to 32
public static void isApplicantParticipantValid(final Matching matching, final Participant participant) {
if (matching.getApplicantParticipant() != participant) {
throw new FestimateException(ResponseError.FORBIDDEN_RESOURCE);
}
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Participant comparison uses reference equality – will fail with detached/rehydrated entities

matching.getApplicantParticipant() != participant compares object references, not logical identity.
In a Hibernate/JPA context the same DB row can be represented by different Java instances (e.g., proxy ≠ DTO), causing a legitimate request to be rejected.

-import org.festimate.team.domain.participant.entity.Participant;
+import org.festimate.team.domain.participant.entity.Participant;
+import java.util.Objects;-        if (matching.getApplicantParticipant() != participant) {
+        if (!Objects.equals(
+                matching.getApplicantParticipant().getParticipantId(),
+                participant.getParticipantId())) {
             throw new FestimateException(ResponseError.FORBIDDEN_RESOURCE);
         }

Compare by participantId (or equals) to avoid false negatives.

📝 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
public static void isApplicantParticipantValid(final Matching matching, final Participant participant) {
if (matching.getApplicantParticipant() != participant) {
throw new FestimateException(ResponseError.FORBIDDEN_RESOURCE);
}
}
import org.festimate.team.domain.participant.entity.Participant;
import java.util.Objects;
public static void isApplicantParticipantValid(final Matching matching, final Participant participant) {
- if (matching.getApplicantParticipant() != participant) {
+ if (!Objects.equals(
+ matching.getApplicantParticipant().getParticipantId(),
+ participant.getParticipantId())) {
throw new FestimateException(ResponseError.FORBIDDEN_RESOURCE);
}
}
🤖 Prompt for AI Agents
In
src/main/java/org/festimate/team/domain/matching/validator/MatchingValidator.java
around lines 28 to 32, the participant comparison uses reference equality which
can fail for detached or rehydrated entities. Replace the reference comparison
with a logical identity check by comparing participant IDs or using the equals
method to ensure correct validation of participant identity.

@2hyunjinn 2hyunjinn merged commit 1022668 into main Jun 12, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[hotfix] 매칭 상세조회 권한 검증 누락 수정

1 participant

Comments