Skip to content

Commit

Permalink
fix: 에러 처리 순서 변경
Browse files Browse the repository at this point in the history
방id검사보다 방type 검사를 먼저 하도록 변경하였다.
  • Loading branch information
yooooonshine committed Aug 10, 2024
1 parent 2e20c95 commit 5d66388
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,27 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
//5. 그 외 모든 경우는 에러 리턴
if (accessToken != null && jwtTokenProvider.isTokenValid(accessToken)) {


//토큰이 logout된 토큰인지 검사
if (jwtTokenProvider.isLogout(accessToken)) {
log.info("logout된 accessToken으로 인증 실패");
throw new CustomException(INVALID_ACCESS_TOKEN);
}

//토큰이 다른 room의 토큰인지 검사
final String nowRoomId = jwtTokenProvider.extractRoomId(request).orElse(null);
if (!Objects.equals(nowRoomId, tokenRoomId)) {
log.info("다른 방의 accessToken으로 인증 실패");
throw new CustomException(UNAUTHORIZED);
}

//토큰의 있는 방의 Type과 헤더와 RoomType이 같은지 검사
//토큰의 있는 방의 Type과 헤더와 RoomType이 같은지 검사(room검사보다 먼저 되어야 함)
final RoomType nowRoomType = jwtTokenProvider.extractRoomType(request).orElse(null);
final Room room = roomRepository.findByIdentityNumber(tokenRoomId)
.orElseThrow(() -> new CustomException(ROOM_NOT_FOUND));
if (nowRoomType != room.getRoomType()) {
throw new CustomException(ROOM_TYPE_UNPROCESSABLE);
}

//토큰이 다른 room의 토큰인지 검사
final String nowRoomId = jwtTokenProvider.extractRoomId(request).orElse(null);
if (!Objects.equals(nowRoomId, tokenRoomId)) {
log.info("다른 방의 accessToken으로 인증 실패");
throw new CustomException(UNAUTHORIZED);
}

log.info("access토큰 인증 성공");
Authentication authentication = jwtTokenProvider.getAuthentication(accessToken);
saveAuthentication(authentication);
Expand Down

0 comments on commit 5d66388

Please sign in to comment.