Skip to content

Fix(security): permitAll 경로에서도 토큰이 있으면 인증 세팅되도록 수정#266

Merged
gisu1102 merged 3 commits intomainfrom
develop
Oct 7, 2025
Merged

Fix(security): permitAll 경로에서도 토큰이 있으면 인증 세팅되도록 수정#266
gisu1102 merged 3 commits intomainfrom
develop

Conversation

@gisu1102
Copy link
Contributor

@gisu1102 gisu1102 commented Oct 7, 2025

#️⃣ 연관된 이슈

#263
#264

📝 작업 내용

Fix(security): permitAll 경로에서도 토큰이 있으면 인증 세팅되도록 수정

Summary by CodeRabbit

  • 신규 기능

    • 비로그인 사용자도 게시글 조회 시 조회수가 증가하도록 동작 개선.
  • 버그 수정

    • 공개(permit-all) 경로에서 토큰이 없을 때 인증 오류로 차단되지 않도록 처리.
    • 토큰 공백/빈 값에 대한 방어 로직 추가로 인증 흐름 안정화.
    • API 문서 경로의 토큰 처리 일관성 개선.
  • 리팩터링

    • 인증 필터의 제어 흐름을 단순화하여 가독성과 유지보수성 향상.
    • 조회수 엔터티의 과도한 유효성 검사 제거로 저장 실패 가능성 완화.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 7, 2025

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

JWT 필터에서 permit-all 경로 처리와 토큰 선택 로직을 재구성하고, 토큰 존재 검사 방식을 StringUtils 기반으로 변경했습니다. JwtService는 빈 액세스 토큰 반환 가드를 추가했습니다. HitsEntity의 @notblank 제약을 제거했습니다. PostInteractionService는 로그아웃 사용자(null userId)도 조회수 증가 대상이 되도록 분기 조건을 수정했습니다.

Changes

Cohort / File(s) Summary
JWT/Auth 필터 및 서비스
src/main/java/inu/codin/codin/common/security/filter/JwtAuthenticationFilter.java, src/main/java/inu/codin/codin/common/security/service/JwtService.java
필터: permit-all 여부 플래그 도입, Swagger 경로는 refresh 토큰, 기타는 access 토큰 사용, StringUtils.hasText로 토큰 존재 검사, 토큰 없으면 보안 컨텍스트 초기화 후 permit-all은 체인 계속. 서비스: getAccessToken에서 공백/빈 토큰이면 null 반환 가드 추가.
게시글 조회수 도메인
src/main/java/inu/codin/codin/domain/post/domain/hits/entity/HitsEntity.java, src/main/java/inu/codin/codin/domain/post/service/PostInteractionService.java
엔티티: _id, userId, postId@notblank 제거. 서비스: increaseHits에서 userId가 null이거나 validateHits가 false일 때 addHits 호출로 분기 확장(로그아웃 사용자 조회수 증가 허용).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Client
  participant F as JwtAuthenticationFilter
  participant S as JwtService
  participant SC as SecurityContext
  participant D as Downstream FilterChain

  rect rgba(220,235,245,0.4)
  Note over F: 요청 처리 시작
  C->>F: HTTP Request
  F->>F: isPermitAll = 매칭 검사
  alt Swagger 경로
    F->>S: getRefreshToken(req)
    S-->>F: refreshToken or null
  else 기타 경로
    F->>S: getAccessToken(req)
    S-->>F: accessToken or null
  end
  F->>F: StringUtils.hasText(token)?
  alt 토큰 없음
    F->>SC: clearContext()
    alt permit-all
      F->>D: doFilter(request, response)
      D-->>F: return
      F-->>C: Response (인증 미적용)
    else 비 permit-all
      F-->>C: Response (인증 실패 흐름 지속)
    end
  else 토큰 있음
    F->>SC: 인증 설정/검증 흐름 계속
    F->>D: doFilter(request, response)
    D-->>F: return
    F-->>C: Response
  end
  end
Loading
sequenceDiagram
  autonumber
  participant S as PostInteractionService
  participant V as validateHits()
  participant R as addHits()
  Note over S: increaseHits(userId, postId)
  alt userId == null
    S->>R: addHits(postId)
    R-->>S: done
  else 사용자 로그인
    S->>V: validateHits(userId, postId)
    V-->>S: true/false
    alt 이전 조회 없음(false)
      S->>R: addHits(postId)
      R-->>S: done
    else 이미 조회(true)
      Note over S: 증가 없음
    end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

귀 쫑긋, 코드 들판에 바람 솔솔 분다
permit-all 길은 살짝 비켜 주고, 토큰은 꼭 확인한다
빈 주머니 토큰은 집에 돌려보내고
발자국(null) 남긴 손님도 조회수 콩콩 추가!
오늘도 깡총, 스웨거 길 따라 리뷰 완료 🥕🐇

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch develop

📜 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 b7ca3bd and a17eb6a.

📒 Files selected for processing (4)
  • src/main/java/inu/codin/codin/common/security/filter/JwtAuthenticationFilter.java (3 hunks)
  • src/main/java/inu/codin/codin/common/security/service/JwtService.java (2 hunks)
  • src/main/java/inu/codin/codin/domain/post/domain/hits/entity/HitsEntity.java (1 hunks)
  • src/main/java/inu/codin/codin/domain/post/service/PostInteractionService.java (1 hunks)

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 and usage tips.

@gisu1102 gisu1102 merged commit 72a37a0 into main Oct 7, 2025
1 check was pending
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