diff --git a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/UserInitializer.java b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/UserInitializer.java index a9f6f77b..34f90d2a 100644 --- a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/UserInitializer.java +++ b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/UserInitializer.java @@ -4,6 +4,7 @@ import me.nalab.core.data.user.UserOAuthInfoEntity; import me.nalab.core.idgenerator.idcore.IdGenerator; import me.nalab.user.domain.user.Provider; +import me.nalab.user.domain.user.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @@ -22,7 +23,7 @@ public class UserInitializer { private IdGenerator idGenerator; @Transactional - public void saveUserWithOAuth(Provider provider, String name, String email, Instant date) { + public Long saveUserWithOAuth(Provider provider, String name, String email, Instant date) { var userEntity = UserEntity.builder() .id(idGenerator.generate()) .nickname(name) @@ -42,6 +43,7 @@ public void saveUserWithOAuth(Provider provider, String name, String email, Inst entityManager.persist(userEntity); entityManager.persist(userOauthInfoEntity); + return userEntity.getId(); } } diff --git a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/bookmark/BookmarkReplaceAcceptanceTest.java b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/bookmark/BookmarkReplaceAcceptanceTest.java index 9e9884a9..bd411975 100644 --- a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/bookmark/BookmarkReplaceAcceptanceTest.java +++ b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/bookmark/BookmarkReplaceAcceptanceTest.java @@ -58,7 +58,7 @@ void REPLACE_BOOKMARK_SUCCESS_TEST() throws Exception { // given Long targetId = targetInitializer.saveTargetAndGetId("target", Instant.now()); - String token = "token"; + String token = "bearer token"; applicationEventPublisher.publishEvent(MockUserRegisterEvent.builder() .expectedId(targetId) .expectedToken(token) diff --git a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/create/FeedbackCreateAcceptanceTest.java b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/create/FeedbackCreateAcceptanceTest.java index 388bcaea..25dec6ba 100644 --- a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/create/FeedbackCreateAcceptanceTest.java +++ b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/create/FeedbackCreateAcceptanceTest.java @@ -66,7 +66,7 @@ class FeedbackCreateAcceptanceTest extends AbstractFeedbackTestSupporter { void CREATE_FEEDBACK_TO_SURVEY_SUCCESS() throws Exception { // given Long targetId = targetInitializer.saveTargetAndGetId("nalab", Instant.now()); - String token = "nalab-token"; + String token = "bearer nalab-token"; applicationEventPublisher.publishEvent(MockUserRegisterEvent.builder() .expectedToken(token) .expectedId(targetId) @@ -88,7 +88,7 @@ void CREATE_FEEDBACK_TO_SURVEY_SUCCESS() throws Exception { void CREATE_MULTIPLE_FEEDBACK_TO_SURVEY_SUCCESS() throws Exception { // given Long targetId = targetInitializer.saveTargetAndGetId("hello", Instant.now()); - String token = "hello-token"; + String token = "bearer hello-token"; applicationEventPublisher.publishEvent(MockUserRegisterEvent.builder() .expectedToken(token) .expectedId(targetId) diff --git a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/find/FeedbackFindAcceptanceTest.java b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/find/FeedbackFindAcceptanceTest.java index b8de5cce..e988ff77 100644 --- a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/find/FeedbackFindAcceptanceTest.java +++ b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/find/FeedbackFindAcceptanceTest.java @@ -55,7 +55,7 @@ class FeedbackFindAcceptanceTest extends AbstractFeedbackTestSupporter { void FIND_FEED_BACK_SUCCESS() throws Exception { // given Long targetId = targetInitializer.saveTargetAndGetId("hello world", Instant.now()); - String token = "mock token"; + String token = "bearer token"; applicationEventPublisher.publishEvent(MockUserRegisterEvent.builder() .expectedId(targetId) .expectedToken(token) @@ -79,7 +79,7 @@ void FIND_FEED_BACK_SUCCESS() throws Exception { void FIND_FEED_BACK_SUCCESS_ANY_FEEDBACK() throws Exception { // given Long targetId = targetInitializer.saveTargetAndGetId("hello world", Instant.now()); - String token = "mock token"; + String token = "bearer token"; applicationEventPublisher.publishEvent(MockUserRegisterEvent.builder() .expectedId(targetId) .expectedToken(token) @@ -112,7 +112,7 @@ void FIND_BOOKMARKED_FEED_BACK_SUCCESS() throws Exception { void FIND_BOOKMARKED_FEED_BACK_SUCCESS_ANY_FEEDBACK() throws Exception { // given Long targetId = targetInitializer.saveTargetAndGetId("hello world", Instant.now()); - String token = "mock token"; + String token = "bearer token"; applicationEventPublisher.publishEvent(MockUserRegisterEvent.builder() .expectedId(targetId) .expectedToken(token) @@ -130,7 +130,7 @@ void FIND_BOOKMARKED_FEED_BACK_SUCCESS_ANY_FEEDBACK() throws Exception { private Long setUpSurveyAndFeedbackAndBookmark() throws Exception { // 유저 생성 Long targetId = targetInitializer.saveTargetAndGetId("hello world", Instant.now()); - String token = "mock token"; + String token = "bearer token"; applicationEventPublisher.publishEvent(MockUserRegisterEvent.builder() .expectedId(targetId) .expectedToken(token) diff --git a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/find/FeedbackFindByTypeAcceptanceTest.java b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/find/FeedbackFindByTypeAcceptanceTest.java index 289c8dc5..15ed73f8 100644 --- a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/find/FeedbackFindByTypeAcceptanceTest.java +++ b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/find/FeedbackFindByTypeAcceptanceTest.java @@ -63,7 +63,7 @@ class FeedbackFindByTypeAcceptanceTest extends AbstractFeedbackTestSupporter { void FIND_FEEDBACK_BY_FORM_TYPE_TENDENCY() throws Exception { // given Long targetId = targetInitializer.saveTargetAndGetId("hello world", Instant.now()); - String token = "mock token"; + String token = "bearer token"; applicationEventPublisher.publishEvent(MockUserRegisterEvent.builder() .expectedId(targetId) .expectedToken(token) @@ -86,7 +86,7 @@ void FIND_FEEDBACK_BY_FORM_TYPE_TENDENCY() throws Exception { void FIND_FEEDBACK_BY_FORM_TYPE_CUSTOM() throws Exception { // given Long targetId = targetInitializer.saveTargetAndGetId("hello world", Instant.now()); - String token = "mock token"; + String token = "bearer token"; applicationEventPublisher.publishEvent(MockUserRegisterEvent.builder() .expectedId(targetId) .expectedToken(token) @@ -109,7 +109,7 @@ void FIND_FEEDBACK_BY_FORM_TYPE_CUSTOM() throws Exception { void FIND_FEEDBACK_BY_TYPE_TENDENCY_WITH_NO_FEEDBACK() throws Exception { // given Long targetId = targetInitializer.saveTargetAndGetId("hello world", Instant.now()); - String token = "mock token"; + String token = "bearer token"; applicationEventPublisher.publishEvent(MockUserRegisterEvent.builder() .expectedId(targetId) .expectedToken(token) @@ -129,7 +129,7 @@ void FIND_FEEDBACK_BY_TYPE_TENDENCY_WITH_NO_FEEDBACK() throws Exception { void FIND_FEEDBACK_BY_TYPE_CUSTOM_WITH_NO_FEEDBACK() throws Exception { // given Long targetId = targetInitializer.saveTargetAndGetId("hello world", Instant.now()); - String token = "mock token"; + String token = "bearer token"; applicationEventPublisher.publishEvent(MockUserRegisterEvent.builder() .expectedId(targetId) .expectedToken(token) diff --git a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/findreviewers/ReviewersFindAcceptanceTest.java b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/findreviewers/ReviewersFindAcceptanceTest.java index bd03a053..435c5a88 100644 --- a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/findreviewers/ReviewersFindAcceptanceTest.java +++ b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/findreviewers/ReviewersFindAcceptanceTest.java @@ -64,7 +64,7 @@ class ReviewersFindAcceptanceTest extends AbstractFeedbackTestSupporter { void FEEDBACKS_WITH_NO_REVIEWER_TEST() throws Exception { // given - String token = "token"; + String token = "bearer token"; Long targetId = targetInitializer.saveTargetAndGetId("sujin", Instant.now()); applicationEventPublisher.publishEvent( MockUserRegisterEvent.builder().expectedToken(token).expectedId(targetId).build()); @@ -84,7 +84,7 @@ void FEEDBACKS_WITH_NO_REVIEWER_TEST() throws Exception { void FEEDBACKS_WITH_REVIEWERS_TEST() throws Exception { // given - String token = "token"; + String token = "bearer token"; Long targetId = targetInitializer.saveTargetAndGetId("sujin", Instant.now()); applicationEventPublisher.publishEvent( MockUserRegisterEvent.builder().expectedToken(token).expectedId(targetId).build()); diff --git a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/findspecific/SpecificFindAcceptanceTest.java b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/findspecific/SpecificFindAcceptanceTest.java index bdead954..f2283d97 100644 --- a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/findspecific/SpecificFindAcceptanceTest.java +++ b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/findspecific/SpecificFindAcceptanceTest.java @@ -63,7 +63,7 @@ public class SpecificFindAcceptanceTest extends AbstractFeedbackTestSupporter { void FIND_SPECIFIC_FEEDBACK_SUCCESS_TEST() throws Exception { // given - String token = "token"; + String token = "bearer token"; Long targetId = targetInitializer.saveTargetAndGetId("sujin", Instant.now()); applicationEventPublisher.publishEvent( MockUserRegisterEvent.builder().expectedToken(token).expectedId(targetId).build()); diff --git a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/findsummary/FeedbackFindSummaryAcceptanceTest.java b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/findsummary/FeedbackFindSummaryAcceptanceTest.java index c97373a3..d04fcf9f 100644 --- a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/findsummary/FeedbackFindSummaryAcceptanceTest.java +++ b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/findsummary/FeedbackFindSummaryAcceptanceTest.java @@ -63,7 +63,7 @@ class FeedbackFindSummaryAcceptanceTest extends AbstractFeedbackTestSupporter { void FEEFBACK_SUMMARY_FIND_SUCCESS_TEST_WITH_NO_FEEDBACK() throws Exception { // given - String token = "token"; + String token = "bearer token"; Long targetId = targetInitializer.saveTargetAndGetId("sujin", Instant.now()); applicationEventPublisher.publishEvent( MockUserRegisterEvent.builder().expectedToken(token).expectedId(targetId).build()); @@ -81,7 +81,7 @@ void FEEFBACK_SUMMARY_FIND_SUCCESS_TEST_WITH_NO_FEEDBACK() throws Exception { void FEEFBACK_SUMMARY_FIND_SUCCESS_TEST_WITH_FEEDBACK() throws Exception { // given - String token = "token"; + String token = "bearer token"; Long targetId = targetInitializer.saveTargetAndGetId("sujin", Instant.now()); applicationEventPublisher.publishEvent( MockUserRegisterEvent.builder().expectedToken(token).expectedId(targetId).build()); diff --git a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/reviewer/summary/ReviewerSummarizeAcceptanceTest.java b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/reviewer/summary/ReviewerSummarizeAcceptanceTest.java index f3104ad8..c1272b3e 100644 --- a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/reviewer/summary/ReviewerSummarizeAcceptanceTest.java +++ b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/feedback/reviewer/summary/ReviewerSummarizeAcceptanceTest.java @@ -97,7 +97,7 @@ void FIND_REVIEWER_SUMMARY_SUCCESS() throws Exception { private String saveTargetAndGetToken(String name) { Long targetId = targetInitializer.saveTargetAndGetId("nalab", Instant.now()); - String token = "nalab-token"; + String token = "bearer nalab-token"; applicationEventPublisher.publishEvent(MockUserRegisterEvent.builder() .expectedToken(token) .expectedId(targetId) diff --git a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/survey/bookmark/SurveyBookmarkAcceptanceTest.java b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/survey/bookmark/SurveyBookmarkAcceptanceTest.java index 8427c25e..c5d6618e 100644 --- a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/survey/bookmark/SurveyBookmarkAcceptanceTest.java +++ b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/survey/bookmark/SurveyBookmarkAcceptanceTest.java @@ -43,7 +43,7 @@ void BOOKMARK_SURVEY_TO_TOKEN_OWNER() throws Exception { // given var targetId = targetInitializer.saveTargetAndGetId("luffy", LocalDateTime.now().minusYears(24).toInstant(ZoneOffset.UTC)); - var token = "luffy's-double-token"; + var token = "bearer luffy's-double-token"; applicationEventPublisher.publishEvent(MockUserRegisterEvent.builder() .expectedToken(token) .expectedId(targetId) diff --git a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/survey/create/SurveyCreateAcceptanceTest.java b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/survey/create/SurveyCreateAcceptanceTest.java index 31d125e6..5e180acb 100644 --- a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/survey/create/SurveyCreateAcceptanceTest.java +++ b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/survey/create/SurveyCreateAcceptanceTest.java @@ -49,7 +49,7 @@ void CREATE_NEW_SURVEY_SUCCESS_DEFAULT() throws Exception { // given Long targetId = targetInitializer.saveTargetAndGetId("luffy", LocalDateTime.now().minusYears(24).toInstant(ZoneOffset.UTC)); - String token = "luffy's-double-token"; + String token = "bearer luffy's-double-token"; applicationEventPublisher.publishEvent(MockUserRegisterEvent.builder() .expectedToken(token) .expectedId(targetId) @@ -68,7 +68,7 @@ void CREATE_NEW_SURVEY_SUCCESS_SUCCESS_CUSTOM() throws Exception { // given Long targetId = targetInitializer.saveTargetAndGetId("luffy", LocalDateTime.now().minusYears(24).toInstant(ZoneOffset.UTC)); - String token = "luffy's-double-token"; + String token = "bearer luffy's-double-token"; applicationEventPublisher.publishEvent(MockUserRegisterEvent.builder() .expectedToken(token) .expectedId(targetId) @@ -86,7 +86,7 @@ void CREATE_NEW_SURVEY_SUCCESS_SUCCESS_CUSTOM() throws Exception { void CREATE_NEW_SURVEY_WITH_FAIL() throws Exception { // given Long targetId = targetInitializer.saveTargetAndGetId("luffy", LocalDateTime.now().minusYears(24).toInstant(ZoneOffset.UTC)); - String token = "luffy's-double-token"; + String token = "bearer luffy's-double-token"; applicationEventPublisher.publishEvent(MockUserRegisterEvent.builder() .expectedToken(token) .expectedId(targetId) diff --git a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/survey/exists/SurveyExistsAcceptanceTest.java b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/survey/exists/SurveyExistsAcceptanceTest.java index c1d8a166..d756f1e5 100644 --- a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/survey/exists/SurveyExistsAcceptanceTest.java +++ b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/survey/exists/SurveyExistsAcceptanceTest.java @@ -38,7 +38,7 @@ class SurveyExistsAcceptanceTest extends AbstractSurveyTestSupporter { @DisplayName("token에 해당하는 survey가 존재한다면, true를 반환한다.") void RETURN_TRUE_IF_SURVEY_EXISTS() throws Exception { // given - String token = "luffy's-double-token"; + String token = "bearer luffy's-double-token"; Long targetId = targetInitializer.saveTargetAndGetId("devxb", Instant.now()); applicationEventPublisher.publishEvent(MockUserRegisterEvent.builder() .expectedToken(token) @@ -59,7 +59,7 @@ void RETURN_TRUE_IF_SURVEY_EXISTS() throws Exception { @DisplayName("token에 해당하는 survey가 존재하지 않는다면, false를 반환한다.") void RETURN_FALSE_IF_SURVEY_DOES_NOT_EXISTS() throws Exception { // given - String token = "luffy's-double-token"; + String token = "bearer luffy's-double-token"; Long targetId = targetInitializer.saveTargetAndGetId("devxb", Instant.now()); applicationEventPublisher.publishEvent(MockUserRegisterEvent.builder() .expectedToken(token) diff --git a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/survey/find/SurveyFindAcceptanceTest.java b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/survey/find/SurveyFindAcceptanceTest.java index df517a63..3cc5ba9a 100644 --- a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/survey/find/SurveyFindAcceptanceTest.java +++ b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/survey/find/SurveyFindAcceptanceTest.java @@ -38,7 +38,7 @@ class SurveyFindAcceptanceTest extends AbstractSurveyTestSupporter { @Test void SURVEY_FIND_SUCCESS_TEST() throws Exception { - String token = "luffy's-double-token"; + String token = "bearer luffy's-double-token"; Long targetId = targetInitializer.saveTargetAndGetId("sujin", Instant.now()); applicationEventPublisher.publishEvent( MockUserRegisterEvent.builder().expectedToken(token).expectedId(targetId).build()); diff --git a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/survey/findid/SurveyFindidAcceptanceTest.java b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/survey/findid/SurveyFindidAcceptanceTest.java index ea6f1fa3..59d56a91 100644 --- a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/survey/findid/SurveyFindidAcceptanceTest.java +++ b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/survey/findid/SurveyFindidAcceptanceTest.java @@ -41,7 +41,7 @@ class SurveyFindidAcceptanceTest extends AbstractSurveyTestSupporter { void GET_LOGINED_SURVEY_ID_SUCCESS() throws Exception { // given Long targetId = targetInitializer.saveTargetAndGetId("nalab", Instant.now()); - String token = "nalab-token"; + String token = "bearer nalab-token"; applicationEventPublisher.publishEvent(MockUserRegisterEvent.builder() .expectedToken(token) .expectedId(targetId) @@ -60,7 +60,7 @@ void GET_LOGINED_SURVEY_ID_SUCCESS() throws Exception { void GET_LOGINED_SURVEY_ID_FAIL_NO_SURVEY() throws Exception { // given Long targetId = targetInitializer.saveTargetAndGetId("nalab", Instant.now()); - String token = "nalab-token"; + String token = "bearer nalab-token"; applicationEventPublisher.publishEvent(MockUserRegisterEvent.builder() .expectedToken(token) .expectedId(targetId) diff --git a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/survey/findtarget/TargetFindAcceptanceTest.java b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/survey/findtarget/TargetFindAcceptanceTest.java index 3f16bfaa..4aaaecd9 100644 --- a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/survey/findtarget/TargetFindAcceptanceTest.java +++ b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/survey/findtarget/TargetFindAcceptanceTest.java @@ -59,7 +59,7 @@ class TargetFindAcceptanceTest extends AbstractSurveyTestSupporter { void FIND_TARGET_BY_SURVEY_ID_WITH_NO_AUTHORIZATION() throws Exception { // given Long targetId = targetInitializer.saveTargetAndGetId("target", Instant.now()); - String token = "token"; + String token = "bearer token"; applicationEventPublisher.publishEvent(MockUserRegisterEvent.builder() .expectedToken(token) .expectedId(targetId) diff --git a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/UserAcceptanceTestSupporter.java b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/UserAcceptanceTestSupporter.java index cf415cb7..86cf4bf6 100644 --- a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/UserAcceptanceTestSupporter.java +++ b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/UserAcceptanceTestSupporter.java @@ -17,7 +17,7 @@ public class UserAcceptanceTestSupporter { protected ResultActions getLoginedUser(String token) throws Exception { return mockMvc.perform(MockMvcRequestBuilders - .get(API_VERSION + "/users/logined") + .get(API_VERSION + "/users/logins") .accept(MediaType.APPLICATION_JSON) .header(HttpHeaders.AUTHORIZATION, token) ); @@ -33,6 +33,12 @@ protected ResultActions updateTargetPosition(String token, String content) throw ); } + protected ResultActions deleteUser(String token) throws Exception { + return mockMvc.perform(MockMvcRequestBuilders + .delete(API_VERSION + "/users") + .header(HttpHeaders.AUTHORIZATION, token)); + } + @Autowired final void setMockMvc(MockMvc mockMvc) { this.mockMvc = mockMvc; diff --git a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/UserAcceptanceValidator.java b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/UserAcceptanceValidator.java index bf074b3f..56504b3b 100644 --- a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/UserAcceptanceValidator.java +++ b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/UserAcceptanceValidator.java @@ -6,11 +6,12 @@ public class UserAcceptanceValidator { - public static void assertIsLogined(ResultActions resultActions, Long targetId, String nickname) throws Exception { + public static void assertIsLogined(ResultActions resultActions, Long targetId, String nickname, String email) throws Exception { resultActions.andExpectAll( status().isOk(), jsonPath("$.target_id").value(targetId), - jsonPath("$.nickname").value(nickname) + jsonPath("$.nickname").value(nickname), + jsonPath("$.email").value(email) ); } diff --git a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/delete/UserDeleteAcceptanceTest.java b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/delete/UserDeleteAcceptanceTest.java new file mode 100644 index 00000000..f932fa39 --- /dev/null +++ b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/delete/UserDeleteAcceptanceTest.java @@ -0,0 +1,73 @@ +package me.nalab.luffy.api.acceptance.test.user.delete; + +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.time.Instant; +import java.util.Set; +import me.nalab.auth.application.common.dto.Payload; +import me.nalab.auth.application.common.utils.JwtUtils; +import me.nalab.auth.mock.api.MockUserRegisterEvent; +import me.nalab.luffy.api.acceptance.test.TargetInitializer; +import me.nalab.luffy.api.acceptance.test.UserInitializer; +import me.nalab.luffy.api.acceptance.test.user.UserAcceptanceTestSupporter; +import me.nalab.user.domain.user.Provider; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.test.context.TestPropertySource; + +@SpringBootTest +@AutoConfigureMockMvc +@TestPropertySource("classpath:h2.properties") +@ComponentScan("me.nalab") +@EnableJpaRepositories(basePackages = {"me.nalab"}) +@EntityScan(basePackages = {"me.nalab"}) +class UserDeleteAcceptanceTest extends UserAcceptanceTestSupporter { + + @Autowired + private ApplicationEventPublisher applicationEventPublisher; + + @Autowired + private TargetInitializer targetInitializer; + + @Autowired + private JwtUtils jwtUtils; + + @Autowired + private UserInitializer userInitializer; + + @Test + @DisplayName("DELETE /v1/users API는 token에 해당하는 유저가 삭제되면 200 OK를 반환한다.") + void DELETE_USER_SUCCESS() throws Exception { + // given + String nickname = "delete_user_success"; + String email = "delete_user_success"; + + var token = "bearer " + createUserAndSetToken(nickname, email); + + // when + var result = deleteUser(token); + + // then + result.andExpect(status().isOk()); + } + + private String createUserAndSetToken(String nickname, String email) { + Long userId = userInitializer.saveUserWithOAuth(Provider.DEFAULT, nickname, email, Instant.now()); + Long targetId = targetInitializer.saveTargetAndGetId(nickname, Instant.now()); + + var token = jwtUtils.createAccessToken(Set.of(new Payload(Payload.Key.USER_ID, String.valueOf(userId)), + new Payload(Payload.Key.TARGET_ID, String.valueOf(targetId)))); + + applicationEventPublisher.publishEvent( + MockUserRegisterEvent.builder().expectedToken("bearer " + token).expectedId(targetId).build()); + + return token; + } +} diff --git a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/logined/LoginedTargetFindAcceptanceTest.java b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/logined/LoginedTargetFindAcceptanceTest.java index 176f5d65..df70b9ab 100644 --- a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/logined/LoginedTargetFindAcceptanceTest.java +++ b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/logined/LoginedTargetFindAcceptanceTest.java @@ -5,6 +5,8 @@ import java.time.Instant; import java.util.Set; +import me.nalab.luffy.api.acceptance.test.UserInitializer; +import me.nalab.user.domain.user.Provider; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -40,14 +42,19 @@ class LoginedTargetFindAcceptanceTest extends UserAcceptanceTestSupporter { @Autowired private JwtUtils jwtUtils; + @Autowired + private UserInitializer userInitializer; + @Test @DisplayName("로그인된 유저 정보 조회 성공 테스트") void GET_LOGINED_USER_SUCCESS() throws Exception { // given String nickname = "devxb"; + String email = "email"; + Long userId = userInitializer.saveUserWithOAuth(Provider.DEFAULT, nickname, "email", Instant.now()); Long targetId = targetInitializer.saveTargetAndGetId(nickname, Instant.now()); - String token = jwtUtils.createAccessToken(Set.of(new Payload(Payload.Key.NICKNAME, nickname), - new Payload(Payload.Key.USER_ID, 12345 + ""), new Payload(Payload.Key.TARGET_ID, targetId + ""))); + String token = jwtUtils.createAccessToken(Set.of(new Payload(Payload.Key.USER_ID, String.valueOf(userId)), + new Payload(Payload.Key.TARGET_ID, String.valueOf(targetId)))); applicationEventPublisher.publishEvent( MockUserRegisterEvent.builder().expectedToken("bearer " + token).expectedId(targetId).build()); @@ -55,7 +62,7 @@ void GET_LOGINED_USER_SUCCESS() throws Exception { ResultActions resultActions = getLoginedUser("bearer " + token); // then - assertIsLogined(resultActions, targetId, nickname); + assertIsLogined(resultActions, targetId, nickname, email); } } diff --git a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/updatetarget/TargetPositionUpdateAcceptanceTest.java b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/updatetarget/TargetPositionUpdateAcceptanceTest.java index 1e6fe2df..7bf4bb73 100644 --- a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/updatetarget/TargetPositionUpdateAcceptanceTest.java +++ b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/updatetarget/TargetPositionUpdateAcceptanceTest.java @@ -41,7 +41,7 @@ void TARGET_POSITION_UPDATE_SUCCESS_TEST() throws Exception { // given String nickname = "nickname"; Long targetId = targetInitializer.saveTargetAndGetId(nickname, Instant.now()); - String token = "token"; + String token = "bearer token"; applicationEventPublisher.publishEvent(MockUserRegisterEvent.builder() .expectedToken(token) .expectedId(targetId) diff --git a/auth/auth-application/src/main/java/me/nalab/auth/application/common/dto/CreateAuthTokenRequest.java b/auth/auth-application/src/main/java/me/nalab/auth/application/common/dto/CreateAuthTokenRequest.java index 6c98c9d4..16fe250f 100644 --- a/auth/auth-application/src/main/java/me/nalab/auth/application/common/dto/CreateAuthTokenRequest.java +++ b/auth/auth-application/src/main/java/me/nalab/auth/application/common/dto/CreateAuthTokenRequest.java @@ -5,6 +5,5 @@ @Data public class CreateAuthTokenRequest { private final String userId; - private final String nickname; private final String targetId; } diff --git a/auth/auth-application/src/main/java/me/nalab/auth/application/common/dto/Payload.java b/auth/auth-application/src/main/java/me/nalab/auth/application/common/dto/Payload.java index f6fff8d9..5f7887a0 100644 --- a/auth/auth-application/src/main/java/me/nalab/auth/application/common/dto/Payload.java +++ b/auth/auth-application/src/main/java/me/nalab/auth/application/common/dto/Payload.java @@ -14,6 +14,5 @@ public class Payload { public enum Key { USER_ID, TARGET_ID, - NICKNAME, } } diff --git a/auth/auth-application/src/main/java/me/nalab/auth/application/common/exception/AuthException.java b/auth/auth-application/src/main/java/me/nalab/auth/application/common/exception/AuthException.java new file mode 100644 index 00000000..08ff33ca --- /dev/null +++ b/auth/auth-application/src/main/java/me/nalab/auth/application/common/exception/AuthException.java @@ -0,0 +1,8 @@ +package me.nalab.auth.application.common.exception; + +public class AuthException extends RuntimeException { + + public AuthException(String message) { + super(message); + } +} diff --git a/auth/auth-application/src/main/java/me/nalab/auth/application/common/utils/JwtUtils.java b/auth/auth-application/src/main/java/me/nalab/auth/application/common/utils/JwtUtils.java index b038ef4b..b98eddeb 100644 --- a/auth/auth-application/src/main/java/me/nalab/auth/application/common/utils/JwtUtils.java +++ b/auth/auth-application/src/main/java/me/nalab/auth/application/common/utils/JwtUtils.java @@ -1,10 +1,16 @@ package me.nalab.auth.application.common.utils; +import com.auth0.jwt.exceptions.AlgorithmMismatchException; +import com.auth0.jwt.exceptions.IncorrectClaimException; +import com.auth0.jwt.exceptions.MissingClaimException; +import com.auth0.jwt.exceptions.SignatureVerificationException; +import com.auth0.jwt.exceptions.TokenExpiredException; import java.time.Instant; import java.util.HashMap; import java.util.Map; import java.util.Set; +import me.nalab.auth.application.common.exception.AuthException; import org.springframework.stereotype.Component; import com.auth0.jwt.JWT; @@ -33,7 +39,16 @@ public DecodedJWT verify(String jwt) { var algorithm = getAlgorithm(); var verifier = getVerifier(algorithm); - return verifier.verify(jwt); + try { + return verifier.verify(jwt); + } catch (TokenExpiredException tokenExpiredException) { + throw new AuthException("Expired token"); + } catch (IncorrectClaimException + | MissingClaimException + | SignatureVerificationException + | AlgorithmMismatchException invalidTokenException) { + throw new AuthException("Invalid token"); + } } private JWTVerifier getVerifier(Algorithm algorithm) { diff --git a/auth/auth-application/src/main/java/me/nalab/auth/application/service/AuthTokenCreateService.java b/auth/auth-application/src/main/java/me/nalab/auth/application/service/AuthTokenCreateService.java index 29c7e6fd..080d85ef 100644 --- a/auth/auth-application/src/main/java/me/nalab/auth/application/service/AuthTokenCreateService.java +++ b/auth/auth-application/src/main/java/me/nalab/auth/application/service/AuthTokenCreateService.java @@ -22,15 +22,12 @@ public class AuthTokenCreateService implements AuthTokenCreateUseCase { @Override public AuthToken create(CreateAuthTokenRequest request) { var userId = request.getUserId(); - var nickname = request.getNickname(); var targetId = request.getTargetId(); Assert.isTrue(userId != null && !userId.isBlank(), "Authentication token 생성 시 유저 식별자는 필수입니다."); - Assert.isTrue(nickname != null && !nickname.isBlank(), "Authentication token 생성 시 유저의 별명은 필수입니다."); Assert.isTrue(targetId != null && !targetId.isBlank(), "Authentication token 생성 시 유저의 별명은 필수입니다."); Set payload = new HashSet<>(); payload.add(new Payload(Payload.Key.USER_ID, userId)); - payload.add(new Payload(Payload.Key.NICKNAME, nickname)); payload.add(new Payload(Payload.Key.TARGET_ID, targetId)); String token = createToken(payload); diff --git a/auth/auth-application/src/main/java/me/nalab/auth/application/service/JwtLoginedDecryptService.java b/auth/auth-application/src/main/java/me/nalab/auth/application/service/JwtLoginedDecryptService.java index 8f79ead5..53ab1be2 100644 --- a/auth/auth-application/src/main/java/me/nalab/auth/application/service/JwtLoginedDecryptService.java +++ b/auth/auth-application/src/main/java/me/nalab/auth/application/service/JwtLoginedDecryptService.java @@ -9,7 +9,7 @@ import me.nalab.auth.application.common.dto.Payload; import me.nalab.auth.application.common.utils.JwtUtils; import me.nalab.auth.application.port.in.web.TargetIdGetPort; -import me.nalab.user.application.common.dto.LoginedInfo; +import me.nalab.user.application.common.dto.TokenInfo; import me.nalab.user.application.port.out.persistence.LoginedUserGetByTokenPort; @Service @@ -19,14 +19,13 @@ public class JwtLoginedDecryptService implements LoginedUserGetByTokenPort, Targ private final JwtUtils jwtUtils; @Override - public LoginedInfo decryptToken(String encryptedToken) { + public TokenInfo decryptToken(String encryptedToken) { Assert.isTrue(encryptedToken != null && !encryptedToken.isBlank(), "encryptedToken 으로 blank나 null 값이 들어올 수 없습니다."); DecodedJWT decodedJWT = jwtUtils.verify(encryptedToken); - String nickName = decodedJWT.getClaim(Payload.Key.NICKNAME.name()).asString(); Long userId = Long.valueOf(decodedJWT.getClaim(Payload.Key.USER_ID.name()).asString()); Long targetId = Long.valueOf(decodedJWT.getClaim(Payload.Key.TARGET_ID.name()).asString()); - return new LoginedInfo(nickName, targetId, userId); + return new TokenInfo(targetId, userId); } @Override diff --git a/auth/auth-application/src/main/java/me/nalab/auth/application/service/SignInWithOAuthService.java b/auth/auth-application/src/main/java/me/nalab/auth/application/service/SignInWithOAuthService.java index 70866829..2e37ff5f 100644 --- a/auth/auth-application/src/main/java/me/nalab/auth/application/service/SignInWithOAuthService.java +++ b/auth/auth-application/src/main/java/me/nalab/auth/application/service/SignInWithOAuthService.java @@ -36,7 +36,7 @@ public AuthToken signInWithOAuth(SignInWithOAuthRequest request) { var userId = foundUser.orElseThrow(IllegalAccessError::new); var targetId = targetFindByUsernameUseCase.findTargetByUsername(request.getUsername()).orElseThrow().getId(); - var authTokenCreateRequest = new CreateAuthTokenRequest(userId.toString(), request.getUsername(), String.valueOf(targetId)); + var authTokenCreateRequest = new CreateAuthTokenRequest(userId.toString(), String.valueOf(targetId)); return authTokenCreateUseCase.create(authTokenCreateRequest); } diff --git a/auth/auth-application/src/main/java/module-info.java b/auth/auth-application/src/main/java/module-info.java index e15d8ffe..34202880 100644 --- a/auth/auth-application/src/main/java/module-info.java +++ b/auth/auth-application/src/main/java/module-info.java @@ -3,6 +3,7 @@ exports me.nalab.auth.application.port.in.web; exports me.nalab.auth.application.port.in; exports me.nalab.auth.application.port.out; + exports me.nalab.auth.application.common.exception; requires lombok; requires com.fasterxml.jackson.annotation; diff --git a/auth/auth-application/src/test/java/me/nalab/auth/application/service/AuthTokenCreateServiceTest.java b/auth/auth-application/src/test/java/me/nalab/auth/application/service/AuthTokenCreateServiceTest.java index eff30c90..2b1171a8 100644 --- a/auth/auth-application/src/test/java/me/nalab/auth/application/service/AuthTokenCreateServiceTest.java +++ b/auth/auth-application/src/test/java/me/nalab/auth/application/service/AuthTokenCreateServiceTest.java @@ -31,25 +31,8 @@ class AuthTokenCreateServiceTest { @DisplayName("유저식별자가 없거나 비어있다면 예외를 발생시킨다") void THROW_EXCEPTION_WHEN_USER_ID_IS_BLANK(String userId) { // given - var nickname = "nickname"; var targetId = "targetId"; - var request = new CreateAuthTokenRequest(userId, nickname, targetId); - - // when - var throwable = Assertions.catchThrowable(() -> authTokenCreateService.create(request)); - - // then - Assertions.assertThat(throwable).isInstanceOf(IllegalArgumentException.class); - } - - @ParameterizedTest - @NullAndEmptySource() - @DisplayName("닉네임가 없거나 비어있다면 예외를 발생시킨다") - void THROW_EXCEPTION_WHEN_NICKNAME_IS_BLANK(String nickname) { - // given - var userId = "userId"; - var targetId = "targetId"; - var request = new CreateAuthTokenRequest(userId, nickname, targetId); + var request = new CreateAuthTokenRequest(userId, targetId); // when var throwable = Assertions.catchThrowable(() -> authTokenCreateService.create(request)); @@ -64,8 +47,7 @@ void THROW_EXCEPTION_WHEN_NICKNAME_IS_BLANK(String nickname) { void THROW_EXCEPTION_WHEN_TARGET_ID_IS_BLANK(String targetId) { // given var userId = "userId"; - var nickname = "nickname"; - var request = new CreateAuthTokenRequest(userId, nickname, targetId); + var request = new CreateAuthTokenRequest(userId, targetId); // when var throwable = Assertions.catchThrowable(() -> authTokenCreateService.create(request)); @@ -79,9 +61,8 @@ void THROW_EXCEPTION_WHEN_TARGET_ID_IS_BLANK(String targetId) { void RETURN_TOKEN_WHEN_VALID_REQUEST() { // given var userId = "userId"; - var nickname = "nickname"; var targetId = "targetId"; - var request = new CreateAuthTokenRequest(userId, nickname, targetId); + var request = new CreateAuthTokenRequest(userId, targetId); var expectedToken = "token"; when(jwtUtils.createAccessToken(any())).thenReturn(expectedToken); diff --git a/auth/auth-application/src/test/java/me/nalab/auth/application/service/JwtLoginedDecryptServiceTest.java b/auth/auth-application/src/test/java/me/nalab/auth/application/service/JwtLoginedDecryptServiceTest.java index 89674276..ac1b32e0 100644 --- a/auth/auth-application/src/test/java/me/nalab/auth/application/service/JwtLoginedDecryptServiceTest.java +++ b/auth/auth-application/src/test/java/me/nalab/auth/application/service/JwtLoginedDecryptServiceTest.java @@ -18,7 +18,7 @@ import me.nalab.auth.application.common.dto.Payload; import me.nalab.auth.application.common.property.JwtProperties; import me.nalab.auth.application.common.utils.JwtUtils; -import me.nalab.user.application.common.dto.LoginedInfo; +import me.nalab.user.application.common.dto.TokenInfo; @ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {JwtLoginedDecryptService.class, JwtUtils.class, JwtProperties.class}) @@ -38,11 +38,11 @@ void JWT_DECRYPT_SUCCESS() { long userId = 12345; long targetId = 54321; String requestToken = jwtUtils.createAccessToken( - Set.of(new Payload(Payload.Key.NICKNAME, nickName), new Payload(Payload.Key.USER_ID, userId + ""), + Set.of(new Payload(Payload.Key.USER_ID, userId + ""), new Payload(Payload.Key.TARGET_ID, targetId + ""))); // when - LoginedInfo response = jwtLoginedDecryptService.decryptToken(requestToken); + TokenInfo response = jwtLoginedDecryptService.decryptToken(requestToken); // then assertDecryptedInfo(response, nickName, userId, targetId); @@ -59,11 +59,10 @@ void THROW_EXCEPTION_WHEN_TOKEN_IS_NULL_OR_EMPTY(String token) { assertThat(throwable).isInstanceOf(IllegalArgumentException.class); } - private void assertDecryptedInfo(LoginedInfo response, String expectedName, Long expectedUserId, + private void assertDecryptedInfo(TokenInfo response, String expectedName, Long expectedUserId, Long expectedTargetId) { - Assertions.assertEquals(response.getNickName(), expectedName); - Assertions.assertEquals(response.getUserId(), expectedUserId); - Assertions.assertEquals(response.getTargetId(), expectedTargetId); + Assertions.assertEquals(response.userId(), expectedUserId); + Assertions.assertEquals(response.targetId(), expectedTargetId); } @Test @@ -74,7 +73,6 @@ void DECRYPTE_TARGET_ID_SUCCESS() { long userId = 12345; long targetId = 54321; String requestToken = jwtUtils.createAccessToken(Set.of( - new Payload(Payload.Key.NICKNAME, nickName), new Payload(Payload.Key.USER_ID, String.valueOf(userId)), new Payload(Payload.Key.TARGET_ID, String.valueOf(targetId)) )); diff --git a/auth/auth-interceptor/src/main/java/me/nalab/auth/interceptor/AuthenticateHeaderPrefix.java b/auth/auth-interceptor/src/main/java/me/nalab/auth/interceptor/AuthenticateHeaderPrefix.java new file mode 100644 index 00000000..0396a863 --- /dev/null +++ b/auth/auth-interceptor/src/main/java/me/nalab/auth/interceptor/AuthenticateHeaderPrefix.java @@ -0,0 +1,7 @@ +package me.nalab.auth.interceptor; + +public enum AuthenticateHeaderPrefix { + + BEARER, + ; +} diff --git a/auth/auth-interceptor/src/main/java/me/nalab/auth/interceptor/JwtDecryptInterceptor.java b/auth/auth-interceptor/src/main/java/me/nalab/auth/interceptor/JwtDecryptInterceptor.java index d3e1a7fc..a29942cb 100644 --- a/auth/auth-interceptor/src/main/java/me/nalab/auth/interceptor/JwtDecryptInterceptor.java +++ b/auth/auth-interceptor/src/main/java/me/nalab/auth/interceptor/JwtDecryptInterceptor.java @@ -32,6 +32,8 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons throwIfCannotValidToken(token); Long targetId = getTargetId(token); request.setAttribute("logined", targetId); + request.setAttribute("tokenType", AuthenticateHeaderPrefix.valueOf(token.split(" ")[0].toUpperCase())); + request.setAttribute("tokenValue", token.split(" ")[1]); } return true; } diff --git a/auth/auth-interceptor/src/main/java/me/nalab/auth/interceptor/JwtDecryptInterceptorConfigurer.java b/auth/auth-interceptor/src/main/java/me/nalab/auth/interceptor/JwtDecryptInterceptorConfigurer.java index b57b22da..02c04199 100644 --- a/auth/auth-interceptor/src/main/java/me/nalab/auth/interceptor/JwtDecryptInterceptorConfigurer.java +++ b/auth/auth-interceptor/src/main/java/me/nalab/auth/interceptor/JwtDecryptInterceptorConfigurer.java @@ -33,6 +33,7 @@ public class JwtDecryptInterceptorConfigurer implements WebMvcConfigurer { "/v1/gallerys/logins", "/v1/gallerys", "/v1/surveys/bookmarks*", + "/v1/users/logins", }; @Override diff --git a/auth/auth-mock/src/main/java/me/nalab/auth/mock/config/MockAuthConfigurer.java b/auth/auth-mock/src/main/java/me/nalab/auth/mock/config/MockAuthConfigurer.java index c2bcfda3..5dbe9242 100644 --- a/auth/auth-mock/src/main/java/me/nalab/auth/mock/config/MockAuthConfigurer.java +++ b/auth/auth-mock/src/main/java/me/nalab/auth/mock/config/MockAuthConfigurer.java @@ -23,6 +23,7 @@ public class MockAuthConfigurer implements WebMvcConfigurer { "/v1/reviewers/summary*", "/v2/surveys/*/feedbacks", "/v1/surveys/*/bookmarks", + "/v1/users/logins", }; @Override diff --git a/auth/auth-mock/src/main/java/me/nalab/auth/mock/interceptor/AuthenticateHeaderPrefix.java b/auth/auth-mock/src/main/java/me/nalab/auth/mock/interceptor/AuthenticateHeaderPrefix.java new file mode 100644 index 00000000..2319d909 --- /dev/null +++ b/auth/auth-mock/src/main/java/me/nalab/auth/mock/interceptor/AuthenticateHeaderPrefix.java @@ -0,0 +1,7 @@ +package me.nalab.auth.mock.interceptor; + +public enum AuthenticateHeaderPrefix { + + BEARER, + ; +} diff --git a/auth/auth-mock/src/main/java/me/nalab/auth/mock/interceptor/MockAuthInterceptor.java b/auth/auth-mock/src/main/java/me/nalab/auth/mock/interceptor/MockAuthInterceptor.java index 3c1c0827..93eeef76 100644 --- a/auth/auth-mock/src/main/java/me/nalab/auth/mock/interceptor/MockAuthInterceptor.java +++ b/auth/auth-mock/src/main/java/me/nalab/auth/mock/interceptor/MockAuthInterceptor.java @@ -26,6 +26,8 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons String token = request.getHeader("Authorization"); throwIfCannotValidToken(token); request.setAttribute("logined", expectedId); + request.setAttribute("tokenType", AuthenticateHeaderPrefix.valueOf(token.split(" ")[0].toUpperCase())); + request.setAttribute("tokenValue", token.split(" ")[1]); } return true; } diff --git a/auth/auth-mock/src/test/java/me/nalab/auth/mock/interceptor/MockAuthInterceptorTest.java b/auth/auth-mock/src/test/java/me/nalab/auth/mock/interceptor/MockAuthInterceptorTest.java index b18b58da..13f0d784 100644 --- a/auth/auth-mock/src/test/java/me/nalab/auth/mock/interceptor/MockAuthInterceptorTest.java +++ b/auth/auth-mock/src/test/java/me/nalab/auth/mock/interceptor/MockAuthInterceptorTest.java @@ -62,24 +62,24 @@ void FAIL_LOGIN(HttpMethod httpMethod, String url, String requestToken, String e static Stream successSources() { return Stream.of( - of(HttpMethod.POST, "/v1/surveys", "token1", 1L) - , of(HttpMethod.POST, "/v1/surveys", "token1", 2L) - , of(HttpMethod.GET, "/v1/surveys-id", "token3", 3L) - , of(HttpMethod.GET, "/v1/questions?survey-id=4", "token4", 4L) - , of(HttpMethod.GET, "/v1/feedbacks?survey-id=5", "token5", 5L) - , of(HttpMethod.GET, "/v1/feedbacks/6", "token6", 6L) - , of(HttpMethod.GET, "/v1/feedbacks/summary?survey-id=7", "token7", 7L) - , of(HttpMethod.GET, "/v1/feedbacks?question-id=8", "token8", 8L) + of(HttpMethod.POST, "/v1/surveys", "bearer token1", 1L) + , of(HttpMethod.POST, "/v1/surveys", "bearer token1", 2L) + , of(HttpMethod.GET, "/v1/surveys-id", "bearer token3", 3L) + , of(HttpMethod.GET, "/v1/questions?survey-id=4", "bearer token4", 4L) + , of(HttpMethod.GET, "/v1/feedbacks?survey-id=5", "bearer token5", 5L) + , of(HttpMethod.GET, "/v1/feedbacks/6", "bearer token6", 6L) + , of(HttpMethod.GET, "/v1/feedbacks/summary?survey-id=7", "bearer token7", 7L) + , of(HttpMethod.GET, "/v1/feedbacks?question-id=8", "bearer token8", 8L) ); } static Stream failSources() { return Stream.of( of(HttpMethod.POST, "/v1/surveys", null, null, null) - , of(HttpMethod.GET, "/v1/users", null, "token2", 2L) - , of(HttpMethod.GET, "/v1/users", "token3", null, 3L) - , of(HttpMethod.GET, "/v1/users", "token4", "4nekot", 4L) - , of(HttpMethod.GET, "/v1/users", "token4", "token4", null) + , of(HttpMethod.GET, "/v1/users", null, "bearer token2", 2L) + , of(HttpMethod.GET, "/v1/users", "bearer token3", null, 3L) + , of(HttpMethod.GET, "/v1/users", "bearer token4", "bearer 4nekot", 4L) + , of(HttpMethod.GET, "/v1/users", "bearer token4", "bearer token4", null) ); } diff --git a/auth/auth-web-adaptor/build.gradle b/auth/auth-web-adaptor/build.gradle index ce7d85cd..4f15b56d 100644 --- a/auth/auth-web-adaptor/build.gradle +++ b/auth/auth-web-adaptor/build.gradle @@ -1,6 +1,7 @@ dependencies { implementation project(':auth:auth-application') implementation project(':auth:oauth-application') + implementation project(':core:exception-handler') testImplementation project(':auth:auth-application') implementation 'org.springframework.boot:spring-boot-starter-web' diff --git a/auth/auth-web-adaptor/src/main/java/me/nalab/auth/web/adaptor/advice/AuthControllerAdvice.java b/auth/auth-web-adaptor/src/main/java/me/nalab/auth/web/adaptor/advice/AuthControllerAdvice.java new file mode 100644 index 00000000..3c2cfd71 --- /dev/null +++ b/auth/auth-web-adaptor/src/main/java/me/nalab/auth/web/adaptor/advice/AuthControllerAdvice.java @@ -0,0 +1,19 @@ +package me.nalab.auth.web.adaptor.advice; + +import me.nalab.auth.application.common.exception.AuthException; +import me.nalab.core.exception.handler.ErrorTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@RestControllerAdvice +public class AuthControllerAdvice { + + @ExceptionHandler(AuthException.class) + @ResponseStatus(HttpStatus.UNAUTHORIZED) + public ErrorTemplate handleAuthException(AuthException authException) { + return ErrorTemplate.of(authException.getMessage()); + } + +} diff --git a/auth/auth-web-adaptor/src/main/java/module-info.java b/auth/auth-web-adaptor/src/main/java/module-info.java index 14ccca98..ca16a0e4 100644 --- a/auth/auth-web-adaptor/src/main/java/module-info.java +++ b/auth/auth-web-adaptor/src/main/java/module-info.java @@ -3,6 +3,7 @@ requires luffy.auth.auth.application.main; requires luffy.auth.oauth.application.main; + requires luffy.core.exception.handler.main; requires lombok; requires java.validation; diff --git a/core/exception-handler/src/main/java/module-info.java b/core/exception-handler/src/main/java/module-info.java index 6a97ed6e..f1b49a4f 100644 --- a/core/exception-handler/src/main/java/module-info.java +++ b/core/exception-handler/src/main/java/module-info.java @@ -1,4 +1,6 @@ module luffy.core.exception.handler.main { + exports me.nalab.core.exception.handler; + requires spring.web; requires lombok; requires com.fasterxml.jackson.annotation; diff --git a/support/e2e/v1_13_get_logined_target.hurl b/support/e2e/v1_13_get_logined_target.hurl new file mode 100644 index 00000000..8407dce4 --- /dev/null +++ b/support/e2e/v1_13_get_logined_target.hurl @@ -0,0 +1,29 @@ +POST http://nalab-server:8080/v1/oauth/default # Default provider를 통해서 로그인 진행 +{ + "nickname": "devxb", + "email": "get_logined_target@naver.com" +} + +HTTP 200 +[Asserts] +header "Content-type" == "application/json" + +jsonpath "$.access_token" exists +jsonpath "$.token_type" exists + +[Captures] +token_type: jsonpath "$.token_type" +auth_token: jsonpath "$.access_token" + +####### + +GET http://nalab-server:8080/v1/users/logins # Token에 해당하는 유저 조회 +Authorization: {{ token_type }} {{ auth_token }} + +HTTP 200 +[Asserts] +header "Content-type" == "application/json" + +jsonpath "$.target_id" exists +jsonpath "$.nickname" == "devxb" +jsonpath "$.email" == "get_logined_target@naver.com" diff --git a/user/user-application/src/main/java/me/nalab/user/application/common/dto/LoginedInfo.java b/user/user-application/src/main/java/me/nalab/user/application/common/dto/LoginedInfo.java index c636eec5..2eda3b2d 100644 --- a/user/user-application/src/main/java/me/nalab/user/application/common/dto/LoginedInfo.java +++ b/user/user-application/src/main/java/me/nalab/user/application/common/dto/LoginedInfo.java @@ -1,12 +1,15 @@ package me.nalab.user.application.common.dto; -import lombok.Data; - -@Data -public class LoginedInfo { - - private final String nickName; - private final Long targetId; - private final Long userId; - +import me.nalab.user.domain.user.User; + +public record LoginedInfo( + Long id, + Long targetId, + String nickname, + String email +) { + + public static LoginedInfo from(Long targetId, User user) { + return new LoginedInfo(user.getId(), targetId, user.getNickname(), user.getEmail()); + } } diff --git a/user/user-application/src/main/java/me/nalab/user/application/common/dto/TokenInfo.java b/user/user-application/src/main/java/me/nalab/user/application/common/dto/TokenInfo.java new file mode 100644 index 00000000..d60e4686 --- /dev/null +++ b/user/user-application/src/main/java/me/nalab/user/application/common/dto/TokenInfo.java @@ -0,0 +1,8 @@ +package me.nalab.user.application.common.dto; + +public record TokenInfo( + Long targetId, + Long userId +) { + +} diff --git a/user/user-application/src/main/java/me/nalab/user/application/port/in/LoginedUserGetByTokenUseCase.java b/user/user-application/src/main/java/me/nalab/user/application/port/in/LoginedUserGetByTokenUseCase.java index 04f2b722..d70be8b0 100644 --- a/user/user-application/src/main/java/me/nalab/user/application/port/in/LoginedUserGetByTokenUseCase.java +++ b/user/user-application/src/main/java/me/nalab/user/application/port/in/LoginedUserGetByTokenUseCase.java @@ -13,6 +13,6 @@ public interface LoginedUserGetByTokenUseCase { * @param encryptedToken 암호화된 토큰 * @return 복호화된 정보 */ - LoginedInfo decryptToken(String encryptedToken); + LoginedInfo getLoginedInfoByToken(String encryptedToken); } diff --git a/user/user-application/src/main/java/me/nalab/user/application/port/in/UserDeleteUseCase.java b/user/user-application/src/main/java/me/nalab/user/application/port/in/UserDeleteUseCase.java new file mode 100644 index 00000000..e2d05037 --- /dev/null +++ b/user/user-application/src/main/java/me/nalab/user/application/port/in/UserDeleteUseCase.java @@ -0,0 +1,9 @@ +package me.nalab.user.application.port.in; + +public interface UserDeleteUseCase { + + /* + 토큰에 해당하는 유저를 삭제합니다. + */ + void deleteByToken(String token); +} diff --git a/user/user-application/src/main/java/me/nalab/user/application/port/out/persistence/LoginedUserGetByTokenPort.java b/user/user-application/src/main/java/me/nalab/user/application/port/out/persistence/LoginedUserGetByTokenPort.java index 7949f301..00f32f3e 100644 --- a/user/user-application/src/main/java/me/nalab/user/application/port/out/persistence/LoginedUserGetByTokenPort.java +++ b/user/user-application/src/main/java/me/nalab/user/application/port/out/persistence/LoginedUserGetByTokenPort.java @@ -1,6 +1,6 @@ package me.nalab.user.application.port.out.persistence; -import me.nalab.user.application.common.dto.LoginedInfo; +import me.nalab.user.application.common.dto.TokenInfo; /** * token을 받아 decrypt된 유저의 정보를 반환하는 유즈케이스 @@ -8,11 +8,11 @@ public interface LoginedUserGetByTokenPort { /** - * 암호화된 유저의 토큰을 받아, 복호화된 유저의 정보를 반환합니다. + * 암호화된 유저의 토큰을 받아, 복호화된 토큰의 정보를 반환합니다. * * @param encryptedToken 암호화된 토큰 * @return 복호화된 정보 */ - LoginedInfo decryptToken(String encryptedToken); + TokenInfo decryptToken(String encryptedToken); } diff --git a/user/user-application/src/main/java/me/nalab/user/application/port/out/persistence/UserDeletePort.java b/user/user-application/src/main/java/me/nalab/user/application/port/out/persistence/UserDeletePort.java new file mode 100644 index 00000000..02c25aa7 --- /dev/null +++ b/user/user-application/src/main/java/me/nalab/user/application/port/out/persistence/UserDeletePort.java @@ -0,0 +1,9 @@ +package me.nalab.user.application.port.out.persistence; + +public interface UserDeletePort { + + /* + user id에 해당하는 유저를 삭제합니다. + */ + void deleteUserById(Long userId); +} diff --git a/user/user-application/src/main/java/me/nalab/user/application/port/out/persistence/UserGetPort.java b/user/user-application/src/main/java/me/nalab/user/application/port/out/persistence/UserGetPort.java new file mode 100644 index 00000000..9b6dd4f2 --- /dev/null +++ b/user/user-application/src/main/java/me/nalab/user/application/port/out/persistence/UserGetPort.java @@ -0,0 +1,8 @@ +package me.nalab.user.application.port.out.persistence; + +import me.nalab.user.domain.user.User; + +public interface UserGetPort { + + User getById(Long id); +} diff --git a/user/user-application/src/main/java/me/nalab/user/application/service/LoginedUserGetByTokenService.java b/user/user-application/src/main/java/me/nalab/user/application/service/LoginedUserGetByTokenService.java index d26f94eb..54320fc6 100644 --- a/user/user-application/src/main/java/me/nalab/user/application/service/LoginedUserGetByTokenService.java +++ b/user/user-application/src/main/java/me/nalab/user/application/service/LoginedUserGetByTokenService.java @@ -2,32 +2,29 @@ import java.util.Objects; +import me.nalab.user.application.common.dto.LoginedInfo; +import me.nalab.user.application.port.out.persistence.UserGetPort; import org.springframework.stereotype.Service; import lombok.RequiredArgsConstructor; -import me.nalab.user.application.common.dto.LoginedInfo; -import me.nalab.user.application.exception.InvalidTokenException; import me.nalab.user.application.port.in.LoginedUserGetByTokenUseCase; import me.nalab.user.application.port.out.persistence.LoginedUserGetByTokenPort; +import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor public class LoginedUserGetByTokenService implements LoginedUserGetByTokenUseCase { private final LoginedUserGetByTokenPort loginedUserGetByTokenPort; + private final UserGetPort userGetPort; @Override - public LoginedInfo decryptToken(String encryptedToken) { + @Transactional(readOnly = true) + public LoginedInfo getLoginedInfoByToken(String encryptedToken) { Objects.requireNonNull(encryptedToken, "encryptedToken은 null이 되면 안됩니다."); - String[] split = encryptedToken.split(" "); - throwIfInvalidToken(split); - return loginedUserGetByTokenPort.decryptToken(split[1]); - } - - private void throwIfInvalidToken(String[] split) { - if(split.length < 2) { - throw new InvalidTokenException(split[0]); - } + var tokenInfo = loginedUserGetByTokenPort.decryptToken(encryptedToken); + var user = userGetPort.getById(tokenInfo.userId()); + return LoginedInfo.from(tokenInfo.targetId(), user); } } diff --git a/user/user-application/src/main/java/me/nalab/user/application/service/UserDeleteService.java b/user/user-application/src/main/java/me/nalab/user/application/service/UserDeleteService.java new file mode 100644 index 00000000..16f3fae2 --- /dev/null +++ b/user/user-application/src/main/java/me/nalab/user/application/service/UserDeleteService.java @@ -0,0 +1,23 @@ +package me.nalab.user.application.service; + +import lombok.RequiredArgsConstructor; +import me.nalab.user.application.port.in.UserDeleteUseCase; +import me.nalab.user.application.port.out.persistence.LoginedUserGetByTokenPort; +import me.nalab.user.application.port.out.persistence.UserDeletePort; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class UserDeleteService implements UserDeleteUseCase { + + private final LoginedUserGetByTokenPort loginedUserGetByTokenPort; + private final UserDeletePort userDeletePort; + + @Override + @Transactional + public void deleteByToken(String token) { + var tokenInfo = loginedUserGetByTokenPort.decryptToken(token); + userDeletePort.deleteUserById(tokenInfo.userId()); + } +} diff --git a/user/user-application/src/test/java/me/nalab/user/application/service/LoginedUserGetByTokenServiceTest.java b/user/user-application/src/test/java/me/nalab/user/application/service/LoginedUserGetByTokenServiceTest.java index 35423160..1703b05c 100644 --- a/user/user-application/src/test/java/me/nalab/user/application/service/LoginedUserGetByTokenServiceTest.java +++ b/user/user-application/src/test/java/me/nalab/user/application/service/LoginedUserGetByTokenServiceTest.java @@ -1,18 +1,22 @@ package me.nalab.user.application.service; +import me.nalab.user.application.common.dto.LoginedInfo; +import me.nalab.user.application.port.out.persistence.UserGetPort; +import me.nalab.user.domain.user.User; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.NullSource; +import org.mockito.Mock; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; -import me.nalab.user.application.common.dto.LoginedInfo; +import me.nalab.user.application.common.dto.TokenInfo; import me.nalab.user.application.exception.InvalidTokenException; import me.nalab.user.application.port.in.LoginedUserGetByTokenUseCase; import me.nalab.user.application.port.out.persistence.LoginedUserGetByTokenPort; @@ -21,23 +25,34 @@ @ContextConfiguration(classes = {LoginedUserGetByTokenService.class}) class LoginedUserGetByTokenServiceTest { + private static final User DEFAULT_USER = User.builder() + .id(54321L) + .email("email") + .nickname("hello") + .build(); + @Autowired private LoginedUserGetByTokenUseCase loginedUserGetByTokenUseCase; @MockBean private LoginedUserGetByTokenPort loginedUserGetByTokenPort; + @MockBean + private UserGetPort userGetPort; + @Test @DisplayName("토큰을 이용해 로그인된 유저의 정보를 조회 성공 테스트") void GET_LOGINED_INFO_BY_TOKEN_SUCCESS() { // given - LoginedInfo expected = new LoginedInfo("hello", 12345L, 54321L); + LoginedInfo expected = new LoginedInfo(DEFAULT_USER.getId(), 12345L, DEFAULT_USER.getNickname(), DEFAULT_USER.getEmail()); + TokenInfo tokenInfo = new TokenInfo(12345L, DEFAULT_USER.getId()); String token = "hello token"; - Mockito.when(loginedUserGetByTokenPort.decryptToken(token.split(" ")[1])).thenReturn(expected); + Mockito.when(loginedUserGetByTokenPort.decryptToken(token)).thenReturn(tokenInfo); + Mockito.when(userGetPort.getById(54321L)).thenReturn(DEFAULT_USER); // when - LoginedInfo result = loginedUserGetByTokenUseCase.decryptToken(token); + LoginedInfo result = loginedUserGetByTokenUseCase.getLoginedInfoByToken(token); // then Assertions.assertThat(result).isEqualTo(expected); @@ -47,23 +62,9 @@ void GET_LOGINED_INFO_BY_TOKEN_SUCCESS() { @NullSource void NULL_PARAMETER_TEST(String token) { // when - Throwable result = Assertions.catchThrowable(() -> loginedUserGetByTokenUseCase.decryptToken(token)); + Throwable result = Assertions.catchThrowable(() -> loginedUserGetByTokenUseCase.getLoginedInfoByToken(token)); // then Assertions.assertThat(result).isInstanceOf(NullPointerException.class); } - - @Test - @DisplayName("Invalid token signature 테스트") - void DECRYPT_INVALID_TOKEN() { - // given - String token = "invalid"; - - // when - Throwable result = Assertions.catchThrowable(() -> loginedUserGetByTokenUseCase.decryptToken(token)); - - // then - Assertions.assertThat(result).isInstanceOf(InvalidTokenException.class); - } - } diff --git a/user/user-jpa-adapter/src/main/java/me/nalab/user/jpa/adaptor/create/UserDeleteAdaptor.java b/user/user-jpa-adapter/src/main/java/me/nalab/user/jpa/adaptor/create/UserDeleteAdaptor.java new file mode 100644 index 00000000..7463e735 --- /dev/null +++ b/user/user-jpa-adapter/src/main/java/me/nalab/user/jpa/adaptor/create/UserDeleteAdaptor.java @@ -0,0 +1,23 @@ +package me.nalab.user.jpa.adaptor.create; + +import lombok.RequiredArgsConstructor; +import me.nalab.user.application.port.out.persistence.UserDeletePort; +import me.nalab.user.jpa.adaptor.create.repository.UserJpaRepository; +import me.nalab.user.jpa.adaptor.create.repository.UserOAuthInfoJpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +@RequiredArgsConstructor +public class UserDeleteAdaptor implements UserDeletePort { + + private final UserJpaRepository userJpaRepository; + private final UserOAuthInfoJpaRepository userOAuthInfoJpaRepository; + + @Override + public void deleteUserById(Long userId) { + var user = userJpaRepository.findById(userId) + .orElseThrow(() -> new IllegalArgumentException("Cannot find exist user")); + userOAuthInfoJpaRepository.deleteByUserId(user.getId()); + userJpaRepository.deleteById(user.getId()); + } +} diff --git a/user/user-jpa-adapter/src/main/java/me/nalab/user/jpa/adaptor/create/UserGetAdaptor.java b/user/user-jpa-adapter/src/main/java/me/nalab/user/jpa/adaptor/create/UserGetAdaptor.java new file mode 100644 index 00000000..3be06346 --- /dev/null +++ b/user/user-jpa-adapter/src/main/java/me/nalab/user/jpa/adaptor/create/UserGetAdaptor.java @@ -0,0 +1,23 @@ +package me.nalab.user.jpa.adaptor.create; + +import lombok.RequiredArgsConstructor; +import me.nalab.user.application.port.out.persistence.UserGetPort; +import me.nalab.user.domain.user.User; +import me.nalab.user.jpa.adaptor.create.common.mapper.UserObjectMapper; +import me.nalab.user.jpa.adaptor.create.repository.UserJpaRepository; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class UserGetAdaptor implements UserGetPort { + + private final UserJpaRepository userJpaRepository; + + @Override + public User getById(Long id) { + var user = userJpaRepository.findById(id) + .orElseThrow(() -> new IllegalArgumentException(String.format("Cannot find exists user \"%d\"", id))); + + return UserObjectMapper.toDomain(user); + } +} diff --git a/user/user-jpa-adapter/src/main/java/me/nalab/user/jpa/adaptor/create/repository/UserOAuthInfoJpaRepository.java b/user/user-jpa-adapter/src/main/java/me/nalab/user/jpa/adaptor/create/repository/UserOAuthInfoJpaRepository.java index 14f9301e..5e286991 100644 --- a/user/user-jpa-adapter/src/main/java/me/nalab/user/jpa/adaptor/create/repository/UserOAuthInfoJpaRepository.java +++ b/user/user-jpa-adapter/src/main/java/me/nalab/user/jpa/adaptor/create/repository/UserOAuthInfoJpaRepository.java @@ -2,6 +2,9 @@ import me.nalab.core.data.user.UserOAuthInfoEntity; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import java.util.Optional; @@ -9,4 +12,8 @@ @Repository public interface UserOAuthInfoJpaRepository extends JpaRepository { Optional findByProviderAndEmail(String provider, String email); + + @Modifying + @Query("delete from UserOAuthInfoEntity u where u.userEntity.id = :userId") + void deleteByUserId(@Param("userId") Long userId); } diff --git a/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/DeleteUserController.java b/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/DeleteUserController.java new file mode 100644 index 00000000..eca953dd --- /dev/null +++ b/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/DeleteUserController.java @@ -0,0 +1,24 @@ +package me.nalab.user.web.adaptor.logined; + +import lombok.RequiredArgsConstructor; +import me.nalab.user.application.port.in.UserDeleteUseCase; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.RequestAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/v1") +@RequiredArgsConstructor +public class DeleteUserController { + + private final UserDeleteUseCase userDeleteUseCase; + + @DeleteMapping("/users") + @ResponseStatus(HttpStatus.OK) + public void deleteUser(@RequestAttribute("tokenValue") String token) { + userDeleteUseCase.deleteByToken(token); + } +} diff --git a/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/LoginedUserGetController.java b/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/LoginedUserGetController.java index 31b9dbfe..17bafe54 100644 --- a/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/LoginedUserGetController.java +++ b/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/LoginedUserGetController.java @@ -1,13 +1,11 @@ package me.nalab.user.web.adaptor.logined; -import org.springframework.http.HttpHeaders; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import lombok.RequiredArgsConstructor; -import me.nalab.user.application.common.dto.LoginedInfo; import me.nalab.user.application.port.in.LoginedUserGetByTokenUseCase; import me.nalab.user.web.adaptor.logined.response.LoginedInfoResponse; @@ -18,11 +16,9 @@ public class LoginedUserGetController { private final LoginedUserGetByTokenUseCase loginedUserGetByTokenUseCase; - @GetMapping("/users/logined") - public LoginedInfoResponse getLoginedUserByToken(@RequestHeader(HttpHeaders.AUTHORIZATION) String token) { - LoginedInfo loginedInfo = loginedUserGetByTokenUseCase.decryptToken(token); - - return new LoginedInfoResponse(String.valueOf(loginedInfo.getTargetId()), loginedInfo.getNickName()); + @GetMapping("/users/logins") + public LoginedInfoResponse getLoginedUserByToken(@RequestAttribute("tokenValue") String token) { + return LoginedInfoResponse.of(loginedUserGetByTokenUseCase.getLoginedInfoByToken(token)); } } diff --git a/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/response/LoginedInfoResponse.java b/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/response/LoginedInfoResponse.java index 7197cc1b..a9cfe5b2 100644 --- a/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/response/LoginedInfoResponse.java +++ b/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/response/LoginedInfoResponse.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; +import me.nalab.user.application.common.dto.LoginedInfo; @Data public class LoginedInfoResponse { @@ -11,5 +12,11 @@ public class LoginedInfoResponse { private final String targetId; @JsonProperty("nickname") private final String nickName; + @JsonProperty("email") + private final String email; + + public static LoginedInfoResponse of(LoginedInfo loginedInfo) { + return new LoginedInfoResponse(String.valueOf(loginedInfo.targetId()), loginedInfo.nickname(), loginedInfo.email()); + } }