Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mod] NO_CHECK_URLS 추가 #165

Merged
merged 2 commits into from
Mar 5, 2025
Merged

[Mod] NO_CHECK_URLS 추가 #165

merged 2 commits into from
Mar 5, 2025

Conversation

jjjh02
Copy link
Contributor

@jjjh02 jjjh02 commented Mar 5, 2025

추가한 코드

  • NO_CHECK_URLS에 /swagger관련 주소와 /sign-up 추가

해결 과정

문제

swagger와 sign-up 접근이 안됨

원인

.permitAll() 설정은 Security 인증을 허용하지만, JwtAuthenticationFilter는 그대로 실행됨. JwtAuthenticationFilter에서 accessToken == null && refreshToken == null이면 요청이 컨트롤러까지 가지 않고 필터 체인에서 종료됨.
(Security에서 허용하더라도 JwtAuthenticationFilter가 먼저 실행되면 요청이 거부될 수 있음.)

기존 코드에서 됐던 이유

기존 코드에서는 accesstoken, refreshtoken 둘다 없을때 if (refreshToken == null) 를 통과하면서 checkAccessTokenAndAuthentication()가 실행되면서 JWT 없이도 filterChain.doFilter()가 호출되어 요청이 컨트롤러까지 도달했음.

해결 방법

NO_CHECK_URLS에 /swagger관련 주소와 /sign-up 추가하여 JwtAuthenticationFilter를 통과하지 않도록 설정

중요한점

  • .permitAll() 설정은 Security 인증을 허용하지만, JwtAuthenticationFilter는 그대로 실행됨. Security 인증은 컨트롤러에서 적용됨
  • Security의 인증 흐름
    • Http 요청 → JwtAuthenticationFilter가 실행됨.
    • (NO_CHECK_URLS에 포함된 경우, 필터를 건너뛰고 Security까지 요청이 전달됨.)
    • Security에서 .permitAll()이 적용되면 인증 없이 접근 가능.
    • .authenticated()가 적용된 경우, SecurityContextHolder를 확인하여 인증이 필요함.

@JunbeomKoreaUniv
Copy link
Contributor

회원가입은 당연히 토큰이 필요없어서 NO_CHECK_URL에 넣는게 자연스러워서 잘 수정하신 것 같습니다. 스웨거도 개발단계에서만 쓰니까 괜찮을 것 같구요~(운영서버를 배포하게되면 스웨거 URL은 제거하고 배포해야할 듯 합니다) 수고하셨습니다!

@JunbeomKoreaUniv JunbeomKoreaUniv merged commit 6af29ae into main Mar 5, 2025
2 checks passed
@JunbeomKoreaUniv JunbeomKoreaUniv deleted the mod/jwt3 branch March 5, 2025 05:21
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.

2 participants