Skip to content

Commit

Permalink
#31 [Update] 토큰이 Null일 때 예외 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
Anna-Jin committed Aug 1, 2022
1 parent a3100a0 commit 3fd6740
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ else if(exception.equals(ErrorCode.WRONG_TYPE_SIGNATURE.getCode())) {
else if(exception.equals(ErrorCode.EXPIRED_ACCESS_TOKEN.getCode())) {
setResponse(response, ErrorCode.EXPIRED_ACCESS_TOKEN);
}
// 토큰이 존재하지 않을 경우
else if (exception.equals(ErrorCode.ACCESS_TOKEN_NOT_EXIST.getCode())) {
setResponse(response, ErrorCode.ACCESS_TOKEN_NOT_EXIST);
}
else {
setResponse(response, ErrorCode.INVALID_ACCESS_TOKEN);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ protected void doFilterInternal(
Authentication authentication = tokenProvider.getAuthentication(token);
// SecurityContextHolder 에 인증 객체를 넣는다.
SecurityContextHolder.getContext().setAuthentication(authentication);
} else {
throw new CustomException(ErrorCode.ACCESS_TOKEN_NOT_EXIST);
}
// 에러가 발생했을 때, request에 attribute를 세팅하고 RestAuthenticationEntryPoint로 request를 넘겨준다.
} catch (SignatureException e) {
Expand All @@ -61,6 +63,9 @@ protected void doFilterInternal(
} catch (IllegalArgumentException e) {
log.info(e.toString().split(":")[1].trim());
request.setAttribute("exception", ErrorCode.INVALID_ACCESS_TOKEN.getCode());
} catch (CustomException e) {
log.info("Access Token이 존재하지 않습니다.");
request.setAttribute("exception", ErrorCode.ACCESS_TOKEN_NOT_EXIST.getCode());
}

filterChain.doFilter(request, response);
Expand Down

0 comments on commit 3fd6740

Please sign in to comment.