Skip to content

Commit 478a2db

Browse files
committed
🚀chore: develop 브랜치와 merge
2 parents a0d67b6 + 27ca54a commit 478a2db

File tree

7 files changed

+27
-38
lines changed

7 files changed

+27
-38
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ dependencies {
3838
implementation 'io.jsonwebtoken:jjwt-jackson:0.12.3'
3939

4040
// 응답 통일
41-
implementation 'org.namul:api-payload:0.5.1'
41+
implementation 'org.namul:api-payload:0.6.0'
4242

4343
// validation
4444
implementation 'org.springframework.boot:spring-boot-starter-validation'

src/main/java/org/withtime/be/withtimebe/domain/auth/service/command/AuthCommandServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class AuthCommandServiceImpl implements AuthCommandService {
3939
public void signUp(AuthRequestDTO.SignUp request) {
4040
validateSignUp(request);
4141

42-
Member member = memberRepository.save(AuthConverter.toLocalMember(request.email(), request.username(), passwordEncoder.encode(request.password()), request.phoneNumber(), request.gender(), request.birth()));
42+
Member member = memberRepository.save(AuthConverter.toLocalMember(request.email(), request.username(), request.socialId() != null ? passwordEncoder.encode(request.password()) : null, request.phoneNumber(), request.gender(), request.birth()));
4343
if (request.socialId() != null) {
4444
Social social = socialRepository.findById(request.socialId()).orElseThrow(() ->
4545
new SocialException(SocialErrorCode.NOT_FOUND_SOCIAL));
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
package org.withtime.be.withtimebe.global.error;
22

3-
import lombok.RequiredArgsConstructor;
4-
import org.namul.api.payload.code.DefaultResponseErrorCode;
53
import org.namul.api.payload.code.dto.supports.DefaultResponseErrorReasonDTO;
64
import org.namul.api.payload.error.configurer.DefaultExceptionAdviceConfigurer;
75
import org.namul.api.payload.error.configurer.ExceptionAdviceConfigurer;
86
import org.namul.api.payload.writer.FailureResponseWriter;
97
import org.springframework.context.annotation.Bean;
108
import org.springframework.context.annotation.Configuration;
11-
import org.springframework.web.servlet.resource.NoResourceFoundException;
129

1310
@Configuration
14-
@RequiredArgsConstructor
1511
public class ExceptionAdviceConfig {
1612

17-
private final NoResourceFoundExceptionHandler noResourceFoundExceptionHandler;
1813
@Bean
1914
ExceptionAdviceConfigurer<DefaultResponseErrorReasonDTO> defaultExceptionAdviceConfigurer(FailureResponseWriter<DefaultResponseErrorReasonDTO> failureResponseWriter) {
20-
ExceptionAdviceConfigurer<DefaultResponseErrorReasonDTO> configurer = new DefaultExceptionAdviceConfigurer(failureResponseWriter);
21-
configurer.addAdvice(NoResourceFoundException.class, noResourceFoundExceptionHandler, DefaultResponseErrorCode._BAD_REQUEST.getReason());
22-
return configurer;
15+
return new DefaultExceptionAdviceConfigurer(failureResponseWriter);
2316
}
2417
}

src/main/java/org/withtime/be/withtimebe/global/error/NoResourceFoundExceptionHandler.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/main/java/org/withtime/be/withtimebe/global/error/code/AuthErrorCode.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
@AllArgsConstructor
99
public enum AuthErrorCode implements BaseErrorCode {
1010

11+
NOT_FOUND_LOGIN_MEMBER(HttpStatus.NOT_FOUND, "AUTH404_1", "해당 이메일을 찾을 수 없습니다."),
1112
FAIL_AUTH_LOGIN(HttpStatus.UNAUTHORIZED, "AUTH401_1", "일반 로그인에 실패했습니다."),
12-
ALREADY_EXIST_EMAIL(HttpStatus.BAD_REQUEST, "AUTH400_1", "이미 존재하는 이메일입니다.")
13+
ALREADY_EXIST_EMAIL(HttpStatus.BAD_REQUEST, "AUTH400_1", "이미 존재하는 이메일입니다."),
14+
ONLY_AVAILABLE_SOCIAL(HttpStatus.BAD_REQUEST, "AUTH400_2", "소셜 로그인만 가능합니다.")
1315
;
1416
private final HttpStatus httpStatus;
1517
private final String code;

src/main/java/org/withtime/be/withtimebe/global/security/filter/JsonLoginFilter.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
import jakarta.servlet.http.HttpServletResponse;
99
import lombok.Getter;
1010
import lombok.RequiredArgsConstructor;
11+
import org.namul.api.payload.code.BaseErrorCode;
12+
import org.namul.api.payload.code.DefaultResponseErrorCode;
1113
import org.namul.api.payload.code.dto.supports.DefaultResponseErrorReasonDTO;
14+
import org.namul.api.payload.error.exception.ServerApplicationException;
1215
import org.namul.api.payload.writer.FailureResponseWriter;
1316
import org.springframework.http.HttpMethod;
1417
import org.springframework.http.MediaType;
@@ -51,6 +54,8 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
5154
return;
5255
}
5356
this.successfulAuthentication(request, response, authentication);
57+
} catch (ServerApplicationException e) {
58+
handleServerApplicationException(response, e);
5459
} catch (Exception e) {
5560
handleException(response, e);
5661
}
@@ -70,7 +75,8 @@ public Authentication attemptAuthentication(HttpServletRequest request) throws A
7075
} catch (IOException e) {
7176
throw new AuthenticationServiceException("Json Parsing Error In Json Filter");
7277
} catch (Exception e) {
73-
throw new AuthenticationServiceException("CustomJsonUsernamePasswordLoginFilter(" + e.getClass() + "): " + e.getMessage());
78+
Throwable throwable = e.getCause();
79+
throw throwable instanceof ServerApplicationException serverApplicationException ? serverApplicationException : new AuthenticationServiceException("CustomJsonUsernamePasswordLoginFilter(" + e.getClass() + "): " + e.getMessage());
7480
}
7581
}
7682

@@ -93,6 +99,14 @@ private AuthRequestDTO.Login getBodyInRequest(HttpServletRequest request) throws
9399
return om.readValue(content, AuthRequestDTO.Login.class);
94100
}
95101

