diff --git a/src/main/java/umc/meme/auth/global/auth/AuthService.java b/src/main/java/umc/meme/auth/global/auth/AuthService.java index 5114ad5..a4dfae2 100644 --- a/src/main/java/umc/meme/auth/global/auth/AuthService.java +++ b/src/main/java/umc/meme/auth/global/auth/AuthService.java @@ -56,8 +56,8 @@ public AuthResponse.TokenDto login(AuthRequest.LoginDto loginDto) throws AuthExc throw new LockedException("LOCKED_EXCEPTION", exception); } catch (BadCredentialsException exception) { throw new BadCredentialsException("BAD_CREDENTIALS_EXCEPTION", exception); - } catch (AuthException e) { - throw new AuthException(e.getBaseErrorCode()); + } catch (AuthException exception) { + throw exception; } UserDetails userDetails = principalDetailsService.loadUserByUsername(userName); @@ -68,9 +68,9 @@ public AuthResponse.TokenDto login(AuthRequest.LoginDto loginDto) throws AuthExc private User getUser(AuthRequest.LoginDto loginDto) throws AuthException { OAuthService oAuthService; - if (loginDto.getProvider() == "KAKAO") { + if (loginDto.getProvider().equals("KAKAO")) { oAuthService = new KakaoAuthService(userRepository, redisRepository); - } else if (loginDto.getProvider() == "APPLE") { + } else if (loginDto.getProvider().equals("APPLE")) { oAuthService = new AppleAuthService(userRepository, redisRepository); } else { throw new AuthException(ErrorStatus.PROVIDER_ERROR); diff --git a/src/main/java/umc/meme/auth/global/common/status/ErrorStatus.java b/src/main/java/umc/meme/auth/global/common/status/ErrorStatus.java index c7b9934..540a923 100644 --- a/src/main/java/umc/meme/auth/global/common/status/ErrorStatus.java +++ b/src/main/java/umc/meme/auth/global/common/status/ErrorStatus.java @@ -57,8 +57,6 @@ public enum ErrorStatus implements BaseErrorCode { NOT_FOUND(HttpStatus.NOT_FOUND, 404, "요청한 주소로 응답을 받을 수 없습니다."), PROVIDER_ERROR(HttpStatus.UNAUTHORIZED, 401, "지정한 소셜 로그인 방식을 찾을 수 없습니다."), - - // 소셜 로그인 관련 에러 KEY_NOT_FOUND(HttpStatus.NOT_FOUND, 404, "일치하는 Web Key를 찾을 수 없습니다."); diff --git a/src/main/java/umc/meme/auth/global/exception/ControllerAdvice.java b/src/main/java/umc/meme/auth/global/exception/ControllerAdvice.java index baef92f..7d1ba69 100644 --- a/src/main/java/umc/meme/auth/global/exception/ControllerAdvice.java +++ b/src/main/java/umc/meme/auth/global/exception/ControllerAdvice.java @@ -1,19 +1,16 @@ package umc.meme.auth.global.exception; -import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +import umc.meme.auth.global.common.BaseResponseDto; +import umc.meme.auth.global.common.status.ErrorStatus; import umc.meme.auth.global.exception.handler.AuthException; @RestControllerAdvice public class ControllerAdvice { @ExceptionHandler(value = AuthException.class) - public ResponseEntity invokeError(AuthException e) { - System.out.println("=== AuthException.class ==="); - System.out.println("HTTP_STATUS = " + e.getReason().getHttpStatus()); - System.out.println("CODE = " + e.getReason().getCode()); - System.out.println("REASON = " + e.getReason().getMessage()); - return ResponseEntity.badRequest().build(); + public BaseResponseDto invokeError(AuthException e) { + return BaseResponseDto.ErrorResponse((ErrorStatus) e.getBaseErrorCode()); } } diff --git a/src/main/java/umc/meme/auth/global/oauth/OAuthService.java b/src/main/java/umc/meme/auth/global/oauth/OAuthService.java index 3ef2aeb..e8ad875 100644 --- a/src/main/java/umc/meme/auth/global/oauth/OAuthService.java +++ b/src/main/java/umc/meme/auth/global/oauth/OAuthService.java @@ -50,6 +50,9 @@ public User getUserInfo(String idToken) throws AuthException { selectedKey = jsonWebKey; } + if (selectedKey == null) + throw new AuthException(ErrorStatus.KEY_NOT_FOUND); + // 서명 검증 Claims claims = validateSignature(idToken, getRSAPublicKey(selectedKey)); userEmail = claims.get("email").toString();