-
Notifications
You must be signed in to change notification settings - Fork 2
[Fix] 관리자페이지(위치정보시스템) 로그인 실패 문제 해결 #247
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,7 +111,7 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse | |
| // 타임리프 페이지 인가 처리 | ||
| String accessToken = resolveToken(request); | ||
| jwtUtils.validateToken(accessToken); // 토큰 검증 | ||
| jwtUtils.isTokenBlacklisted(authHeader); // 🚨 블랙리스트 확인 | ||
| jwtUtils.isTokenBlacklisted(accessToken); // 🚨 블랙리스트 확인 | ||
| } catch (Exception e) { | ||
| Gson gson = new Gson(); | ||
| String json = ""; | ||
|
|
@@ -163,9 +163,11 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse | |
| private String resolveToken(HttpServletRequest request) { | ||
| // 1) Authorization 헤더: Bearer | ||
| String authHeader = request.getHeader(jwtHeader); | ||
| if (authHeader != null && authHeader.startsWith("Bearer ")) { | ||
| checkAuthorizationHeader(authHeader); // header 가 올바른 형식인지 체크 | ||
| return JwtUtils.getTokenFromHeader(authHeader); | ||
| if (authHeader != null) { | ||
| if (authHeader.startsWith("Bearer ")){ | ||
| checkAuthorizationHeader(authHeader); // header 가 올바른 형식인지 체크 | ||
| return JwtUtils.getTokenFromHeader(authHeader); | ||
| } | ||
| } | ||
|
Comment on lines
+166
to
171
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| // 2) 쿠키: ACCESS_TOKEN | ||
| if (request.getCookies() != null) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -258,6 +258,7 @@ public IsAvailable verifyUsernameOverlap(String username) { | |||||||||||
|
|
||||||||||||
| @Override | ||||||||||||
| public void logout(String accessToken) { | ||||||||||||
| String accessTokenWithoutBearer = accessToken.split(" ")[1]; | ||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| // 로그아웃시킬 회원의 refresh token redis에서 삭제 | ||||||||||||
| Long userId = SecurityUtil.getCurrentUserId(); | ||||||||||||
| String key = "users:" + userId.toString(); | ||||||||||||
|
|
@@ -266,7 +267,7 @@ public void logout(String accessToken) { | |||||||||||
| // 로그아웃시킬 회원의 access token redis의 블랙리스트로 저장 | ||||||||||||
| key = "blackList:" + userId.toString(); | ||||||||||||
| long tokenRemainTimeSecond = jwtUtils.tokenRemainTimeSecond(accessToken); | ||||||||||||
| redisTemplate.opsForValue().set(key, accessToken, tokenRemainTimeSecond, TimeUnit.SECONDS); | ||||||||||||
| redisTemplate.opsForValue().set(key, accessTokenWithoutBearer, tokenRemainTimeSecond, TimeUnit.SECONDS); | ||||||||||||
|
|
||||||||||||
| } | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재
isTokenBlacklisted구현은 Redis의KEYS명령을 사용하여 운영 환경에서 심각한 성능 문제를 일으킬 수 있습니다.KEYS는 전체 키를 스캔하므로 사용을 피해야 합니다.블랙리스트 확인을 위해 토큰에서
userId를 추출하고,blackList:{userId}키를 직접 조회하여 토큰을 비교하는 것이 훨씬 효율적입니다.validateToken이 이미 호출되었으므로, 반환된 클레임에서userId를 가져와 사용할 수 있습니다. 이 로직을 수정하여 성능 문제를 해결하는 것을 강력히 권장합니다.