From 8861dd0aa42fb73aea0807357dc94fbdc566fbf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=95=9C=EA=B4=80=ED=9D=AC?= Date: Mon, 23 Sep 2024 11:50:29 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EC=8B=A4=ED=8C=A8=EC=8B=9C=20401=20=EC=83=81=ED=83=9C=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=EB=A5=BC=20=EB=B0=98=ED=99=98=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/stempo/api/global/handler/GlobalExceptionHandler.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/stempo/api/global/handler/GlobalExceptionHandler.java b/src/main/java/com/stempo/api/global/handler/GlobalExceptionHandler.java index 37ced90..de4b9ac 100644 --- a/src/main/java/com/stempo/api/global/handler/GlobalExceptionHandler.java +++ b/src/main/java/com/stempo/api/global/handler/GlobalExceptionHandler.java @@ -30,6 +30,7 @@ import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.security.access.AccessDeniedException; import org.springframework.security.authentication.BadCredentialsException; +import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.transaction.TransactionSystemException; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.MissingServletRequestParameterException; @@ -76,6 +77,7 @@ public ErrorResponse badRequestException(HttpServletResponse response MalformedJwtException.class, ExpiredJwtException.class, UnsupportedJwtException.class, + UsernameNotFoundException.class }) public ApiResponse unAuthorizeException(HttpServletResponse response, Exception e) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); From 0bb1a1e734d7638e3e6654a88b69a2f76de745a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=95=9C=EA=B4=80=ED=9D=AC?= Date: Mon, 23 Sep 2024 11:54:03 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor(Auth):=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20=EC=99=84=EB=A3=8C=20=EC=8B=9C=20=ED=86=A0?= =?UTF-8?q?=ED=81=B0=EC=9D=84=20=EC=9D=91=EB=8B=B5=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stempo/api/domain/application/service/AuthService.java | 2 +- .../api/domain/application/service/AuthServiceImpl.java | 5 +++-- .../com/stempo/api/domain/presentation/AuthController.java | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/stempo/api/domain/application/service/AuthService.java b/src/main/java/com/stempo/api/domain/application/service/AuthService.java index 47583d6..b02ea11 100644 --- a/src/main/java/com/stempo/api/domain/application/service/AuthService.java +++ b/src/main/java/com/stempo/api/domain/application/service/AuthService.java @@ -6,7 +6,7 @@ public interface AuthService { - String registerUser(AuthRequestDto requestDto); + TokenInfo registerUser(AuthRequestDto requestDto); TokenInfo login(AuthRequestDto requestDto); diff --git a/src/main/java/com/stempo/api/domain/application/service/AuthServiceImpl.java b/src/main/java/com/stempo/api/domain/application/service/AuthServiceImpl.java index de20ea3..ff2d49a 100644 --- a/src/main/java/com/stempo/api/domain/application/service/AuthServiceImpl.java +++ b/src/main/java/com/stempo/api/domain/application/service/AuthServiceImpl.java @@ -27,7 +27,7 @@ public class AuthServiceImpl implements AuthService { private final PasswordEncoder passwordEncoder; @Override - public String registerUser(AuthRequestDto requestDto) { + public TokenInfo registerUser(AuthRequestDto requestDto) { String deviceTag = requestDto.getDeviceTag(); String password = requestDto.getPassword(); @@ -37,7 +37,8 @@ public String registerUser(AuthRequestDto requestDto) { String finalPassword = StringUtils.isEmpty(password) ? null : passwordEncoder.encode(password); User user = User.create(deviceTag, finalPassword); - return userService.save(user).getDeviceTag(); + userService.save(user); + return jwtTokenProvider.generateToken(user.getDeviceTag(), user.getRole()); } @Override diff --git a/src/main/java/com/stempo/api/domain/presentation/AuthController.java b/src/main/java/com/stempo/api/domain/presentation/AuthController.java index 86b217d..12a6b4b 100644 --- a/src/main/java/com/stempo/api/domain/presentation/AuthController.java +++ b/src/main/java/com/stempo/api/domain/presentation/AuthController.java @@ -23,11 +23,11 @@ public class AuthController { @Operation(summary = "회원 가입", description = "ROLE_ANONYMOUS 이상의 권한이 필요함") @PostMapping("/api/v1/auth/register") - public ApiResponse registerUser( + public ApiResponse registerUser( @Valid @RequestBody AuthRequestDto requestDto ) { - String deviceTag = authService.registerUser(requestDto); - return ApiResponse.success(deviceTag); + TokenInfo token = authService.registerUser(requestDto); + return ApiResponse.success(token); } @Operation(summary = "로그인", description = "ROLE_ANONYMOUS 이상의 권한이 필요함
" +