Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/main/java/org/runimo/runimo/auth/service/OidcService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
public class OidcService {

private final KakaoTokenVerifier verifier;
private final OidcNonceService nonceService;

public String validateOidcTokenAndGetProviderId(final DecodedJWT token, final SocialProvider provider) {
DecodedJWT verifyResult;
Expand All @@ -20,7 +19,6 @@ public String validateOidcTokenAndGetProviderId(final DecodedJWT token, final So
case KAKAO -> verifyResult = verifier.verifyToken(token);
default -> throw new IllegalStateException("not supported provider");
}
nonceService.checkNonceAndSave(provider, verifyResult);
return verifyResult.getSubject();
}
}
1 change: 1 addition & 0 deletions src/main/java/org/runimo/runimo/common/BaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public abstract class BaseEntity implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Id
@Column(name = "id", nullable = false, updatable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Long id;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package org.runimo.runimo.exceptions;

import lombok.extern.slf4j.Slf4j;
import org.runimo.runimo.common.response.ErrorResponse;
import org.runimo.runimo.user.exceptions.SignUpException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.ErrorResponse;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

Expand All @@ -12,6 +13,12 @@
@RestControllerAdvice
public class GlobalExceptionHandler {

@ExceptionHandler(SignUpException.class)
public ResponseEntity<ErrorResponse> handleSignUpException(SignUpException e) {
log.debug("ERROR: {}}", e.getMessage(), e);
return ResponseEntity.badRequest().body(ErrorResponse.of(e.getErrorCode()));
}

@ExceptionHandler(NoSuchElementException.class)
public ResponseEntity<ErrorResponse> handleNoSuchElementException(NoSuchElementException e) {
log.debug("ERROR: {}}", e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ public enum UserHttpResponseCode implements CustomResponseCode {

USE_ITEM_SUCCESS("USH2005", "아이템 사용 성공", "아이템 사용 성공"),
REGISTER_EGG_SUCCESS("USH2006", "부화기 등록 성공", "부화기 등록 성공"),
USE_LOVE_POINT_SUCCESS("USH2007","애정 사용 성공" , "애정 사용 성공");
USE_LOVE_POINT_SUCCESS("USH2007","애정 사용 성공" , "애정 사용 성공"),

LOGIN_FAIL_NOT_SIGN_IN("UEH4041", "로그인 실패 - 회원가입하지 않은 사용자", "로그인 실패 - 회원가입하지 않은 사용자"),
SIGNIN_FAIL_ALREADY_EXIST("UEH4042", "로그인 실패 - 이미 존재하는 사용자", "로그인 실패 - 이미 존재하는 사용자"),;

private final String code;
private final String clientMessage;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.runimo.runimo.user.exceptions;

import org.runimo.runimo.exceptions.BusinessException;
import org.runimo.runimo.exceptions.code.CustomResponseCode;

public class SignUpException extends BusinessException {

public SignUpException(CustomResponseCode errorCode) {
super(errorCode);
}

protected SignUpException(CustomResponseCode errorCode, String logMessage) {
super(errorCode, logMessage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.runimo.runimo.user.domain.OAuthInfo;
import org.runimo.runimo.user.domain.SocialProvider;
import org.runimo.runimo.user.domain.User;
import org.runimo.runimo.user.enums.UserHttpResponseCode;
import org.runimo.runimo.user.exceptions.SignUpException;
import org.runimo.runimo.user.repository.OAuthInfoRepository;
import org.runimo.runimo.user.service.dtos.AuthResponse;
import org.runimo.runimo.user.service.dtos.SignupUserResponse;
Expand All @@ -34,7 +36,7 @@ public AuthResponse validateAndLogin(final String rawToken, final SocialProvider
DecodedJWT token = JWT.decode(rawToken);
String pid = oidcService.validateOidcTokenAndGetProviderId(token, provider);
OAuthInfo oAuthInfo = oAuthInfoRepository.findByProviderAndProviderId(provider, pid)
.orElseThrow(() -> new NoSuchElementException("가입된 유저 없음."));
.orElseThrow(() -> new SignUpException(UserHttpResponseCode.LOGIN_FAIL_NOT_SIGN_IN));
oidcNonceService.useNonce(token, provider);
TokenPair tokenPair = jwtfactory.generateTokenPair(oAuthInfo.getUser());
return new AuthResponse(oAuthInfo.getUser(), tokenPair);
Expand All @@ -47,7 +49,7 @@ public SignupUserResponse validateAndSignup(final UserSignupCommand command, fin
String pid = oidcService.validateOidcTokenAndGetProviderId(token, provider);
oAuthInfoRepository.findByProviderAndProviderId(provider, pid)
.ifPresent(oAuthInfo -> {
throw new IllegalArgumentException("이미 존재하는 회원입니다.");
throw new SignUpException(UserHttpResponseCode.SIGNIN_FAIL_ALREADY_EXIST);
});
User savedUser = userRegisterService.register(command, pid);
TokenPair tokenPair = jwtfactory.generateTokenPair(savedUser);
Expand Down