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

[FEAT]스프링시큐리티 에러처리 #39

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
토큰이 오지 않을 경우 감지
토큰이 안 오는 경우도 감지합니다
  • Loading branch information
qlcskcode committed Jan 14, 2025
commit 5fa10a52f1462b8f7465eadbd124f6c484ecc8fa
Original file line number Diff line number Diff line change
@@ -33,9 +33,9 @@ public enum ErrorCode {
/* JWT 관련 에러 */
INVALID_TOKEN(HttpStatus.UNAUTHORIZED, "JWT4001", "유효하지 않은 JWT 토큰입니다."),
INVALID_SIGNATURE(HttpStatus.UNAUTHORIZED, "JWT4002", "JWT 서명이 유효하지 않습니다."),
TOKEN_EXPIRED(HttpStatus.UNAUTHORIZED, "JWT4003", "JWT 토큰이 만료되었습니다.");
// UNSUPPORTED_TOKEN(HttpStatus.UNAUTHORIZED, "JWT4004", "지원하지 않는 JWT 토큰입니다."),
// EMPTY_CLAIMS(HttpStatus.UNAUTHORIZED, "JWT4005", "JWT claims 문자열이 비어 있습니다.");
TOKEN_EXPIRED(HttpStatus.UNAUTHORIZED, "JWT4003", "JWT 토큰이 만료되었습니다."),
MISSING_TOKEN(HttpStatus.UNAUTHORIZED, "JWT4000", "JWT 토큰이 요청에 포함되어 있지 않습니다.");


private final HttpStatus httpStatus;
private final String code;
Original file line number Diff line number Diff line change
@@ -28,9 +28,12 @@ public void commence(HttpServletRequest request, HttpServletResponse response, o
log.info("[CustomAuthenticationEntryPointHandler] :: {}", request.getRequestURL());

ErrorCode errorCode = ErrorCode.INVALID_TOKEN;
String authorizationHeader = request.getHeader("Authorization");
if (authorizationHeader == null || authorizationHeader.trim().isEmpty()) {
errorCode = ErrorCode.MISSING_TOKEN;
}

CustomException customException = new CustomException(errorCode);

ApiResponse<Object> apiResponse = ApiResponse.fail(customException, null);

response.setStatus(errorCode.getHttpStatus().value());