From 83a62afc8da58bd93f0807e03a9dded550b459b3 Mon Sep 17 00:00:00 2001 From: ckx6954 Date: Wed, 22 Jan 2025 18:57:47 +0900 Subject: [PATCH] =?UTF-8?q?handler=20Error=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/security/handler/MemberAuthFailureHandler.java | 3 ++- .../common/security/service/MemberPrincipalDetailService.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/company/localhost/common/security/handler/MemberAuthFailureHandler.java b/src/main/java/io/company/localhost/common/security/handler/MemberAuthFailureHandler.java index 3acbd4d..b978aaa 100644 --- a/src/main/java/io/company/localhost/common/security/handler/MemberAuthFailureHandler.java +++ b/src/main/java/io/company/localhost/common/security/handler/MemberAuthFailureHandler.java @@ -20,6 +20,7 @@ import io.company.localhost.common.exception.code.UserErrorCode; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.springframework.http.MediaType; +import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.authentication.AuthenticationFailureHandler; import org.springframework.stereotype.Component; @@ -39,7 +40,7 @@ public class MemberAuthFailureHandler implements AuthenticationFailureHandler { ApiResponse res = UserErrorCode.BAD_CREDENTIAL.getApiResponse(); String message = exception.getMessage(); - if (message.startsWith("NOT_FOUND")) { + if (exception instanceof BadCredentialsException || message.startsWith("NOT_FOUND")) { res = UserErrorCode.USER_NOT_FOUND.getApiResponse(); } else if (message.startsWith("NOT_AUTHORIZED")) { res = UserErrorCode.NOT_AUTHORIZED.getApiResponse(); diff --git a/src/main/java/io/company/localhost/common/security/service/MemberPrincipalDetailService.java b/src/main/java/io/company/localhost/common/security/service/MemberPrincipalDetailService.java index 3a6b9b4..07e1171 100644 --- a/src/main/java/io/company/localhost/common/security/service/MemberPrincipalDetailService.java +++ b/src/main/java/io/company/localhost/common/security/service/MemberPrincipalDetailService.java @@ -34,7 +34,7 @@ public class MemberPrincipalDetailService implements UserDetailsService { public UserDetails loadUserByUsername(String id) throws UsernameNotFoundException { MemberVo member = memberMapper.findByLoginId(id); - // 없을경우 에러 발생 + //FailHandler 에서 처리 if(member == null) throw new UsernameNotFoundException("NOT_FOUND");