Skip to content

Commit

Permalink
Merge pull request #143 from fourix4/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
TaeHoon0 authored Jul 25, 2024
2 parents b44c21b + a4ad2ae commit 4e2d2fa
Showing 1 changed file with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,10 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
SecurityContextHolder.getContext().setAuthentication(authentication); // 검증 후 security context 인증 정보 저장
} catch (ExpiredJwtException e) { // 만료 에러 발생
// refreshToken 존재시
if(jwtUtil.validateRefreshToken(accessToken)) {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");

Response<Void> errorResponse = Response.error("401", ErrorCode.EXPIRED_ACCESS_TOKEN.getMessage());
ObjectMapper objectMapper = new ObjectMapper();
String jsonResponse = objectMapper.writeValueAsString(errorResponse);
response.getWriter().write(jsonResponse);
if (jwtUtil.validateRefreshToken(accessToken)) {
sendErrorResponse(response, "401", ErrorCode.EXPIRED_ACCESS_TOKEN.getMessage());
} else {
sendErrorResponse(response, "403", ErrorCode.EXPIRED_LOGIN_ERROR.getMessage());
}

return;
Expand All @@ -78,4 +73,16 @@ private String resolveToken(HttpServletRequest request) {

return null;
}

private static void sendErrorResponse(HttpServletResponse response, String statusCode, String message) throws IOException {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");

Response<Void> errorResponse = Response.error(statusCode, message);
ObjectMapper objectMapper = new ObjectMapper();
String jsonResponse = objectMapper.writeValueAsString(errorResponse);
response.getWriter().write(jsonResponse);
}

}

0 comments on commit 4e2d2fa

Please sign in to comment.