From 2cd8cea879256f7adf544c399dad28a4542f15ef Mon Sep 17 00:00:00 2001 From: ta2ye0n Date: Wed, 20 Nov 2024 14:48:12 +0900 Subject: [PATCH 1/7] add :: deleteByUser --- .../v3/domain/user/domain/repository/UserRoleRepository.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/gcms/v3/domain/user/domain/repository/UserRoleRepository.java b/src/main/java/com/gcms/v3/domain/user/domain/repository/UserRoleRepository.java index cf16d5e..1b45bab 100644 --- a/src/main/java/com/gcms/v3/domain/user/domain/repository/UserRoleRepository.java +++ b/src/main/java/com/gcms/v3/domain/user/domain/repository/UserRoleRepository.java @@ -8,4 +8,6 @@ public interface UserRoleRepository extends JpaRepository { List findByUser(User user); + + void deleteByUser(User user); } From e952137e1667bd5713f5ee1e1cbce79a84504105 Mon Sep 17 00:00:00 2001 From: ta2ye0n Date: Wed, 20 Nov 2024 14:48:33 +0900 Subject: [PATCH 2/7] =?UTF-8?q?refactor=20::=20transactional=20=EC=96=B4?= =?UTF-8?q?=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/gcms/v3/domain/auth/service/impl/SignInServiceImpl.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/gcms/v3/domain/auth/service/impl/SignInServiceImpl.java b/src/main/java/com/gcms/v3/domain/auth/service/impl/SignInServiceImpl.java index b350f99..842e04f 100644 --- a/src/main/java/com/gcms/v3/domain/auth/service/impl/SignInServiceImpl.java +++ b/src/main/java/com/gcms/v3/domain/auth/service/impl/SignInServiceImpl.java @@ -18,7 +18,6 @@ import org.springframework.stereotype.Service; @Service -@Transactional(rollbackOn = Exception.class) @RequiredArgsConstructor public class SignInServiceImpl implements SignInService { From 94b6109212528e0f42c58bb4bbb24226dedb73f5 Mon Sep 17 00:00:00 2001 From: ta2ye0n Date: Wed, 20 Nov 2024 14:48:50 +0900 Subject: [PATCH 3/7] add :: CancelMembershipService --- .../auth/service/CancelMembershipService.java | 5 ++++ .../impl/CancelMembershipServiceImpl.java | 27 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/main/java/com/gcms/v3/domain/auth/service/CancelMembershipService.java create mode 100644 src/main/java/com/gcms/v3/domain/auth/service/impl/CancelMembershipServiceImpl.java diff --git a/src/main/java/com/gcms/v3/domain/auth/service/CancelMembershipService.java b/src/main/java/com/gcms/v3/domain/auth/service/CancelMembershipService.java new file mode 100644 index 0000000..3378bcd --- /dev/null +++ b/src/main/java/com/gcms/v3/domain/auth/service/CancelMembershipService.java @@ -0,0 +1,5 @@ +package com.gcms.v3.domain.auth.service; + +public interface CancelMembershipService { + void execute(); +} diff --git a/src/main/java/com/gcms/v3/domain/auth/service/impl/CancelMembershipServiceImpl.java b/src/main/java/com/gcms/v3/domain/auth/service/impl/CancelMembershipServiceImpl.java new file mode 100644 index 0000000..17d63a3 --- /dev/null +++ b/src/main/java/com/gcms/v3/domain/auth/service/impl/CancelMembershipServiceImpl.java @@ -0,0 +1,27 @@ +package com.gcms.v3.domain.auth.service.impl; + +import com.gcms.v3.domain.auth.service.CancelMembershipService; +import com.gcms.v3.domain.user.domain.entity.User; +import com.gcms.v3.domain.user.domain.repository.UserRepository; +import com.gcms.v3.domain.user.domain.repository.UserRoleRepository; +import com.gcms.v3.domain.user.util.UserUtil; +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +@Transactional +public class CancelMembershipServiceImpl implements CancelMembershipService { + + private final UserUtil userUtil; + private final UserRepository userRepository; + private final UserRoleRepository userRoleRepository; + + public void execute() { + User user = userUtil.getCurrentUser(); + + userRoleRepository.deleteByUser(user); + userRepository.deleteById(user.getId()); + } +} From 2d81f15a74bb2db00091b55cc892e508a7487a44 Mon Sep 17 00:00:00 2001 From: ta2ye0n Date: Wed, 20 Nov 2024 14:49:00 +0900 Subject: [PATCH 4/7] add :: endpoint --- .../v3/domain/auth/presentation/AuthController.java | 12 ++++++++++-- .../v3/global/security/config/SecurityConfig.java | 7 ++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/gcms/v3/domain/auth/presentation/AuthController.java b/src/main/java/com/gcms/v3/domain/auth/presentation/AuthController.java index 1bcd88d..ce5359e 100644 --- a/src/main/java/com/gcms/v3/domain/auth/presentation/AuthController.java +++ b/src/main/java/com/gcms/v3/domain/auth/presentation/AuthController.java @@ -2,6 +2,7 @@ import com.gcms.v3.domain.auth.presentation.data.request.SignInRequestDto; import com.gcms.v3.domain.auth.presentation.data.response.TokenInfoResponseDto; +import com.gcms.v3.domain.auth.service.CancelMembershipService; import com.gcms.v3.domain.auth.service.LogoutService; import com.gcms.v3.domain.auth.service.ReissueTokenService; import com.gcms.v3.domain.auth.service.SignInService; @@ -12,12 +13,13 @@ @RequiredArgsConstructor @RestController -@RequestMapping("/v3/auth") +@RequestMapping("/auth") public class AuthController { private final SignInService signInService; private final ReissueTokenService reissueTokenService; private final LogoutService logoutService; + private final CancelMembershipService cancelMembershipService; @PostMapping public ResponseEntity signIn (@RequestBody SignInRequestDto signInRequestDto) { @@ -32,8 +34,14 @@ public ResponseEntity reissueToken (@RequestBody String re } @DeleteMapping("/logout") - public ResponseEntity logout(HttpServletRequest request) { + public ResponseEntity logout (HttpServletRequest request) { logoutService.execute(request); return ResponseEntity.noContent().build(); } + + @DeleteMapping + public ResponseEntity cancelMembership () { + cancelMembershipService.execute(); + return ResponseEntity.noContent().build(); + } } diff --git a/src/main/java/com/gcms/v3/global/security/config/SecurityConfig.java b/src/main/java/com/gcms/v3/global/security/config/SecurityConfig.java index 21ef9a4..33e1487 100644 --- a/src/main/java/com/gcms/v3/global/security/config/SecurityConfig.java +++ b/src/main/java/com/gcms/v3/global/security/config/SecurityConfig.java @@ -42,9 +42,10 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti .authorizeHttpRequests((authorizeRequests) -> authorizeRequests - .requestMatchers(HttpMethod.POST, "/v3/auth").permitAll() - .requestMatchers(HttpMethod.POST, "/v3/auth/reissueToken").authenticated() - .requestMatchers(HttpMethod.DELETE, "/v3/auth/logout").authenticated() + .requestMatchers(HttpMethod.POST, "/auth").permitAll() + .requestMatchers(HttpMethod.POST, "/auth/reissueToken").authenticated() + .requestMatchers(HttpMethod.DELETE, "/auth/logout").authenticated() + .requestMatchers(HttpMethod.DELETE, "/auth").authenticated() ) .addFilterBefore(new ExceptionFilter(objectMapper), UsernamePasswordAuthenticationFilter.class) From 4a8bed059cc9484226972d0275e6947638d5cb40 Mon Sep 17 00:00:00 2001 From: ta2ye0n Date: Wed, 20 Nov 2024 21:03:06 +0900 Subject: [PATCH 5/7] =?UTF-8?q?refactor=20::=20@Id=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/gcms/v3/domain/auth/domain/entity/RefreshToken.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gcms/v3/domain/auth/domain/entity/RefreshToken.java b/src/main/java/com/gcms/v3/domain/auth/domain/entity/RefreshToken.java index beba913..abf97a0 100644 --- a/src/main/java/com/gcms/v3/domain/auth/domain/entity/RefreshToken.java +++ b/src/main/java/com/gcms/v3/domain/auth/domain/entity/RefreshToken.java @@ -11,10 +11,10 @@ @RedisHash(value = "refreshToken", timeToLive = 60L * 60 * 24 * 7) public class RefreshToken { + @Id @Indexed private String email; - @Id @Indexed private String token; } From 51be8add9a1a1836ec2a123e9b7c8b3278446be1 Mon Sep 17 00:00:00 2001 From: ta2ye0n Date: Wed, 20 Nov 2024 21:03:18 +0900 Subject: [PATCH 6/7] =?UTF-8?q?update=20::=20refreshToken=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/auth/service/impl/CancelMembershipServiceImpl.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/gcms/v3/domain/auth/service/impl/CancelMembershipServiceImpl.java b/src/main/java/com/gcms/v3/domain/auth/service/impl/CancelMembershipServiceImpl.java index 17d63a3..1a2c32a 100644 --- a/src/main/java/com/gcms/v3/domain/auth/service/impl/CancelMembershipServiceImpl.java +++ b/src/main/java/com/gcms/v3/domain/auth/service/impl/CancelMembershipServiceImpl.java @@ -1,5 +1,6 @@ package com.gcms.v3.domain.auth.service.impl; +import com.gcms.v3.domain.auth.domain.repository.RefreshTokenRepository; import com.gcms.v3.domain.auth.service.CancelMembershipService; import com.gcms.v3.domain.user.domain.entity.User; import com.gcms.v3.domain.user.domain.repository.UserRepository; @@ -17,10 +18,13 @@ public class CancelMembershipServiceImpl implements CancelMembershipService { private final UserUtil userUtil; private final UserRepository userRepository; private final UserRoleRepository userRoleRepository; + private final RefreshTokenRepository refreshTokenRepository; public void execute() { User user = userUtil.getCurrentUser(); + refreshTokenRepository.deleteById(user.getEmail()); + userRoleRepository.deleteByUser(user); userRepository.deleteById(user.getId()); } From d96c313c7d438f515d598e9af49a76dbabdd7959 Mon Sep 17 00:00:00 2001 From: ta2ye0n Date: Fri, 22 Nov 2024 14:31:00 +0900 Subject: [PATCH 7/7] refactor :: authenticated() -> permitAll() --- .../java/com/gcms/v3/global/security/config/SecurityConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gcms/v3/global/security/config/SecurityConfig.java b/src/main/java/com/gcms/v3/global/security/config/SecurityConfig.java index 33e1487..c1ee41e 100644 --- a/src/main/java/com/gcms/v3/global/security/config/SecurityConfig.java +++ b/src/main/java/com/gcms/v3/global/security/config/SecurityConfig.java @@ -43,7 +43,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti .authorizeHttpRequests((authorizeRequests) -> authorizeRequests .requestMatchers(HttpMethod.POST, "/auth").permitAll() - .requestMatchers(HttpMethod.POST, "/auth/reissueToken").authenticated() + .requestMatchers(HttpMethod.POST, "/auth/reissueToken").permitAll() .requestMatchers(HttpMethod.DELETE, "/auth/logout").authenticated() .requestMatchers(HttpMethod.DELETE, "/auth").authenticated() )