Skip to content

Commit 51e8f5a

Browse files
Merge pull request #46 from SoongSilComputingClub/fix/#45-debugging-token-authentication-issues-when-submitt
[Fix/#45] 지원폼 제출시 토큰 인증문제 디버깅
2 parents e523a69 + 3f51e42 commit 51e8f5a

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

src/main/java/com/example/ssccwebbe/global/security/jwt/filter/JwtFilter.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
import com.example.ssccwebbe.global.security.jwt.util.JwtUtil;
2222
import com.fasterxml.jackson.databind.ObjectMapper;
2323

24+
import lombok.extern.slf4j.Slf4j;
25+
2426
// JWT 검증 필터
27+
@Slf4j
2528
public class JwtFilter extends OncePerRequestFilter {
2629

2730
// Request 헤더에서 accessToken 을 추출하여 인증, 인가를 처리함
@@ -30,13 +33,26 @@ protected void doFilterInternal(
3033
HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
3134
throws ServletException, IOException {
3235

36+
log.info(
37+
"[JwtFilter] Processing request - Method: {}, URI: {}",
38+
request.getMethod(),
39+
request.getRequestURI());
40+
3341
String authorization = request.getHeader("Authorization");
3442
if (authorization == null) {
43+
log.warn(
44+
"[JwtFilter] No Authorization header found for URI: {}",
45+
request.getRequestURI());
3546
filterChain.doFilter(request, response);
3647
return;
3748
}
3849

50+
log.info("[JwtFilter] Authorization header found");
51+
3952
if (!authorization.startsWith("Bearer ")) {
53+
log.error(
54+
"[JwtFilter] Invalid token format - Authorization header does not start with"
55+
+ " 'Bearer '");
4056
// ApiResponse 형식으로 응답 작성
4157
response.setStatus(JwtErrorCode.INVALID_TOKEN_FORMAT.getHttpStatus().value());
4258
response.setContentType("application/json;charset=UTF-8");
@@ -47,25 +63,39 @@ protected void doFilterInternal(
4763
return;
4864
}
4965

66+
log.info("[JwtFilter] Token format valid (starts with 'Bearer ')");
67+
5068
// 토큰 파싱
5169
String accessToken = authorization.split(" ")[1];
70+
String tokenPreview =
71+
accessToken.length() > 20 ? accessToken.substring(0, 20) + "..." : accessToken;
72+
log.info("[JwtFilter] Extracted token: {}", tokenPreview);
5273

5374
// 토큰 검증
75+
log.info("[JwtFilter] Validating token...");
5476
if (JwtUtil.isValid(accessToken, true)) {
5577

5678
String username = JwtUtil.getUsername(accessToken);
5779
String role = JwtUtil.getRole(accessToken);
5880

81+
log.info("[JwtFilter] Token valid - Username: {}, Role: {}", username, role);
82+
5983
List<GrantedAuthority> authorities =
6084
Collections.singletonList(new SimpleGrantedAuthority(role));
6185

6286
Authentication auth =
6387
new UsernamePasswordAuthenticationToken(username, null, authorities);
6488
SecurityContextHolder.getContext().setAuthentication(auth);
6589

90+
log.info(
91+
"[JwtFilter] Authentication successful for user: {} with role: {}",
92+
username,
93+
role);
94+
6695
filterChain.doFilter(request, response);
6796

6897
} else {
98+
log.error("[JwtFilter] Token validation failed - Token is invalid or expired");
6999
// ApiResponse 형식으로 응답 작성
70100
response.setStatus(JwtErrorCode.INVALID_TOKEN.getHttpStatus().value());
71101
response.setContentType("application/json;charset=UTF-8");

src/main/resources/application-local.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ refresh-token:
3939

4040
# Frontend Configuration
4141
frontend:
42-
url: http://localhost:5173
42+
url: http://localhost:3000
4343
cookie:
4444
secure: false
45-
same-site: none
45+
same-site: lax
4646
http-only: true
4747

4848
logging:

0 commit comments

Comments
 (0)