From 5744641eafc0c08b58d4e7ecd8b61e7fdd6ffe29 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Fri, 27 Oct 2023 15:32:11 +0900 Subject: [PATCH 01/15] =?UTF-8?q?[feat]=20=EC=97=90=EB=9F=AC=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/CustomExceptionContext.java | 25 +++++++++++ .../global/exception/ErrorResponse.java | 13 ++++++ .../global/exception/ExceptionContext.java | 11 +++++ .../exception/GlobalExceptionHandler.java | 43 +++++++++++++++++++ .../exception/ModernFarmerException.java | 19 ++++++++ .../badrequest/BadRequestException.java | 13 ++++++ .../badrequest/FirebaseConfigException.java | 10 +++++ .../exception/notfound/NotFoundException.java | 16 +++++++ .../notfound/NotFoundMedicineException.java | 12 ++++++ .../notfound/NotFoundMemberException.java | 12 ++++++ .../unauthorized/InvalidBearerException.java | 8 ++++ .../unauthorized/InvalidTokenException.java | 12 ++++++ .../unauthorized/TokenExpiredException.java | 12 ++++++ .../unauthorized/UnauthorizedException.java | 12 ++++++ .../farmususer/user/service/AuthService.java | 4 ++ 15 files changed, 222 insertions(+) create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/CustomExceptionContext.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/ErrorResponse.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/ExceptionContext.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/GlobalExceptionHandler.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/ModernFarmerException.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/badrequest/BadRequestException.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/badrequest/FirebaseConfigException.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundException.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMedicineException.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMemberException.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidBearerException.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidTokenException.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/TokenExpiredException.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/UnauthorizedException.java diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/CustomExceptionContext.java b/src/main/java/modernfarmer/server/farmususer/global/exception/CustomExceptionContext.java new file mode 100644 index 0000000..bf83931 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/CustomExceptionContext.java @@ -0,0 +1,25 @@ +package modernfarmer.server.farmususer.global.exception; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +@Getter +@RequiredArgsConstructor +public enum CustomExceptionContext implements ExceptionContext{ + // MEMBER (예시) + NOT_FOUND_MEMBER_ERROR(HttpStatus.NOT_FOUND, 1000, "해당 회원을 찾을 수 없습니다."), + INVALID_MEMBER_ID_ERROR(HttpStatus.BAD_REQUEST, 1001, "회원에 대한 유효하지 않은 요청입니다."), + NOT_FOUND_ALARM_ERROR(HttpStatus.NOT_FOUND, 1002, "해당 알람 정보를 찾을 수 없습니다."), + INVALID_ADD_MEMBER(HttpStatus.BAD_REQUEST, 1003, "이미 존재하는 캐릭터입니다."), + SDK_NOT_FOUND(HttpStatus.BAD_REQUEST, 1007, "해당 경로에 Firebase SDK json 파일이 존재하지 않아, Firebase 시스템을 초기화 할 수 없습니다."), + FIREBASE_TOKEN_EXCEPTION(HttpStatus.BAD_REQUEST, 1004, "파이어베이스 토큰 오류입니다."), + FIREBASE_CONFIG_EXCEPTION(HttpStatus.BAD_REQUEST, 1005, "파이어베이스 설정 오류입니다."), + NOT_FOUND_MEDICINE_ERROR(HttpStatus.NOT_FOUND, 1006, "해당 약 정보를 찾을 수 없습니다."); + // DOMAIN PER EXCEPTIONS ... + + + private final HttpStatus httpStatus; + private final int code; + private final String message; +} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/ErrorResponse.java b/src/main/java/modernfarmer/server/farmususer/global/exception/ErrorResponse.java new file mode 100644 index 0000000..472b87c --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/ErrorResponse.java @@ -0,0 +1,13 @@ +package modernfarmer.server.farmususer.global.exception; + +import lombok.*; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@ToString +public class ErrorResponse { + + private int code; + private String message; +} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/ExceptionContext.java b/src/main/java/modernfarmer/server/farmususer/global/exception/ExceptionContext.java new file mode 100644 index 0000000..8f2bbb7 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/ExceptionContext.java @@ -0,0 +1,11 @@ +package modernfarmer.server.farmususer.global.exception; + +import org.springframework.http.HttpStatus; + +public interface ExceptionContext { + HttpStatus getHttpStatus(); + + String getMessage(); + + int getCode(); +} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/GlobalExceptionHandler.java b/src/main/java/modernfarmer/server/farmususer/global/exception/GlobalExceptionHandler.java new file mode 100644 index 0000000..7f34258 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/GlobalExceptionHandler.java @@ -0,0 +1,43 @@ +package modernfarmer.server.farmususer.global.exception; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.FieldError; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import javax.servlet.http.HttpServletRequest; +import java.util.Objects; + +@Slf4j +@RequiredArgsConstructor +@RestControllerAdvice +public class GlobalExceptionHandler { + private final int INVALID_PARAMETER_CODE = 400; + + @ExceptionHandler(MethodArgumentNotValidException.class) + public ResponseEntity handleInputFieldException(MethodArgumentNotValidException e) { + FieldError mainError = e.getFieldErrors().get(0); + String[] errorInfo = Objects.requireNonNull(mainError.getDefaultMessage()).split(":"); + String message = errorInfo[0]; + return ResponseEntity.badRequest().body(new ErrorResponse(INVALID_PARAMETER_CODE, message)); + } + + @ExceptionHandler(ModernFarmerException.class) + public ResponseEntity handleModernFarmerException(ModernFarmerException e) { + return ResponseEntity.status(e.getHttpStatus()).body(new ErrorResponse(e.getCode(), e.getMessage())); + } + + @ExceptionHandler(Exception.class) + public ResponseEntity unhandledException(Exception e, HttpServletRequest request) { + log.error("UnhandledException: {} {} errMessage={}\n", + request.getMethod(), + request.getRequestURI(), + e.getMessage() + ); + return ResponseEntity.internalServerError() + .body(new ErrorResponse(7777, "서버와의 접속이 원활하지 않습니다.")); + } +} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/ModernFarmerException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/ModernFarmerException.java new file mode 100644 index 0000000..6a40961 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/ModernFarmerException.java @@ -0,0 +1,19 @@ +package modernfarmer.server.farmususer.global.exception; + +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +public class ModernFarmerException extends RuntimeException { + private final HttpStatus httpStatus; + private final String message; + private final int code; + + public ModernFarmerException(HttpStatus httpStatus, String message, int code) { + this.httpStatus = httpStatus; + this.message = message; + this.code = code; + } + + +} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/badrequest/BadRequestException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/badrequest/BadRequestException.java new file mode 100644 index 0000000..b91018d --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/badrequest/BadRequestException.java @@ -0,0 +1,13 @@ +package modernfarmer.server.farmususer.global.exception.badrequest; + + +import lombok.Getter; +import modernfarmer.server.farmususer.global.exception.ExceptionContext; +import modernfarmer.server.farmususer.global.exception.ModernFarmerException; + +@Getter +public class BadRequestException extends ModernFarmerException { + public BadRequestException(ExceptionContext context){ + super(context.getHttpStatus(), context.getMessage(), context.getCode()); + } +} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/badrequest/FirebaseConfigException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/badrequest/FirebaseConfigException.java new file mode 100644 index 0000000..fa3c385 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/badrequest/FirebaseConfigException.java @@ -0,0 +1,10 @@ +package modernfarmer.server.farmususer.global.exception.badrequest; + + +import static modernfarmer.server.farmususer.global.exception.CustomExceptionContext.FIREBASE_CONFIG_EXCEPTION; + +public class FirebaseConfigException extends BadRequestException { + public FirebaseConfigException(){ + super(FIREBASE_CONFIG_EXCEPTION); + } +} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundException.java new file mode 100644 index 0000000..a522576 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundException.java @@ -0,0 +1,16 @@ +package modernfarmer.server.farmususer.global.exception.notfound; + + +import lombok.Getter; +import modernfarmer.server.farmususer.global.exception.ExceptionContext; +import modernfarmer.server.farmususer.global.exception.ModernFarmerException; +import org.springframework.http.HttpStatus; + +@Getter +public class NotFoundException extends ModernFarmerException { + public NotFoundException(ExceptionContext context) { + super(context.getHttpStatus(), context.getMessage(), context.getCode()); + } + + +} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMedicineException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMedicineException.java new file mode 100644 index 0000000..2d02c6c --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMedicineException.java @@ -0,0 +1,12 @@ +package modernfarmer.server.farmususer.global.exception.notfound; + + +import modernfarmer.server.farmususer.global.exception.ModernFarmerException; + +import static modernfarmer.server.farmususer.global.exception.CustomExceptionContext.NOT_FOUND_MEDICINE_ERROR; + +public class NotFoundMedicineException extends NotFoundException { + public NotFoundMedicineException() { + super(NOT_FOUND_MEDICINE_ERROR); + } +} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMemberException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMemberException.java new file mode 100644 index 0000000..976fe3e --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMemberException.java @@ -0,0 +1,12 @@ +package modernfarmer.server.farmususer.global.exception.notfound; + +import modernfarmer.server.farmususer.global.exception.ModernFarmerException; + +import static modernfarmer.server.farmususer.global.exception.CustomExceptionContext.NOT_FOUND_MEMBER_ERROR; + + +public class NotFoundMemberException extends NotFoundException { + public NotFoundMemberException() { + super(NOT_FOUND_MEMBER_ERROR); + } +} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidBearerException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidBearerException.java new file mode 100644 index 0000000..01c1a40 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidBearerException.java @@ -0,0 +1,8 @@ +package modernfarmer.server.farmususer.global.exception.unauthorized; + +public class InvalidBearerException extends UnauthorizedException { + + public InvalidBearerException() { + super("로그인이 필요한 서비스입니다.", 1013); + } +} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidTokenException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidTokenException.java new file mode 100644 index 0000000..55af400 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidTokenException.java @@ -0,0 +1,12 @@ +package modernfarmer.server.farmususer.global.exception.unauthorized; + +public class InvalidTokenException extends UnauthorizedException { + + public InvalidTokenException() { + super("올바르지 않은 토큰입니다. 다시 로그인해주세요.", 1015); + } + + public InvalidTokenException(String message) { + super(message, 1015); + } +} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/TokenExpiredException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/TokenExpiredException.java new file mode 100644 index 0000000..f7882b6 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/TokenExpiredException.java @@ -0,0 +1,12 @@ +package modernfarmer.server.farmususer.global.exception.unauthorized; + +public class TokenExpiredException extends UnauthorizedException { + + public TokenExpiredException() { + super("로그인 인증 유효기간이 만료되었습니다. 다시 로그인 해주세요.", 1014); + } + + public TokenExpiredException(String message) { + super(message, 1014); + } +} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/UnauthorizedException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/UnauthorizedException.java new file mode 100644 index 0000000..8ebccb6 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/UnauthorizedException.java @@ -0,0 +1,12 @@ +package modernfarmer.server.farmususer.global.exception.unauthorized; + + +import modernfarmer.server.farmususer.global.exception.ModernFarmerException; +import org.springframework.http.HttpStatus; + +public class UnauthorizedException extends ModernFarmerException { + + public UnauthorizedException(String message, int code) { + super(HttpStatus.UNAUTHORIZED, message, code); + } +} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java index 32da0bd..d399a87 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java @@ -1,6 +1,7 @@ package modernfarmer.server.farmususer.user.service; import lombok.extern.slf4j.Slf4j; +import modernfarmer.server.farmususer.global.exception.unauthorized.TokenExpiredException; import modernfarmer.server.farmususer.user.dto.response.GoogleUserResponseDto; import modernfarmer.server.farmususer.user.dto.response.KakaoUserResponseDto; import modernfarmer.server.farmususer.user.dto.response.ResponseDto; @@ -163,6 +164,9 @@ public TokenResponseDto reissueToken(String refreshToken, Long userId) { .code(417) .message("재로그인하시오") .build(); + + + new TokenExpiredException(); return reissueTokenResponse; } From d9506d3c959a7bb525b9382799e5d6e6cad7043a Mon Sep 17 00:00:00 2001 From: seungryeol Date: Fri, 27 Oct 2023 17:19:16 +0900 Subject: [PATCH 02/15] =?UTF-8?q?[feat]=20=EC=9E=AC=EB=B0=9C=EA=B8=89=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=EC=B2=98=EB=A6=AC=20=EC=A0=81=EC=9A=A9=20?= =?UTF-8?q?=ED=99=95=EC=9D=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- .../unauthorized/InvalidBearerException.java | 8 -- .../unauthorized/InvalidTokenException.java | 12 --- .../user/controller/UserController.java | 8 +- .../farmususer/user/service/AuthService.java | 66 -------------- .../farmususer/user/service/UserService.java | 90 +++++++++++++++++++ .../user/util/JwtTokenProvider.java | 4 +- 7 files changed, 98 insertions(+), 92 deletions(-) delete mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidBearerException.java delete mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidTokenException.java create mode 100644 src/main/java/modernfarmer/server/farmususer/user/service/UserService.java diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 2b9666e..20917ec 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -2,7 +2,7 @@ name: ModernFarmer CI/CD on: push: - branches: ["dev"] + branches: ["feature_11/에러처리-추가"] pull_request: branches: ["dev"] diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidBearerException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidBearerException.java deleted file mode 100644 index 01c1a40..0000000 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidBearerException.java +++ /dev/null @@ -1,8 +0,0 @@ -package modernfarmer.server.farmususer.global.exception.unauthorized; - -public class InvalidBearerException extends UnauthorizedException { - - public InvalidBearerException() { - super("로그인이 필요한 서비스입니다.", 1013); - } -} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidTokenException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidTokenException.java deleted file mode 100644 index 55af400..0000000 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/InvalidTokenException.java +++ /dev/null @@ -1,12 +0,0 @@ -package modernfarmer.server.farmususer.global.exception.unauthorized; - -public class InvalidTokenException extends UnauthorizedException { - - public InvalidTokenException() { - super("올바르지 않은 토큰입니다. 다시 로그인해주세요.", 1015); - } - - public InvalidTokenException(String message) { - super(message, 1015); - } -} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index fd8a8bf..60eed70 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -4,7 +4,9 @@ import lombok.extern.slf4j.Slf4j; import modernfarmer.server.farmususer.user.dto.response.ResponseDto; import modernfarmer.server.farmususer.user.dto.response.TokenResponseDto; + import modernfarmer.server.farmususer.user.service.AuthService; +import modernfarmer.server.farmususer.user.service.UserService; import modernfarmer.server.farmususer.user.util.JwtTokenProvider; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; @@ -19,7 +21,7 @@ @RequiredArgsConstructor public class UserController { - private final AuthService authService; + private final UserService userService; private final JwtTokenProvider jwtTokenProvider; @@ -29,7 +31,7 @@ public ResponseDto logout(HttpServletRequest request) { String userId = jwtTokenProvider.getUserId(request); - ResponseDto logoutResponseDto = authService.logout(Long.valueOf(userId)); + ResponseDto logoutResponseDto = userService.logout(Long.valueOf(userId)); log.info("로그아웃 완료"); @@ -42,7 +44,7 @@ public TokenResponseDto reissueToken(HttpServletRequest request) { String userId = jwtTokenProvider.getUserId(request); String refreshToken = jwtTokenProvider.resolveToken(request); - TokenResponseDto reissueTokenResponseDto = authService.reissueToken(refreshToken, Long.valueOf(userId)); + TokenResponseDto reissueTokenResponseDto = userService.reissueToken(refreshToken, Long.valueOf(userId)); log.info("토큰 재발급 완료"); diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java index d399a87..03f9d1d 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java @@ -145,72 +145,6 @@ public TokenResponseDto kakaoLogin(String accessToken) { } - public ResponseDto logout(Long userId) { - deleteValueByKey(String.valueOf(userId)); - - ResponseDto responseDto = ResponseDto.builder() - .message("OK") - .code(200) - .build(); - return responseDto; - } - - public TokenResponseDto reissueToken(String refreshToken, Long userId) { - TokenResponseDto reissueTokenResponse; - - if(!jwtTokenProvider.validateRefreshToken(refreshToken)){ - - reissueTokenResponse = TokenResponseDto.builder() - .code(417) - .message("재로그인하시오") - .build(); - - - new TokenExpiredException(); - - return reissueTokenResponse; - } - - String redisRefreshToken = redisTemplate.opsForValue().get(userId.toString()); - - if(redisRefreshToken.equals(refreshToken)){ - - String userRole = userRepository.findUserRole(userId); - - reissueTokenResponse= TokenResponseDto - .builder() - .code(200) - .message("OK") - .accessToken(jwtTokenProvider.createAccessToken(userId, userRole)) - .refreshToken(refreshToken) - .build(); - - return reissueTokenResponse; - - } - - reissueTokenResponse = TokenResponseDto.builder() - .code(403) - .message("접근이 올바르지 않습니다.") - .build(); - - return reissueTokenResponse; - - } - - - - - public void deleteValueByKey(String key) { - redisTemplate.delete(key); - } - - - - - - - public Mono getUserKakaoInfo(String accessToken) { return webClient .get() diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java new file mode 100644 index 0000000..5bb839f --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -0,0 +1,90 @@ +package modernfarmer.server.farmususer.user.service; + +import modernfarmer.server.farmususer.global.exception.unauthorized.TokenExpiredException; +import modernfarmer.server.farmususer.user.dto.response.ResponseDto; +import modernfarmer.server.farmususer.user.dto.response.TokenResponseDto; +import modernfarmer.server.farmususer.user.repository.UserRepository; +import modernfarmer.server.farmususer.user.util.JwtTokenProvider; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; +import org.springframework.web.reactive.function.client.WebClient; + + +@Service +public class UserService { + + public JwtTokenProvider jwtTokenProvider; + public RedisTemplate redisTemplate; + + public UserRepository userRepository; + + private final WebClient webClient; + + @Autowired + public UserService(WebClient webClient, UserRepository userRepository, JwtTokenProvider jwtTokenProvider, RedisTemplate redisTemplate) { + this.webClient = webClient; + this.userRepository = userRepository; + this.jwtTokenProvider = jwtTokenProvider; + this.redisTemplate = redisTemplate; + } + + + public ResponseDto logout(Long userId) { + deleteValueByKey(String.valueOf(userId)); + + ResponseDto responseDto = ResponseDto.builder() + .message("OK") + .code(200) + .build(); + return responseDto; + } + + public TokenResponseDto reissueToken(String refreshToken, Long userId) { + TokenResponseDto reissueTokenResponse; + + if(!jwtTokenProvider.validateRefreshToken(refreshToken)){ + +// reissueTokenResponse = TokenResponseDto.builder() +// .code(417) +// .message("재로그인하시오") +// .build(); + + + new TokenExpiredException(); + + // return reissueTokenResponse; + } + + String redisRefreshToken = redisTemplate.opsForValue().get(userId.toString()); + + if(redisRefreshToken.equals(refreshToken)){ + + String userRole = userRepository.findUserRole(userId); + + reissueTokenResponse= TokenResponseDto + .builder() + .code(200) + .message("OK") + .accessToken(jwtTokenProvider.createAccessToken(userId, userRole)) + .refreshToken(refreshToken) + .build(); + + return reissueTokenResponse; + + } + + reissueTokenResponse = TokenResponseDto.builder() + .code(403) + .message("접근이 올바르지 않습니다.") + .build(); + + return reissueTokenResponse; + + } + + public void deleteValueByKey(String key) { + redisTemplate.delete(key); + } + +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java b/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java index 998d757..12d657b 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java +++ b/src/main/java/modernfarmer/server/farmususer/user/util/JwtTokenProvider.java @@ -26,10 +26,10 @@ public class JwtTokenProvider { private String secretKey; - private final long accessTokenTime = 30L * 24L * 60 * 60 * 1000; // 1달 토큰 유효 + private final long accessTokenTime = 30L * 1000;; // 1달 토큰 유효 - private final long refreshTokenTime = 1L * 60 * 1000 * 2; // 1달 토큰 유효 + private final long refreshTokenTime = 30L * 1000 * 2; // 1달 토큰 유효 @PostConstruct protected void init() { From 72233ddb07ad9d6819ad3dd8a2c51fffa50846a4 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Fri, 27 Oct 2023 17:23:22 +0900 Subject: [PATCH 03/15] =?UTF-8?q?[fix]=20=EC=9D=B8=EC=8A=A4=ED=84=B4?= =?UTF-8?q?=EC=8A=A4=20=EB=8F=84=EC=BB=A4=20=EA=B6=8C=ED=95=9C=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 20917ec..be8a018 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -7,7 +7,6 @@ on: pull_request: branches: ["dev"] - permissions: contents: read From b976adffdfc757349714cc722965d74f5d7f165e Mon Sep 17 00:00:00 2001 From: seungryeol Date: Fri, 27 Oct 2023 18:21:17 +0900 Subject: [PATCH 04/15] =?UTF-8?q?[fix]=20jwt=20secret=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index be8a018..100b0c8 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -63,6 +63,7 @@ jobs: docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 . docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 + # 서버에서 Docker 이미지 실행 - name: EC2 Docker Run uses: appleboy/ssh-action@master From 999737025784cd684f2a272a4ad59372d24b8614 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Fri, 27 Oct 2023 18:33:09 +0900 Subject: [PATCH 05/15] =?UTF-8?q?[fix]=20=ED=8F=AC=ED=8A=B8=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 100b0c8..c1b2e44 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -76,4 +76,4 @@ jobs: docker rm ModernFarmerUser docker rmi ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 - docker run -d -p 80:8080 --name ModernFarmerUser ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 + docker run -d -p 80:8081 --name ModernFarmerUser ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 From 5c88fb20a08d0a2cd9646cd294cefb209c1b4849 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Fri, 27 Oct 2023 18:48:24 +0900 Subject: [PATCH 06/15] =?UTF-8?q?[fix]=20=ED=8F=AC=ED=8A=B8=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index c1b2e44..5213cb3 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -63,7 +63,6 @@ jobs: docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 . docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 - # 서버에서 Docker 이미지 실행 - name: EC2 Docker Run uses: appleboy/ssh-action@master From 9b2181bb239380ea8da4c554c263cf49de50a9fa Mon Sep 17 00:00:00 2001 From: seungryeol Date: Fri, 27 Oct 2023 18:54:11 +0900 Subject: [PATCH 07/15] =?UTF-8?q?[fix]=20=ED=8F=AC=ED=8A=B8=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 5213cb3..be8a018 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -75,4 +75,4 @@ jobs: docker rm ModernFarmerUser docker rmi ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 - docker run -d -p 80:8081 --name ModernFarmerUser ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 + docker run -d -p 80:8080 --name ModernFarmerUser ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 From 99cd678acd8fcb4cdb1a6279bccf833382ab2c7f Mon Sep 17 00:00:00 2001 From: seungryeol Date: Fri, 27 Oct 2023 19:04:53 +0900 Subject: [PATCH 08/15] =?UTF-8?q?[fix]=20=ED=8F=AC=ED=8A=B8=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EB=B3=80=EA=B2=BD=208081?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index be8a018..5213cb3 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -75,4 +75,4 @@ jobs: docker rm ModernFarmerUser docker rmi ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 - docker run -d -p 80:8080 --name ModernFarmerUser ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 + docker run -d -p 80:8081 --name ModernFarmerUser ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:1.0 From 885b27b3954baf98ea8a5bc72ff2597d163845cd Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sat, 28 Oct 2023 02:45:22 +0900 Subject: [PATCH 09/15] =?UTF-8?q?[fix]=20unauthorizedException=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unauthorized/TokenExpiredException.java | 12 ------------ .../unauthorized/UnauthorizedException.java | 12 ------------ .../farmususer/user/service/AuthService.java | 4 ---- .../farmususer/user/service/UserService.java | 14 -------------- 4 files changed, 42 deletions(-) delete mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/TokenExpiredException.java delete mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/UnauthorizedException.java diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/TokenExpiredException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/TokenExpiredException.java deleted file mode 100644 index f7882b6..0000000 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/TokenExpiredException.java +++ /dev/null @@ -1,12 +0,0 @@ -package modernfarmer.server.farmususer.global.exception.unauthorized; - -public class TokenExpiredException extends UnauthorizedException { - - public TokenExpiredException() { - super("로그인 인증 유효기간이 만료되었습니다. 다시 로그인 해주세요.", 1014); - } - - public TokenExpiredException(String message) { - super(message, 1014); - } -} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/UnauthorizedException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/UnauthorizedException.java deleted file mode 100644 index 8ebccb6..0000000 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/unauthorized/UnauthorizedException.java +++ /dev/null @@ -1,12 +0,0 @@ -package modernfarmer.server.farmususer.global.exception.unauthorized; - - -import modernfarmer.server.farmususer.global.exception.ModernFarmerException; -import org.springframework.http.HttpStatus; - -public class UnauthorizedException extends ModernFarmerException { - - public UnauthorizedException(String message, int code) { - super(HttpStatus.UNAUTHORIZED, message, code); - } -} \ No newline at end of file diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java index 03f9d1d..20add15 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java @@ -1,16 +1,12 @@ package modernfarmer.server.farmususer.user.service; import lombok.extern.slf4j.Slf4j; -import modernfarmer.server.farmususer.global.exception.unauthorized.TokenExpiredException; import modernfarmer.server.farmususer.user.dto.response.GoogleUserResponseDto; import modernfarmer.server.farmususer.user.dto.response.KakaoUserResponseDto; -import modernfarmer.server.farmususer.user.dto.response.ResponseDto; import modernfarmer.server.farmususer.user.dto.response.TokenResponseDto; import modernfarmer.server.farmususer.user.entity.User; import modernfarmer.server.farmususer.user.repository.UserRepository; import modernfarmer.server.farmususer.user.util.JwtTokenProvider; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.http.HttpStatus; diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 5bb839f..b50093a 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -1,6 +1,5 @@ package modernfarmer.server.farmususer.user.service; -import modernfarmer.server.farmususer.global.exception.unauthorized.TokenExpiredException; import modernfarmer.server.farmususer.user.dto.response.ResponseDto; import modernfarmer.server.farmususer.user.dto.response.TokenResponseDto; import modernfarmer.server.farmususer.user.repository.UserRepository; @@ -43,19 +42,6 @@ public ResponseDto logout(Long userId) { public TokenResponseDto reissueToken(String refreshToken, Long userId) { TokenResponseDto reissueTokenResponse; - if(!jwtTokenProvider.validateRefreshToken(refreshToken)){ - -// reissueTokenResponse = TokenResponseDto.builder() -// .code(417) -// .message("재로그인하시오") -// .build(); - - - new TokenExpiredException(); - - // return reissueTokenResponse; - } - String redisRefreshToken = redisTemplate.opsForValue().get(userId.toString()); if(redisRefreshToken.equals(refreshToken)){ From 217f533be84ffab730ebc9b3570ac3f058521c1d Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sat, 28 Oct 2023 03:06:35 +0900 Subject: [PATCH 10/15] =?UTF-8?q?[fix]=20=ED=86=A0=ED=81=B0=20=EC=9E=AC?= =?UTF-8?q?=EB=B0=9C=EA=B8=89=20=EC=8B=9C=20=EB=A6=AC=ED=94=84=EB=A0=88?= =?UTF-8?q?=EC=8B=9C=20=ED=86=A0=ED=81=B0=20=EB=B9=88=20=EA=B0=92=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/service/UserService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index b50093a..1d60305 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -9,6 +9,8 @@ import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.client.WebClient; +import java.util.Objects; + @Service public class UserService { @@ -44,7 +46,7 @@ public TokenResponseDto reissueToken(String refreshToken, Long userId) { String redisRefreshToken = redisTemplate.opsForValue().get(userId.toString()); - if(redisRefreshToken.equals(refreshToken)){ + if(Objects.requireNonNull(redisRefreshToken).equals(refreshToken)){ String userRole = userRepository.findUserRole(userId); From b1503a565b18c019c1abfac3b2a0d2aeb2d6dcfd Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sat, 28 Oct 2023 03:10:11 +0900 Subject: [PATCH 11/15] =?UTF-8?q?[fix]=20=ED=86=A0=ED=81=B0=20=EC=9E=AC?= =?UTF-8?q?=EB=B0=9C=EA=B8=89=20=EC=8B=9C=20=EB=A6=AC=ED=94=84=EB=A0=88?= =?UTF-8?q?=EC=8B=9C=20=ED=86=A0=ED=81=B0=20=EB=B9=88=20=EA=B0=92=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/service/UserService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 1d60305..fae8b0f 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -46,7 +46,7 @@ public TokenResponseDto reissueToken(String refreshToken, Long userId) { String redisRefreshToken = redisTemplate.opsForValue().get(userId.toString()); - if(Objects.requireNonNull(redisRefreshToken).equals(refreshToken)){ + if(Objects.requireNonNull(redisRefreshToken).equals(refreshToken) || redisRefreshToken.isEmpty()){ String userRole = userRepository.findUserRole(userId); From 8dcb7299c995489a5e1aa3d11a6a8cb93e3fedc6 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sat, 28 Oct 2023 03:14:08 +0900 Subject: [PATCH 12/15] =?UTF-8?q?[fix]=20=ED=86=A0=ED=81=B0=20=EC=9E=AC?= =?UTF-8?q?=EB=B0=9C=EA=B8=89=20=EC=8B=9C=20=EB=A6=AC=ED=94=84=EB=A0=88?= =?UTF-8?q?=EC=8B=9C=20=ED=86=A0=ED=81=B0=20=EB=B9=88=20=EA=B0=92=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/service/UserService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index fae8b0f..843b2b1 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -46,7 +46,7 @@ public TokenResponseDto reissueToken(String refreshToken, Long userId) { String redisRefreshToken = redisTemplate.opsForValue().get(userId.toString()); - if(Objects.requireNonNull(redisRefreshToken).equals(refreshToken) || redisRefreshToken.isEmpty()){ + if(Objects.requireNonNull(redisRefreshToken).equals(refreshToken) && !redisRefreshToken.isEmpty()){ String userRole = userRepository.findUserRole(userId); From 4c168cdbe9f01eda20cc3743ef6301528fc2ae8b Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sat, 28 Oct 2023 03:21:57 +0900 Subject: [PATCH 13/15] =?UTF-8?q?[fix]=20=ED=86=A0=ED=81=B0=20=EC=9E=AC?= =?UTF-8?q?=EB=B0=9C=EA=B8=89=20=EC=8B=9C=20=EB=A6=AC=ED=94=84=EB=A0=88?= =?UTF-8?q?=EC=8B=9C=20=ED=86=A0=ED=81=B0=20=EB=B9=88=20=EA=B0=92=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/service/UserService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 843b2b1..2a46829 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -46,7 +46,7 @@ public TokenResponseDto reissueToken(String refreshToken, Long userId) { String redisRefreshToken = redisTemplate.opsForValue().get(userId.toString()); - if(Objects.requireNonNull(redisRefreshToken).equals(refreshToken) && !redisRefreshToken.isEmpty()){ + if(!redisRefreshToken.isEmpty() && redisRefreshToken.equals(refreshToken)){ String userRole = userRepository.findUserRole(userId); From 1ef7e7aad3905d45c288b2e41e7bc8bbcd6f2be6 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sat, 28 Oct 2023 03:26:01 +0900 Subject: [PATCH 14/15] =?UTF-8?q?[fix]=20=ED=86=A0=ED=81=B0=20=EC=9E=AC?= =?UTF-8?q?=EB=B0=9C=EA=B8=89=20=EC=8B=9C=20=EB=A6=AC=ED=94=84=EB=A0=88?= =?UTF-8?q?=EC=8B=9C=20=ED=86=A0=ED=81=B0=20=EB=B9=88=20=EA=B0=92=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/farmususer/user/service/UserService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 2a46829..c26aef7 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -46,7 +46,7 @@ public TokenResponseDto reissueToken(String refreshToken, Long userId) { String redisRefreshToken = redisTemplate.opsForValue().get(userId.toString()); - if(!redisRefreshToken.isEmpty() && redisRefreshToken.equals(refreshToken)){ + if(refreshToken.equals(redisRefreshToken)){ String userRole = userRepository.findUserRole(userId); From 627687f34282066d12842fa6e98cb39f620d126b Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sat, 28 Oct 2023 11:13:44 +0900 Subject: [PATCH 15/15] =?UTF-8?q?[fix]=20=EC=9E=AC=EB=B0=9C=EA=B8=89=20api?= =?UTF-8?q?=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80=EC=82=AC=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=EC=B2=98=EB=A6=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/exception/CustomExceptionContext.java | 12 ++++-------- .../global/exception/GlobalExceptionHandler.java | 2 +- .../exception/notfound/NotFoundMemberException.java | 12 ------------ .../notfound/NotFoundRefreshTokenException.java | 10 ++++++++++ .../server/farmususer/user/service/UserService.java | 10 +++------- 5 files changed, 18 insertions(+), 28 deletions(-) delete mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMemberException.java create mode 100644 src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundRefreshTokenException.java diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/CustomExceptionContext.java b/src/main/java/modernfarmer/server/farmususer/global/exception/CustomExceptionContext.java index bf83931..bb79779 100644 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/CustomExceptionContext.java +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/CustomExceptionContext.java @@ -7,15 +7,11 @@ @Getter @RequiredArgsConstructor public enum CustomExceptionContext implements ExceptionContext{ - // MEMBER (예시) - NOT_FOUND_MEMBER_ERROR(HttpStatus.NOT_FOUND, 1000, "해당 회원을 찾을 수 없습니다."), - INVALID_MEMBER_ID_ERROR(HttpStatus.BAD_REQUEST, 1001, "회원에 대한 유효하지 않은 요청입니다."), - NOT_FOUND_ALARM_ERROR(HttpStatus.NOT_FOUND, 1002, "해당 알람 정보를 찾을 수 없습니다."), - INVALID_ADD_MEMBER(HttpStatus.BAD_REQUEST, 1003, "이미 존재하는 캐릭터입니다."), - SDK_NOT_FOUND(HttpStatus.BAD_REQUEST, 1007, "해당 경로에 Firebase SDK json 파일이 존재하지 않아, Firebase 시스템을 초기화 할 수 없습니다."), - FIREBASE_TOKEN_EXCEPTION(HttpStatus.BAD_REQUEST, 1004, "파이어베이스 토큰 오류입니다."), + + FIREBASE_CONFIG_EXCEPTION(HttpStatus.BAD_REQUEST, 1005, "파이어베이스 설정 오류입니다."), - NOT_FOUND_MEDICINE_ERROR(HttpStatus.NOT_FOUND, 1006, "해당 약 정보를 찾을 수 없습니다."); + NOT_FOUND_MEDICINE_ERROR(HttpStatus.NOT_FOUND, 1006, "해당 약 정보를 찾을 수 없습니다."), + REFRESH_TOKEN_DIFFERENT(HttpStatus.BAD_REQUEST , 1000,"접근이 올바르지 않습니다."); // DOMAIN PER EXCEPTIONS ... diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/GlobalExceptionHandler.java b/src/main/java/modernfarmer/server/farmususer/global/exception/GlobalExceptionHandler.java index 7f34258..17d97cc 100644 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/GlobalExceptionHandler.java +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/GlobalExceptionHandler.java @@ -38,6 +38,6 @@ public ResponseEntity unhandledException(Exception e, HttpServlet e.getMessage() ); return ResponseEntity.internalServerError() - .body(new ErrorResponse(7777, "서버와의 접속이 원활하지 않습니다.")); + .body(new ErrorResponse(500, "서버와의 접속이 원활하지 않습니다.")); } } diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMemberException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMemberException.java deleted file mode 100644 index 976fe3e..0000000 --- a/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundMemberException.java +++ /dev/null @@ -1,12 +0,0 @@ -package modernfarmer.server.farmususer.global.exception.notfound; - -import modernfarmer.server.farmususer.global.exception.ModernFarmerException; - -import static modernfarmer.server.farmususer.global.exception.CustomExceptionContext.NOT_FOUND_MEMBER_ERROR; - - -public class NotFoundMemberException extends NotFoundException { - public NotFoundMemberException() { - super(NOT_FOUND_MEMBER_ERROR); - } -} diff --git a/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundRefreshTokenException.java b/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundRefreshTokenException.java new file mode 100644 index 0000000..37e735c --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/global/exception/notfound/NotFoundRefreshTokenException.java @@ -0,0 +1,10 @@ +package modernfarmer.server.farmususer.global.exception.notfound; + +import static modernfarmer.server.farmususer.global.exception.CustomExceptionContext.REFRESH_TOKEN_DIFFERENT; + +public class NotFoundRefreshTokenException extends NotFoundException{ + + public NotFoundRefreshTokenException() { + super(REFRESH_TOKEN_DIFFERENT); + } +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index c26aef7..b3cc99f 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -1,5 +1,6 @@ package modernfarmer.server.farmususer.user.service; +import modernfarmer.server.farmususer.global.exception.notfound.NotFoundRefreshTokenException; import modernfarmer.server.farmususer.user.dto.response.ResponseDto; import modernfarmer.server.farmususer.user.dto.response.TokenResponseDto; import modernfarmer.server.farmususer.user.repository.UserRepository; @@ -60,14 +61,9 @@ public TokenResponseDto reissueToken(String refreshToken, Long userId) { return reissueTokenResponse; - } - - reissueTokenResponse = TokenResponseDto.builder() - .code(403) - .message("접근이 올바르지 않습니다.") - .build(); - return reissueTokenResponse; + } + throw new NotFoundRefreshTokenException(); }