102+
private void handleServerApplicationException(HttpServletResponse response, ServerApplicationException e) throws IOException {
103+
ObjectMapper om = new ObjectMapper();
104+
DefaultResponseErrorReasonDTO reasonDTO = e.getCode().getReason() instanceof DefaultResponseErrorReasonDTO defaultResponseErrorReasonDTO ? defaultResponseErrorReasonDTO : DefaultResponseErrorCode._UNAUTHORIZED.getReason();
105+
response.setStatus(reasonDTO.getHttpStatus().value());
106+
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
107+
om.writeValue(response.getOutputStream(), failureResponseWriter.onFailure(reasonDTO, e.getMessage()));
108+
}
109+
96110
private void handleException(HttpServletResponse response, Exception e) throws IOException {
97111
ObjectMapper om = new ObjectMapper();
98112
DefaultResponseErrorReasonDTO reasonDTO = AuthErrorCode.FAIL_AUTH_LOGIN.getReason();

src/main/java/org/withtime/be/withtimebe/global/security/service/CustomUserDetailsService.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import org.springframework.stereotype.Component;
88
import org.withtime.be.withtimebe.domain.member.entity.Member;
99
import org.withtime.be.withtimebe.domain.member.repository.MemberRepository;
10-
import org.withtime.be.withtimebe.global.error.code.MemberErrorCode;
11-
import org.withtime.be.withtimebe.global.error.exception.MemberException;
10+
import org.withtime.be.withtimebe.global.error.code.AuthErrorCode;
11+
import org.withtime.be.withtimebe.global.error.exception.AuthException;
1212
import org.withtime.be.withtimebe.global.security.domain.CustomUserDetails;
1313

1414
@Component
@@ -19,7 +19,10 @@ public class CustomUserDetailsService implements UserDetailsService {
1919

2020
@Override
2121
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
22-
Member member = memberRepository.findByEmail(email).orElseThrow(() -> new MemberException(MemberErrorCode.NOT_FOUND));
22+
Member member = memberRepository.findByEmail(email).orElseThrow(() -> new AuthException(AuthErrorCode.NOT_FOUND_LOGIN_MEMBER));
23+
if (member.getPassword() == null) {
24+
throw new AuthException(AuthErrorCode.ONLY_AVAILABLE_SOCIAL);
25+
}
2326
return new CustomUserDetails(member);
2427
}
2528
}

0 commit comments

Comments
 (0)