Skip to content

Commit

Permalink
fix: 시큐리티 에러 해결
Browse files Browse the repository at this point in the history
시큐리티 단에서 401에러가 뜨지 않고, 422에러가 뜨는 에러 해결했다.
  • Loading branch information
yooooonshine committed Aug 10, 2024
1 parent 4ddbb83 commit 7c2c95c
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,19 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
final String refreshToken = jwtTokenProvider.extractRefreshToken(request).orElse(null);
final String accessToken = jwtTokenProvider.extractAccessToken(request).orElse(null);
final String tokenRoomId = jwtTokenProvider.extractRoomId(accessToken).orElse(null);
final Room room = roomRepository.findByIdentityNumber(tokenRoomId)
.orElseThrow(() -> new CustomException(ROOM_NOT_FOUND));

final String nowRoomId = jwtTokenProvider.extractRoomId(request).orElse(null);
final RoomType nowRoomType = jwtTokenProvider.extractRoomType(request).orElse(null);

//1. access토큰이 존재하며, accessToken이 유효하면 인증
//2. access토큰이 존재하며, accesToken이 유효하지 않으면 에러 리턴
//3. refresh토큰이 존재하며, refreshToken이 유효하면 access 토큰 재발급
//4. refresh토큰이 존재하며, refreshToken이 유효하지 않으면 로그인 유도
//5. 그 외 모든 경우는 에러 리턴
if (accessToken != null && jwtTokenProvider.isTokenValid(accessToken)) {
final String nowRoomId = jwtTokenProvider.extractRoomId(request).orElse(null);
final RoomType nowRoomType = jwtTokenProvider.extractRoomType(request).orElse(null);

final Room room = roomRepository.findByIdentityNumber(tokenRoomId)
.orElseThrow(() -> new CustomException(ROOM_NOT_FOUND));

//토큰이 logout된 토큰인지 검사
if (jwtTokenProvider.isLogout(accessToken)) {
log.info("logout된 accessToken으로 인증 실패");
Expand Down

0 comments on commit 7c2c95c

Please sign in to comment.