From fa56664a783ea7708f957913d11e1dc370add57b Mon Sep 17 00:00:00 2001 From: Jinwoo Lee Date: Mon, 18 Sep 2023 10:07:55 +0900 Subject: [PATCH 1/4] feat: implement sign-out dto --- .../repl/gifthub/auth/dto/SignOutDto.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/main/java/org/swmaestro/repl/gifthub/auth/dto/SignOutDto.java diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/dto/SignOutDto.java b/src/main/java/org/swmaestro/repl/gifthub/auth/dto/SignOutDto.java new file mode 100644 index 00000000..cbe29814 --- /dev/null +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/dto/SignOutDto.java @@ -0,0 +1,17 @@ +package org.swmaestro.repl.gifthub.auth.dto; + +import com.fasterxml.jackson.databind.PropertyNamingStrategy; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Getter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) +public class SignOutDto { + private String deviceToken; +} From cf6df1efcab3bebbb9216bfda8c08da8ea62f9d5 Mon Sep 17 00:00:00 2001 From: Jinwoo Lee Date: Mon, 18 Sep 2023 10:14:15 +0900 Subject: [PATCH 2/4] test: modify sign-out test --- .../org/swmaestro/repl/gifthub/auth/dto/SignOutDto.java | 6 ++++++ .../repl/gifthub/auth/controller/AuthControllerTest.java | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/dto/SignOutDto.java b/src/main/java/org/swmaestro/repl/gifthub/auth/dto/SignOutDto.java index cbe29814..625e556a 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/dto/SignOutDto.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/dto/SignOutDto.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.annotation.JsonNaming; import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.ToString; @@ -14,4 +15,9 @@ @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) public class SignOutDto { private String deviceToken; + + @Builder + public SignOutDto(String deviceToken) { + this.deviceToken = deviceToken; + } } diff --git a/src/test/java/org/swmaestro/repl/gifthub/auth/controller/AuthControllerTest.java b/src/test/java/org/swmaestro/repl/gifthub/auth/controller/AuthControllerTest.java index ab52d0bd..0c754996 100644 --- a/src/test/java/org/swmaestro/repl/gifthub/auth/controller/AuthControllerTest.java +++ b/src/test/java/org/swmaestro/repl/gifthub/auth/controller/AuthControllerTest.java @@ -20,6 +20,7 @@ import org.swmaestro.repl.gifthub.auth.dto.KakaoDto; import org.swmaestro.repl.gifthub.auth.dto.NaverDto; import org.swmaestro.repl.gifthub.auth.dto.SignInDto; +import org.swmaestro.repl.gifthub.auth.dto.SignOutDto; import org.swmaestro.repl.gifthub.auth.dto.SignUpDto; import org.swmaestro.repl.gifthub.auth.dto.TokenDto; import org.swmaestro.repl.gifthub.auth.entity.Member; @@ -274,11 +275,17 @@ public void signOutTest() throws Exception { String username = "jinlee1703"; String accessToken = "my_awesome_access_token"; + SignOutDto signOutDto = SignOutDto.builder() + .deviceToken("my_awesome_device_token") + .build(); + when(jwtProvider.getUsername(accessToken)).thenReturn(username); when(jwtProvider.resolveToken(any())).thenReturn(accessToken); mockMvc.perform(post("/auth/sign-out") - .header("Authorization", "Bearer " + accessToken)) + .header("Authorization", "Bearer " + accessToken) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(signOutDto))) .andExpect(status().isOk()); } From 564ba9be9dd503234960c3751d2f4ba4f40eb377 Mon Sep 17 00:00:00 2001 From: Jinwoo Lee Date: Mon, 18 Sep 2023 10:15:15 +0900 Subject: [PATCH 3/4] fix: add device-token-deletion logic --- .../gifthub/auth/controller/AuthController.java | 13 ++++++------- .../repl/gifthub/auth/service/AuthService.java | 3 ++- .../repl/gifthub/auth/service/AuthServiceImpl.java | 5 ++++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/controller/AuthController.java b/src/main/java/org/swmaestro/repl/gifthub/auth/controller/AuthController.java index ff60340e..6089d93d 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/controller/AuthController.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/controller/AuthController.java @@ -18,6 +18,7 @@ import org.swmaestro.repl.gifthub.auth.dto.KakaoDto; import org.swmaestro.repl.gifthub.auth.dto.NaverDto; import org.swmaestro.repl.gifthub.auth.dto.SignInDto; +import org.swmaestro.repl.gifthub.auth.dto.SignOutDto; import org.swmaestro.repl.gifthub.auth.dto.SignUpDto; import org.swmaestro.repl.gifthub.auth.dto.TokenDto; import org.swmaestro.repl.gifthub.auth.entity.Member; @@ -259,17 +260,15 @@ public ResponseEntity appleCallback(@RequestBody String code) throws IO @ApiResponse(responseCode = "200", description = "로그인 성공"), @ApiResponse(responseCode = "400(401)", description = "존재하지 않는 사용자") }) - public ResponseEntity signOut(HttpServletRequest request) { + public ResponseEntity signOut(HttpServletRequest request, @RequestBody SignOutDto signOutDto) { String username = jwtProvider.getUsername(jwtProvider.resolveToken(request).substring(7)); - authService.signOut(username); - return new ResponseEntity( + System.out.println("성공?:" + signOutDto.getDeviceToken()); + authService.signOut(username, signOutDto); + return ResponseEntity.ok().body( Message.builder() .status(StatusEnum.OK) .message("로그아웃 성공!") .data(null) - .build(), - new HttpJsonHeaders(), - HttpStatus.OK - ); + .build()); } } diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/service/AuthService.java b/src/main/java/org/swmaestro/repl/gifthub/auth/service/AuthService.java index d54206a6..d4d6050a 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/service/AuthService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/service/AuthService.java @@ -1,11 +1,12 @@ package org.swmaestro.repl.gifthub.auth.service; import org.swmaestro.repl.gifthub.auth.dto.SignInDto; +import org.swmaestro.repl.gifthub.auth.dto.SignOutDto; import org.swmaestro.repl.gifthub.auth.dto.TokenDto; public interface AuthService { TokenDto signIn(SignInDto loginDto); - void signOut(String username); + void signOut(String username, SignOutDto signOutDto); } diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/service/AuthServiceImpl.java b/src/main/java/org/swmaestro/repl/gifthub/auth/service/AuthServiceImpl.java index 8d7bd662..595af097 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/service/AuthServiceImpl.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/service/AuthServiceImpl.java @@ -3,6 +3,7 @@ import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.swmaestro.repl.gifthub.auth.dto.SignInDto; +import org.swmaestro.repl.gifthub.auth.dto.SignOutDto; import org.swmaestro.repl.gifthub.auth.dto.TokenDto; import org.swmaestro.repl.gifthub.auth.entity.Member; import org.swmaestro.repl.gifthub.auth.repository.MemberRepository; @@ -21,6 +22,7 @@ public class AuthServiceImpl implements AuthService { private final JwtProvider jwtProvider; private final RefreshTokenService refreshTokenService; private final NaverService naverService; + private final DeviceTokenService deviceTokenService; public TokenDto signIn(SignInDto loginDto) { Member member = memberRepository.findByUsername(loginDto.getUsername()); @@ -44,11 +46,12 @@ public TokenDto signIn(SignInDto loginDto) { } @Transactional - public void signOut(String username) { + public void signOut(String username, SignOutDto signOutDto) { Member member = memberRepository.findByUsername(username); if (member == null) { throw new BusinessException("존재하지 않는 사용자입니다.", StatusEnum.UNAUTHORIZED); } refreshTokenService.deleteRefreshToken(username); + deviceTokenService.delete(signOutDto.getDeviceToken()); } } From 643e890dcad983c5cb3e1346d0b7289df4f8a473 Mon Sep 17 00:00:00 2001 From: Jinwoo Lee Date: Mon, 18 Sep 2023 16:17:51 +0900 Subject: [PATCH 4/4] fix: remove log --- .../swmaestro/repl/gifthub/auth/controller/AuthController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/controller/AuthController.java b/src/main/java/org/swmaestro/repl/gifthub/auth/controller/AuthController.java index 6089d93d..0537e65e 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/controller/AuthController.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/controller/AuthController.java @@ -262,7 +262,6 @@ public ResponseEntity appleCallback(@RequestBody String code) throws IO }) public ResponseEntity signOut(HttpServletRequest request, @RequestBody SignOutDto signOutDto) { String username = jwtProvider.getUsername(jwtProvider.resolveToken(request).substring(7)); - System.out.println("성공?:" + signOutDto.getDeviceToken()); authService.signOut(username, signOutDto); return ResponseEntity.ok().body( Message.builder()