[๐จย fix] JWT ํํฐ๊ฐ ์ธ์ฆ ์์ธ ๊ฒฝ๋ก๋ฅผ ๊ฑด๋๋ฐ๋๋ก ๊ฐ์ #253
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR updates the JWT filter to skip token validation on configured whitelist endpoints.
- Added
shouldNotFilteroverride inJwtAuthenticationFilterto bypass authentication forAUTH_WHITELISTpaths - Made
AUTH_WHITELISTinSecurityConfigpublic for filter access - Imported and initialized
AntPathMatcherto match request URIs against whitelist
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| JwtAuthenticationFilter.java | Implemented shouldNotFilter using AntPathMatcher and SecurityConfig.AUTH_WHITELIST |
| SecurityConfig.java | Changed AUTH_WHITELIST visibility to public static final |
Comments suppressed due to low confidence (1)
src/main/java/org/terning/terningserver/common/security/jwt/filter/JwtAuthenticationFilter.java:37
- Add unit tests for shouldNotFilter to verify that requests matching AUTH_WHITELIST are correctly skipped and that others are filtered.
@Override
|
|
||
| private final JwtUserIdExtractor jwtUserIdExtractor; | ||
| private final RateLimitingService rateLimitingService; | ||
| private final AntPathMatcher antPathMatcher = new AntPathMatcher(); |
There was a problem hiding this comment.
[nitpick] Consider making the AntPathMatcher instance static final or injecting a shared PathMatcher bean to avoid unnecessary instantiation and improve clarity.
| private final AntPathMatcher antPathMatcher = new AntPathMatcher(); | |
| private static final AntPathMatcher antPathMatcher = new AntPathMatcher(); |
There was a problem hiding this comment.
ํผ๋๋ฐฑ ๊ฐ์ฌํฉ๋๋ค!
AntPathMatcher๋ thread-safeํ๊ณ ์ํ๊ฐ ์์ผ๋ฏ๋ก, ํํฐ ์ธ์คํด์ค๋ง๋ค ์๋ก ์์ฑํ๋ ๊ฒ์ ๋ญ๋น๊ฐ๋ค์!.
์ ์ํด์ฃผ์ ๋๋ก static final๋ก ๋ณ๊ฒฝํ์ฌ ํด๋์ค ๋ ๋ฒจ์ ๋จ์ผ ์ธ์คํด์ค๋ฅผ ์ฌ์ฉํ๋๋ก ์์ ํ๊ฒ ์ต๋!
| @Override | ||
| protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException { | ||
| String requestURI = request.getRequestURI(); | ||
| for (String pattern : SecurityConfig.AUTH_WHITELIST) { |
There was a problem hiding this comment.
[nitpick] Referencing SecurityConfig.AUTH_WHITELIST statically couples the filter to the config class. Inject the whitelist via constructor or @value to improve testability and reduce tight coupling.
There was a problem hiding this comment.
์ด ๋ถ๋ถ์ ํนํ ์ค์ํ ํผ๋๋ฐฑ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค.
ํ์ฌ ํํฐ๊ฐ ์ค์ ํด๋์ค์ ์ง์ ์์กดํ๊ณ ์์ด ํ ์คํธ๊ฐ ์ด๋ ต๊ณ ์ ์ฐ์ฑ์ด ๋จ์ด์ง๋ ๊ตฌ์กฐ๋ค์!
๋ง์ํด์ฃผ์ ๋๋ก SecurityConfig์์ AUTH_WHITELIST๋ฅผ JwtAuthenticationFilter์ ์์ฑ์๋ฅผ ํตํด ์ฃผ์ ํ๋ ๋ฐฉ์์ผ๋ก ๋ฆฌํฉํ ๋งํ์ฌ, ๋ ํด๋์ค ๊ฐ์ ๊ฒฐํฉ๋๋ฅผ ๋ฎ์ถ๊ณ ํ ์คํธ ์ฉ์ด์ฑ์ ๋์ฌ๋ณผ๊ฒ์!
| private final CustomJwtAuthenticationEntryPoint customJwtAuthenticationEntryPoint; | ||
| private static final String[] AUTH_WHITELIST = { | ||
|
|
||
| public static final String[] AUTH_WHITELIST = { |
There was a problem hiding this comment.
Static mutable arrays can be modified at runtime. Consider using an unmodifiable List or an immutable collection to prevent accidental modifications.
| public static final String[] AUTH_WHITELIST = { | |
| public static final List<String> AUTH_WHITELIST = List.of( |
There was a problem hiding this comment.
๋ง์ต๋๋ค!
public static final ๋ฐฐ์ด์ ๋ฐํ์์ ๋ด๋ถ ๊ฐ์ด ๋ณ๊ฒฝ๋ ์ ์์ด ์ ์ฌ์ ์ธ ์ํ์ด ์กด์ฌํ์ฃ !
์ ์ํด์ฃผ์ ๋๋ก List.of()๋ฅผ ์ฌ์ฉํ์ฌ ๋๊ตฌ๋ ์์ ํ ์ ์๋ ๋ถ๋ณ ์ปฌ๋ ์
์ผ๋ก ๋ง๋ค์ด ์ฝ๋์ ์์ ์ฑ์ ๊ฐํํด๋ณด๊ฒ ์ต๋๋ค!
๐ Work Description
๋ฌธ์ ์ํฉ
๊ธฐ์กด
JwtAuthenticationFilter๋SecurityConfig์permitAll์ค์ ๊ณผ ๊ด๊ณ์์ด ๋ชจ๋ ์์ฒญ ํค๋์ ์๋ ํ ํฐ์ ์ ํจ์ฑ์ ๊ฒ์ฌํ์ต๋๋ค. ์ด๋ก ์ธํด ํ ํฐ ์ฌ๋ฐ๊ธ, ์์ ๋ก๊ทธ์ธ ๋ฑ ๋ง๋ฃ๋ ํ ํฐ์ ์ฌ์ฉํ๊ฑฐ๋ ํ ํฐ์ด ์๋ ์ํ๋ก ์ ๊ทผํด์ผ ํ๋ ์ธ์ฆ ๊ด๋ จ API ์์ฒญ์ด ํํฐ ๋จ๊ณ์์ ๋ฏธ๋ฆฌ ์ฐจ๋จ๋๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค.ํด๊ฒฐ ๋ฐฉ์
OncePerRequestFilter๊ฐ ์ ๊ณตํ๋shouldNotFilter๋ฉ์๋๋ฅผ ์ค๋ฒ๋ผ์ด๋ํ์ฌ,SecurityConfig์ ์ ์๋AUTH_WHITELIST๊ฒฝ๋ก์ ๋ํด์๋JwtAuthenticationFilter๊ฐ ๋์ํ์ง ์๋๋ก ์์ ํ์ต๋๋ค.์ด๋ฅผ ํตํด ์ธ์ฆ์ด ํ์ ์๋ ๊ฒฝ๋ก๋ ํ ํฐ ์ ํจ์ฑ ๊ฒ์ฌ๋ฅผ ์์ ํ๊ฒ ํต๊ณผํ์ฌ, ์๋ํ ๋๋ก ์ปจํธ๋กค๋ฌ์์ ์์ฒญ์ ์ฒ๋ฆฌํ ์ ์๋๋ก ๊ฐ์ ํ์ต๋๋ค.
์ฃผ์ ๋ณ๊ฒฝ ์ฌํญ
JwtAuthenticationFilter:
shouldNotFilter๋ฅผ ๊ตฌํํ์ฌ ์ธ์ฆ ์์ธ ๊ฒฝ๋ก์ ๋ํ ํํฐ๋ง ๋ก์ง์ ์ ์ธํ์ต๋๋ค.SecurityConfig:
AUTH_WHITELIST์ ์ ๊ทผ ์ ์ด์๋ฅผpublic์ผ๋ก ๋ณ๊ฒฝํ์ฌJwtAuthenticationFilter์์ ์ฐธ์กฐํ ์ ์๋๋ก ์์ ํ์ต๋๋ค.