From 508bcfc188df6b80e411f52e0e3b8cdcf8033d50 Mon Sep 17 00:00:00 2001 From: jhkim <62026666+horobito@users.noreply.github.com> Date: Thu, 29 Apr 2021 00:00:43 +0900 Subject: [PATCH 01/20] =?UTF-8?q?*=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=BD=94?= =?UTF-8?q?=EB=93=9C=EC=97=90=20=EA=B2=80=EC=A6=9D=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/demo/timeline/service/TimeLineService.java | 1 + .../demo/friend/service/FriendShipCreateTest.java | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/demo/timeline/service/TimeLineService.java b/src/main/java/com/example/demo/timeline/service/TimeLineService.java index 64a95b5..7a92116 100644 --- a/src/main/java/com/example/demo/timeline/service/TimeLineService.java +++ b/src/main/java/com/example/demo/timeline/service/TimeLineService.java @@ -19,6 +19,7 @@ @Service @RequiredArgsConstructor public class TimeLineService { + private final FriendShipRepository friendShipRepository; private final FeedRepository feedRepository; diff --git a/src/test/java/com/example/demo/friend/service/FriendShipCreateTest.java b/src/test/java/com/example/demo/friend/service/FriendShipCreateTest.java index be9d117..462db6a 100644 --- a/src/test/java/com/example/demo/friend/service/FriendShipCreateTest.java +++ b/src/test/java/com/example/demo/friend/service/FriendShipCreateTest.java @@ -19,7 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) @@ -47,6 +47,7 @@ void createFriendShip() throws AccessDeniedException { String[] friender = { "1", "jihwan"}; String [] friendee = { "2", "friendee"}; + Long friendId = Long.parseLong("1"); //when when(userService.findUserInfo()) @@ -57,6 +58,9 @@ void createFriendShip() throws AccessDeniedException { //then + sut.create(friendId); + verify(friendShipRepository, times(2)).save(any()); + } @@ -169,6 +173,9 @@ void testForAccept() throws AccessDeniedException { //then sut.create(1L); + assertEquals(FriendShipState.ACCEPT, forwardFriendShip.getFriendState()); + assertEquals(FriendShipState.ACCEPT, backwardFriendShip.getFriendState()); + System.out.println("forwardFriendShip의 상태 : " + forwardFriendShip.getFriendState()); System.out.println("backwardFriendShip의 상태 : " + backwardFriendShip.getFriendState()); From e8e08bbb031035a0464369b883d9294fda261fdd Mon Sep 17 00:00:00 2001 From: jhkim <62026666+horobito@users.noreply.github.com> Date: Thu, 29 Apr 2021 00:38:43 +0900 Subject: [PATCH 02/20] =?UTF-8?q?*=20=EC=93=B8=EB=AA=A8=EC=97=86=EB=8A=94?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/friend/controller/FriendShipController.java | 8 +------- .../example/demo/friend/service/FriendShipCreateTest.java | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/example/demo/friend/controller/FriendShipController.java b/src/main/java/com/example/demo/friend/controller/FriendShipController.java index ddb51d6..3dd3a97 100644 --- a/src/main/java/com/example/demo/friend/controller/FriendShipController.java +++ b/src/main/java/com/example/demo/friend/controller/FriendShipController.java @@ -48,13 +48,7 @@ public void createFriendShip(@PathVariable Long friendId) throws AccessDeniedExc @DeleteMapping("/{friendId}") public void deleteFriendShip(@PathVariable Long friendId) throws AccessDeniedException { FriendShipResult result = friendShipService.deleteFriendShipRequest(friendId); - switch ((FriendShipResult)result){ - case NEVER_REQUESTED: - ResponseEntity.status(HttpStatus.BAD_REQUEST); - break; - case SUCCESS: - ResponseEntity.ok(); - } + } @GetMapping("/request") diff --git a/src/test/java/com/example/demo/friend/service/FriendShipCreateTest.java b/src/test/java/com/example/demo/friend/service/FriendShipCreateTest.java index 462db6a..790210a 100644 --- a/src/test/java/com/example/demo/friend/service/FriendShipCreateTest.java +++ b/src/test/java/com/example/demo/friend/service/FriendShipCreateTest.java @@ -47,8 +47,8 @@ void createFriendShip() throws AccessDeniedException { String[] friender = { "1", "jihwan"}; String [] friendee = { "2", "friendee"}; - Long friendId = Long.parseLong("1"); + Long friendId = Long.parseLong("1"); //when when(userService.findUserInfo()) .thenReturn(friender); From fa14f22f08b5af2a43966d9f431167169adbf240 Mon Sep 17 00:00:00 2001 From: jhkim <62026666+horobito@users.noreply.github.com> Date: Tue, 4 May 2021 23:35:03 +0900 Subject: [PATCH 03/20] =?UTF-8?q?*=20String[]=20=EC=9D=84=20=EB=8C=80?= =?UTF-8?q?=EC=B2=B4=ED=95=98=EA=B8=B0=20=EC=9C=84=ED=95=9C=20dto=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EB=B0=8F=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/demo/user/service/UserDto.java | 19 +++++++++++++++++++ .../demo/user/service/UserService.java | 16 +++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/example/demo/user/service/UserDto.java diff --git a/src/main/java/com/example/demo/user/service/UserDto.java b/src/main/java/com/example/demo/user/service/UserDto.java new file mode 100644 index 0000000..75ec86a --- /dev/null +++ b/src/main/java/com/example/demo/user/service/UserDto.java @@ -0,0 +1,19 @@ +package com.example.demo.user.service; + +import lombok.Value; + +@Value +public class UserDto { + Long userId; + String username; + + private UserDto(Long userId, String username){ + this.userId = userId; + this.username = username; + } + + public static UserDto create(Long userId, String username){ + return new UserDto(userId, username); + } + +} diff --git a/src/main/java/com/example/demo/user/service/UserService.java b/src/main/java/com/example/demo/user/service/UserService.java index 8cccf80..4c6d622 100644 --- a/src/main/java/com/example/demo/user/service/UserService.java +++ b/src/main/java/com/example/demo/user/service/UserService.java @@ -53,15 +53,21 @@ public void signup(SignupRequest signupRequest){ - public String[] findUserInfo() throws AccessDeniedException { + public UserDto findUserInfo() throws AccessDeniedException { User user = userSessionService.getLoggeddUser(); - return new String[]{String.valueOf(user.getId()), user.getUserBasicInfo().getUsername()}; + return toUserDto(user); } - public String[] findUserInfo(Long id) throws AccessDeniedException { + public UserDto findUserInfo(Long id) throws AccessDeniedException { User user = userRepository.findUserById(id); - return new String[]{String.valueOf(user.getId()), - user.getUserBasicInfo().getUsername()}; + return toUserDto(user); + } + + public UserDto toUserDto(User user){ + return UserDto.create( + user.getId(), + user.getUserBasicInfo().getUsername() + ); } } From da3fffc2181774c95f7e90bdf9e471f9097fccbc Mon Sep 17 00:00:00 2001 From: jhkim <62026666+horobito@users.noreply.github.com> Date: Tue, 4 May 2021 23:38:45 +0900 Subject: [PATCH 04/20] =?UTF-8?q?*=20commentService=20=EC=97=90=20UserDto?= =?UTF-8?q?=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/demo/feed/service/CommentService.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/example/demo/feed/service/CommentService.java b/src/main/java/com/example/demo/feed/service/CommentService.java index fc756ad..043a2d6 100644 --- a/src/main/java/com/example/demo/feed/service/CommentService.java +++ b/src/main/java/com/example/demo/feed/service/CommentService.java @@ -9,6 +9,7 @@ import com.example.demo.user.domain.User; import com.example.demo.user.domain.UserRepository; import com.example.demo.user.domain.Username; +import com.example.demo.user.service.UserDto; import com.example.demo.user.service.UserService; import com.example.demo.user.service.UserSessionService; import lombok.RequiredArgsConstructor; @@ -35,12 +36,12 @@ public CommentDto makeCommentByFeedIdAndContents(Long feedId, String insertedCon throw new IllegalArgumentException(); } - String[] userInfo = userService.findUserInfo(); + UserDto userInfo = userService.findUserInfo(); Long friendId = feed.getWriter().getId(); Friendship friendship = friendShipRepository.findFriendshipByFriender_FrienderIdAndFriendee_FriendeeId( PersonId.create(friendId), - PersonId.create(Long.parseLong(userInfo[0]))); + PersonId.create(userInfo.getUserId())); @@ -50,8 +51,8 @@ public CommentDto makeCommentByFeedIdAndContents(Long feedId, String insertedCon } Content content = Content.create(insertedContent); - WriterId id = WriterId.create(Long.parseLong(userInfo[0])); - WriterName wrtName = WriterName.create(userInfo[1]); + WriterId id = WriterId.create(userInfo.getUserId()); + WriterName wrtName = WriterName.create(userInfo.getUsername()); Writer writer = Writer.create(id, wrtName); Comment comment = Comment.create(writer, content); feed.enrollComment(comment); From 472743dc4ac27a57d87a3174f187ce72211f2b0f Mon Sep 17 00:00:00 2001 From: jhkim <62026666+horobito@users.noreply.github.com> Date: Tue, 4 May 2021 23:40:51 +0900 Subject: [PATCH 05/20] =?UTF-8?q?*=20FeedService=20=EC=97=90=20UserDto=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/demo/feed/service/FeedService.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/example/demo/feed/service/FeedService.java b/src/main/java/com/example/demo/feed/service/FeedService.java index 04fa166..99036cd 100644 --- a/src/main/java/com/example/demo/feed/service/FeedService.java +++ b/src/main/java/com/example/demo/feed/service/FeedService.java @@ -6,6 +6,7 @@ import com.example.demo.friend.domain.FriendShipState; import com.example.demo.friend.domain.Friendship; import com.example.demo.friend.domain.PersonId; +import com.example.demo.user.service.UserDto; import com.example.demo.user.service.UserService; import lombok.RequiredArgsConstructor; @@ -24,7 +25,7 @@ public class FeedService { @Transactional public void deleteFeedByFeedId(Long id) throws AccessDeniedException, IllegalAccessException { Feed feed = feedRepository.findFeedByIdAndDeleted(id, false); - PersonId myId = PersonId.create(Long.parseLong(userService.findUserInfo()[0])); + PersonId myId = PersonId.create(userService.findUserInfo().getUserId()); if (feed==null){ throw new IllegalArgumentException(); @@ -39,14 +40,14 @@ public void deleteFeedByFeedId(Long id) throws AccessDeniedException, IllegalAcc public FeedDto findFeedDetailByFeedId(Long id) throws AccessDeniedException, IllegalAccessException { - String[] userInfo = userService.findUserInfo(); + UserDto userInfo = userService.findUserInfo(); Feed feed = feedRepository.findFeedByIdAndDeleted(id, false); if (feed==null){ throw new IllegalArgumentException(); } - PersonId myId = PersonId.create(Long.parseLong(userInfo[0])); + PersonId myId = PersonId.create(userInfo.getUserId()); PersonId friendId = PersonId.create(feed.getId()); Friendship friendship = friendShipRepository.findFriendshipByFriender_FrienderIdAndFriendee_FriendeeId(myId, friendId); @@ -93,10 +94,10 @@ public FeedDto makeFeedByContents(String insertedTitle, String insertedContent) throw new IllegalArgumentException(); } - String[] userInfo = userService.findUserInfo(); + UserDto userInfo = userService.findUserInfo(); - WriterId id = WriterId.create(Long.parseLong(userInfo[0])); - WriterName wrtName = WriterName.create(userInfo[1]); + WriterId id = WriterId.create(userInfo.getUserId()); + WriterName wrtName = WriterName.create(userInfo.getUsername()); Writer writer = Writer.create(id, wrtName); Content content = Content.create(insertedContent); Title title = Title.create(insertedTitle); From f4f6bf54f8afb4d4e0ad97116e0405dbde9f24c4 Mon Sep 17 00:00:00 2001 From: jhkim <62026666+horobito@users.noreply.github.com> Date: Tue, 4 May 2021 23:43:39 +0900 Subject: [PATCH 06/20] =?UTF-8?q?*=20FriendShipService=20=EC=97=90=20UserD?= =?UTF-8?q?to=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../friend/service/FriendShipService.java | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/example/demo/friend/service/FriendShipService.java b/src/main/java/com/example/demo/friend/service/FriendShipService.java index 92d688a..1b8cbc0 100644 --- a/src/main/java/com/example/demo/friend/service/FriendShipService.java +++ b/src/main/java/com/example/demo/friend/service/FriendShipService.java @@ -1,6 +1,7 @@ package com.example.demo.friend.service; import com.example.demo.friend.domain.*; +import com.example.demo.user.service.UserDto; import com.example.demo.user.service.UserService; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.PageRequest; @@ -26,9 +27,9 @@ public List getMyFriends(int page, int size) throws AccessDeniedExcep throw new IllegalArgumentException(); } - String[] userInfo = userService.findUserInfo(); - PersonId userId = PersonId.create(Long.parseLong(userInfo[0])); - PersonName userName = PersonName.create(userInfo[1]); + UserDto userInfo = userService.findUserInfo(); + PersonId userId = PersonId.create(userInfo.getUserId()); + PersonName userName = PersonName.create(userInfo.getUsername()); Friender friender = Friender.create(userId, userName); @@ -49,14 +50,14 @@ public List getMyFriends(int page, int size) throws AccessDeniedExcep @Transactional public void create(Long inputedFriendId) throws AccessDeniedException { - String[] user = userService.findUserInfo(); - String [] friend = userService.findUserInfo(inputedFriendId); + UserDto userInfo = userService.findUserInfo(); + UserDto friendInfo = userService.findUserInfo(inputedFriendId); - PersonId myId = PersonId.create(Long.parseLong(user[0]) ); - PersonId friendId = PersonId.create(Long.parseLong(friend[0])); + PersonId myId = PersonId.create(userInfo.getUserId() ); + PersonId friendId = PersonId.create(friendInfo.getUserId()); - PersonName myName = PersonName.create(user[1]); - PersonName friendName = PersonName.create( friend[1]); + PersonName myName = PersonName.create(userInfo.getUsername()); + PersonName friendName = PersonName.create( friendInfo.getUsername()); Friender frienderMe = Friender.create(myId, myName); Friendee friendeeYou = Friendee.create(friendId, friendName); @@ -98,9 +99,9 @@ public void create(Long inputedFriendId) throws AccessDeniedException { public FriendShipResult deleteFriendShipRequest(Long inputedId) throws AccessDeniedException { - String[] userInfo = userService.findUserInfo(); - PersonId myId = PersonId.create(Long.parseLong(userInfo[0])); - PersonName myName = PersonName.create( userInfo[1]); + UserDto userInfo = userService.findUserInfo(); + PersonId myId = PersonId.create(userInfo.getUserId()); + PersonName myName = PersonName.create(userInfo.getUsername()); Friender myInfo = Friender.create(myId, myName); PersonId friendId = PersonId.create(inputedId); @@ -132,7 +133,7 @@ public List findRequestForMe(int page, int size) throws AccessDenied } - PersonId myId = PersonId.create(Long.parseLong(userService.findUserInfo()[0])); + PersonId myId = PersonId.create(userService.findUserInfo().getUserId()); List friendshipList = friendShipRepository.findAllByFriendee_FriendeeId(myId, PageRequest.of(page, size)) .stream() From 99b232c458d31967ab1527b0f45a57e1881db8a8 Mon Sep 17 00:00:00 2001 From: jhkim <62026666+horobito@users.noreply.github.com> Date: Tue, 4 May 2021 23:48:26 +0900 Subject: [PATCH 07/20] =?UTF-8?q?*=20PreferenceInfoService=20=EC=97=90=20U?= =?UTF-8?q?serDto=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/PreferenceInfoService.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/example/demo/preferenceinfo/service/PreferenceInfoService.java b/src/main/java/com/example/demo/preferenceinfo/service/PreferenceInfoService.java index 7d91c81..3716ee9 100644 --- a/src/main/java/com/example/demo/preferenceinfo/service/PreferenceInfoService.java +++ b/src/main/java/com/example/demo/preferenceinfo/service/PreferenceInfoService.java @@ -12,6 +12,7 @@ import com.example.demo.preferenceinfo.domain.PreferenceLocation; import com.example.demo.preferenceinfo.domain.PreferenceInfoRepository; import com.example.demo.user.domain.User; +import com.example.demo.user.service.UserDto; import com.example.demo.user.service.UserService; import com.example.demo.user.service.UserSessionService; import lombok.RequiredArgsConstructor; @@ -33,11 +34,9 @@ public class PreferenceInfoService { @Transactional public void likeFeedByFeedId(Long id) throws AccessDeniedException, IllegalAccessException { - String[] userInfo = userService.findUserInfo(); // dto 사용할 것 + UserDto userInfo = userService.findUserInfo(); // dto 사용할 것 Feed feed; - - // 변수는 final 처럼 작성이 깔끔 // 변수의 초기화는 참조가 계속 바뀌기 때문에, 런타임에 이해 어려움 // 초기화는 왠만해서는 딱 1번만 @@ -46,24 +45,24 @@ public void likeFeedByFeedId(Long id) throws AccessDeniedException, IllegalAcces throw new NullPointerException();// 고칠 것 -> IllegalStateException() 등, 또는 IlliArgument xxx[id 값 오류] } - if (feed.getWriter().getId().equals(Long.parseLong(userInfo[0]))){ + if (feed.getWriter().getId().equals(userInfo.getUserId())){ throw new IllegalAccessException(); } if ((friendShipRepository.findFriendshipByFriender_FrienderIdAndFriendee_FriendeeId( - PersonId.create(Long.parseLong(userInfo[0])), PersonId.create(feed.getWriter().getId())))==null){ + PersonId.create(userInfo.getUserId()), PersonId.create(feed.getWriter().getId())))==null){ throw new IllegalStateException(); } PreferenceInfo preferenceInfo = preferenceInfoRepository - .findByDocumentIdAndPreferredPersonIdAndLocation(feed.getId(), Long.parseLong(userInfo[0]), PreferenceLocation.FEED); + .findByDocumentIdAndPreferredPersonIdAndLocation(feed.getId(), userInfo.getUserId(), PreferenceLocation.FEED); // 비지니스 예외 방식에 예외처리를 담는 것은 좋은 방식이 아니다 . - 비쌈 if (preferenceInfo==null){ - preferenceInfo = PreferenceInfo.create(Long.parseLong(userInfo[0]), feed.getId()); + preferenceInfo = PreferenceInfo.create(userInfo.getUserId(), feed.getId()); preferenceInfo.locate(PreferenceLocation.FEED); preferenceInfo.like(); preferenceInfoRepository.save(preferenceInfo); @@ -91,7 +90,7 @@ public void likeFeedByFeedId(Long id) throws AccessDeniedException, IllegalAcces @Transactional public void likeCommentByFeedIdAndCommentId(Long feedId, Long commentId) throws AccessDeniedException { - String[] userInfo = userService.findUserInfo(); + UserDto userInfo = userService.findUserInfo(); Feed feed = feedRepository.findFeedByIdAndDeleted(feedId, false); @@ -106,16 +105,16 @@ public void likeCommentByFeedIdAndCommentId(Long feedId, Long commentId) throws } if (friendShipRepository.findFriendshipByFriender_FrienderIdAndFriendee_FriendeeId( - PersonId.create(Long.parseLong(userInfo[0])), PersonId.create(feed.getWriter().getId()))==null){ + PersonId.create(userInfo.getUserId()), PersonId.create(feed.getWriter().getId()))==null){ throw new IllegalStateException(); } PreferenceInfo preferenceInfo = preferenceInfoRepository - .findByDocumentIdAndPreferredPersonIdAndLocation(comment.getId(), Long.parseLong(userInfo[0]), PreferenceLocation.COMMENT); + .findByDocumentIdAndPreferredPersonIdAndLocation(comment.getId(), userInfo.getUserId(), PreferenceLocation.COMMENT); if (preferenceInfo ==null){ - preferenceInfo = PreferenceInfo.create(Long.parseLong(userInfo[0]), comment.getId()); + preferenceInfo = PreferenceInfo.create(userInfo.getUserId(), comment.getId()); preferenceInfo.locate(PreferenceLocation.COMMENT); preferenceInfo.like(); preferenceInfoRepository.save(preferenceInfo); From 79ffc3cf57c0301caf1c84e2c79e4adfb5ae406e Mon Sep 17 00:00:00 2001 From: jhkim <62026666+horobito@users.noreply.github.com> Date: Tue, 4 May 2021 23:49:51 +0900 Subject: [PATCH 08/20] =?UTF-8?q?*=20TimeLineService=20=EC=97=90=20UserDto?= =?UTF-8?q?=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/demo/timeline/service/TimeLineService.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/demo/timeline/service/TimeLineService.java b/src/main/java/com/example/demo/timeline/service/TimeLineService.java index 7a92116..16f8f40 100644 --- a/src/main/java/com/example/demo/timeline/service/TimeLineService.java +++ b/src/main/java/com/example/demo/timeline/service/TimeLineService.java @@ -6,6 +6,7 @@ import com.example.demo.feed.service.FeedDto; import com.example.demo.friend.domain.*; import com.example.demo.user.domain.User; +import com.example.demo.user.service.UserDto; import com.example.demo.user.service.UserService; import com.example.demo.user.service.UserSessionService; import lombok.RequiredArgsConstructor; @@ -31,9 +32,9 @@ public List findMyTimeLine(int page, int pageSize) throws AccessDeniedE throw new IllegalArgumentException(); } - String [] userInfo = userService.findUserInfo(); - PersonId myId = PersonId.create(Long.parseLong(userInfo[0])); - PersonName myName = PersonName.create(userInfo[1]); + UserDto userInfo = userService.findUserInfo(); + PersonId myId = PersonId.create(userInfo.getUserId()); + PersonName myName = PersonName.create(userInfo.getUsername()); Friender user = Friender.create(myId, myName); List writerList = From b315eda313d95e146ef4497e23e14ce15806c4cb Mon Sep 17 00:00:00 2001 From: jhkim <62026666+horobito@users.noreply.github.com> Date: Tue, 4 May 2021 23:59:53 +0900 Subject: [PATCH 09/20] =?UTF-8?q?*=20CreateCommentTest=20=EC=97=90=20UserD?= =?UTF-8?q?to=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/feed/service/CreateCommentTest.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/test/java/com/example/demo/feed/service/CreateCommentTest.java b/src/test/java/com/example/demo/feed/service/CreateCommentTest.java index feff8a7..1c13c5a 100644 --- a/src/test/java/com/example/demo/feed/service/CreateCommentTest.java +++ b/src/test/java/com/example/demo/feed/service/CreateCommentTest.java @@ -3,6 +3,7 @@ import com.example.demo.feed.domain.*; import com.example.demo.friend.domain.*; +import com.example.demo.user.service.UserDto; import com.example.demo.user.service.UserService; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -86,7 +87,9 @@ void test3() throws AccessDeniedException { Long commentId = Long.parseLong("3"); String commentContent = "asdf"; - String[] person1Info = {"1", "hello"}; + + Long id1 = Long.parseLong("1"); + UserDto person1Info = UserDto.create(id1,"hello"); Long friendId = Long.parseLong("3"); String friendName = "hhhh"; @@ -100,10 +103,10 @@ void test3() throws AccessDeniedException { Title title = Title.create("This is title"); Feed feed = FeedHelper.create(feedId, writer, title, content); - PersonId person1Id = PersonId.create(Long.parseLong(person1Info[0])); + PersonId person1Id = PersonId.create(person1Info.getUserId()); PersonId person2Id = PersonId.create(friendId); - PersonName person1Name = PersonName.create( person1Info[1]); + PersonName person1Name = PersonName.create(person1Info.getUsername()); PersonName person2Name = PersonName.create( friendName); Friender friender = Friender.create(person1Id, person1Name); @@ -131,7 +134,9 @@ void test4() throws AccessDeniedException { Long commentId = Long.parseLong("3"); String commentContent = "asdf"; - String[] person1Info = {"1", "hello"}; + + Long id1 = Long.parseLong("1"); + UserDto person1Info = UserDto.create(id1,"hello"); Long friendId = Long.parseLong("3"); String friendName = "hhhh"; @@ -145,10 +150,10 @@ void test4() throws AccessDeniedException { Title title = Title.create("This is title"); Feed feed = FeedHelper.create(feedId, writer, title, content); - PersonId person1Id = PersonId.create(Long.parseLong(person1Info[0])); + PersonId person1Id = PersonId.create(person1Info.getUserId()); PersonId person2Id = PersonId.create(friendId); - PersonName person1Name = PersonName.create( person1Info[1]); + PersonName person1Name = PersonName.create(person1Info.getUsername()); PersonName person2Name = PersonName.create( friendName); Friender friender = Friender.create(person1Id, person1Name); @@ -181,7 +186,8 @@ void test5() throws AccessDeniedException, IllegalAccessException { Long commentId = Long.parseLong("3"); String commentContent = "나오면 성공"; - String[] person1Info = {"1", "hello"}; + Long id1 = Long.parseLong("1"); + UserDto person1Info = UserDto.create(id1,"hello"); Long friendId = Long.parseLong("3"); String friendName = "hhhh"; @@ -195,10 +201,10 @@ void test5() throws AccessDeniedException, IllegalAccessException { Title title = Title.create("This is title"); Feed feed = FeedHelper.create(feedId, writer, title, content); - PersonId person1Id = PersonId.create(Long.parseLong(person1Info[0])); + PersonId person1Id = PersonId.create(person1Info.getUserId()); PersonId person2Id = PersonId.create(friendId); - PersonName person1Name = PersonName.create( person1Info[1]); + PersonName person1Name = PersonName.create(person1Info.getUsername()); PersonName person2Name = PersonName.create( friendName); Friender friender = Friender.create(person1Id, person1Name); From 7027f104f148c7a9bf9f0569c227fef8a921a065 Mon Sep 17 00:00:00 2001 From: jhkim <62026666+horobito@users.noreply.github.com> Date: Wed, 5 May 2021 00:00:39 +0900 Subject: [PATCH 10/20] =?UTF-8?q?*=20CreateFeedTest=20=EC=97=90=20UserDto?= =?UTF-8?q?=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/demo/feed/service/CreateFeedTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/example/demo/feed/service/CreateFeedTest.java b/src/test/java/com/example/demo/feed/service/CreateFeedTest.java index 59e6e3d..b6ea56e 100644 --- a/src/test/java/com/example/demo/feed/service/CreateFeedTest.java +++ b/src/test/java/com/example/demo/feed/service/CreateFeedTest.java @@ -4,6 +4,7 @@ import com.example.demo.feed.domain.FeedRepository; import com.example.demo.feed.domain.Title; import com.example.demo.friend.domain.FriendShipRepository; +import com.example.demo.user.service.UserDto; import com.example.demo.user.service.UserService; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -39,7 +40,6 @@ void test1() throws AccessDeniedException { userService ); - String[] person1 = {"1" , "jihwan"}; String title = ""; @@ -63,7 +63,8 @@ void test2() throws AccessDeniedException { userService ); - String[] person1Info = {"1" , "jihwan"}; + Long id1 = Long.parseLong("1"); + UserDto person1Info = UserDto.create(id1,"hello"); String title = "title1"; From b15afaf328273d303880a12ceace7e1fb055903f Mon Sep 17 00:00:00 2001 From: jhkim <62026666+horobito@users.noreply.github.com> Date: Wed, 5 May 2021 00:01:23 +0900 Subject: [PATCH 11/20] =?UTF-8?q?*=20DeleteFeedTest=20=EC=97=90=20UserDto?= =?UTF-8?q?=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/demo/feed/service/DeleteFeedTest.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/example/demo/feed/service/DeleteFeedTest.java b/src/test/java/com/example/demo/feed/service/DeleteFeedTest.java index 5be6277..9627a11 100644 --- a/src/test/java/com/example/demo/feed/service/DeleteFeedTest.java +++ b/src/test/java/com/example/demo/feed/service/DeleteFeedTest.java @@ -3,6 +3,7 @@ import com.example.demo.feed.domain.*; import com.example.demo.friend.domain.FriendShipRepository; +import com.example.demo.user.service.UserDto; import com.example.demo.user.service.UserService; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -38,7 +39,8 @@ void test1() throws AccessDeniedException { userService ); - String[] person1 = {"1" , "jihwan"}; + Long id1 = Long.parseLong("1"); + UserDto person1 = UserDto.create(id1,"hello"); String title = ""; @@ -63,7 +65,8 @@ void test2() throws AccessDeniedException { userService ); - String[] userInfo = {"1", "hello"}; + Long id1 = Long.parseLong("1"); + UserDto userInfo= UserDto.create(id1,"hello"); Long friendId = Long.parseLong("3"); From 33cc14935d07980f5fc0266d86d038935f651d05 Mon Sep 17 00:00:00 2001 From: jhkim <62026666+horobito@users.noreply.github.com> Date: Wed, 5 May 2021 00:02:40 +0900 Subject: [PATCH 12/20] =?UTF-8?q?*=20FindFeedDetailTest=20=EC=97=90=20User?= =?UTF-8?q?Dto=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/feed/service/FindFeedDetailTest.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/example/demo/feed/service/FindFeedDetailTest.java b/src/test/java/com/example/demo/feed/service/FindFeedDetailTest.java index d890b4f..e2fd3e7 100644 --- a/src/test/java/com/example/demo/feed/service/FindFeedDetailTest.java +++ b/src/test/java/com/example/demo/feed/service/FindFeedDetailTest.java @@ -3,6 +3,7 @@ import com.example.demo.feed.domain.*; import com.example.demo.friend.domain.*; +import com.example.demo.user.service.UserDto; import com.example.demo.user.service.UserService; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -40,7 +41,8 @@ void test1() throws AccessDeniedException { - String[] person1 = {"1" , "jihwan"}; + Long id1 = Long.parseLong("1"); + UserDto person1 = UserDto.create(id1,"hello"); Long id = Long.parseLong("2"); @@ -63,7 +65,8 @@ void test2() throws AccessDeniedException { userService ); - String[] person1Info = {"1", "hello"}; + Long id1 = Long.parseLong("1"); + UserDto person1Info = UserDto.create(id1,"hello"); Long friendId = Long.parseLong("3"); String friendName = "hhhh"; @@ -73,10 +76,10 @@ void test2() throws AccessDeniedException { WriterName writerName = WriterName.create("writerName"); Writer writer = Writer.create(writerId, writerName); - PersonId person1Id = PersonId.create(Long.parseLong(person1Info[0])); + PersonId person1Id = PersonId.create(person1Info.getUserId()); PersonId person2Id = PersonId.create(friendId); - PersonName person1Name = PersonName.create( person1Info[1]); + PersonName person1Name = PersonName.create(person1Info.getUsername()); PersonName person2Name = PersonName.create( friendName); @@ -119,7 +122,8 @@ void test3() throws AccessDeniedException, IllegalAccessException { userService ); - String[] person1Info = {"1", "hello"}; + Long id1 = Long.parseLong("1"); + UserDto person1Info = UserDto.create(id1,"hello"); Long friendId = Long.parseLong("3"); String friendName = "hhhh"; @@ -133,10 +137,10 @@ void test3() throws AccessDeniedException, IllegalAccessException { Title title = Title.create("This is title"); Feed feed = FeedHelper.create(feedId, writer, title, content); - PersonId person1Id = PersonId.create(Long.parseLong(person1Info[0])); + PersonId person1Id = PersonId.create(person1Info.getUserId()); PersonId person2Id = PersonId.create(friendId); - PersonName person1Name = PersonName.create( person1Info[1]); + PersonName person1Name = PersonName.create(person1Info.getUsername()); PersonName person2Name = PersonName.create( friendName); Comment comment1 = Comment.create(writer, content); From 09bc84ffb71071d67eb46d05313c9f16b54ec99c Mon Sep 17 00:00:00 2001 From: jhkim <62026666+horobito@users.noreply.github.com> Date: Wed, 5 May 2021 00:05:22 +0900 Subject: [PATCH 13/20] =?UTF-8?q?*=20FriendShipCreateTest=20=EC=97=90=20Us?= =?UTF-8?q?erDto=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../friend/service/FriendShipCreateTest.java | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/test/java/com/example/demo/friend/service/FriendShipCreateTest.java b/src/test/java/com/example/demo/friend/service/FriendShipCreateTest.java index 790210a..4479bf2 100644 --- a/src/test/java/com/example/demo/friend/service/FriendShipCreateTest.java +++ b/src/test/java/com/example/demo/friend/service/FriendShipCreateTest.java @@ -6,6 +6,7 @@ import com.example.demo.user.domain.User; import com.example.demo.user.domain.UserRepository; import com.example.demo.user.domain.Username; +import com.example.demo.user.service.UserDto; import com.example.demo.user.service.UserService; import com.example.demo.user.service.UserSessionService; import org.junit.jupiter.api.DisplayName; @@ -45,8 +46,12 @@ void createFriendShip() throws AccessDeniedException { //given - String[] friender = { "1", "jihwan"}; - String [] friendee = { "2", "friendee"}; + + Long id1 = Long.parseLong("1"); + UserDto friender = UserDto.create(id1,"jihwan"); + + Long id2 = Long.parseLong("1"); + UserDto friendee = UserDto.create(id2,"friendee"); Long friendId = Long.parseLong("1"); //when @@ -74,14 +79,17 @@ void testForAlreadyAccept() throws AccessDeniedException { //given - String[] friender = { "1", "jihwan"}; - String [] friendee = { "2", "friendee"}; + Long id1 = Long.parseLong("1"); + UserDto friender = UserDto.create(id1,"jihwan"); - PersonId myId = PersonId.create(Long.parseLong(friender[0]) ); - PersonId friendId = PersonId.create(Long.parseLong(friendee[0])); + Long id2 = Long.parseLong("1"); + UserDto friendee = UserDto.create(id2,"friendee"); - PersonName myName = PersonName.create(friender[1]); - PersonName friendName = PersonName.create(friendee[1]); + PersonId myId = PersonId.create(friender.getUserId() ); + PersonId friendId = PersonId.create(friendee.getUserId()); + + PersonName myName = PersonName.create(friendee.getUsername()); + PersonName friendName = PersonName.create(friendee.getUsername()); Friender frienderMe = Friender.create(myId, myName); Friendee friendeeYou = Friendee.create(friendId, friendName); @@ -128,14 +136,17 @@ void testForAccept() throws AccessDeniedException { //given - String[] friender = { "1", "jihwan"}; - String [] friendee = { "2", "friendee"}; + Long id1 = Long.parseLong("1"); + UserDto friender = UserDto.create(id1,"jihwan"); + + Long id2 = Long.parseLong("1"); + UserDto friendee = UserDto.create(id2,"friendee"); - PersonId myId = PersonId.create(Long.parseLong(friender[0]) ); - PersonId friendId = PersonId.create(Long.parseLong(friendee[0])); + PersonId myId = PersonId.create(friender.getUserId() ); + PersonId friendId = PersonId.create(friendee.getUserId()); - PersonName myName = PersonName.create((String) friender[1]); - PersonName friendName = PersonName.create((String) friendee[1]); + PersonName myName = PersonName.create(friender.getUsername()); + PersonName friendName = PersonName.create((friendee.getUsername())); Friender frienderMe = Friender.create(myId, myName); Friendee friendeeYou = Friendee.create(friendId, friendName); From ddee3b9e7d4981418789067564d795b560f90653 Mon Sep 17 00:00:00 2001 From: jhkim <62026666+horobito@users.noreply.github.com> Date: Wed, 5 May 2021 00:06:46 +0900 Subject: [PATCH 14/20] =?UTF-8?q?*=20FriendShipDeleteTest=20=EC=97=90=20Us?= =?UTF-8?q?erDto=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../friend/service/FriendShipDeleteTest.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/example/demo/friend/service/FriendShipDeleteTest.java b/src/test/java/com/example/demo/friend/service/FriendShipDeleteTest.java index 5b4c14e..bc807b3 100644 --- a/src/test/java/com/example/demo/friend/service/FriendShipDeleteTest.java +++ b/src/test/java/com/example/demo/friend/service/FriendShipDeleteTest.java @@ -4,6 +4,7 @@ import com.example.demo.friend.domain.*; import com.example.demo.user.domain.User; import com.example.demo.user.domain.UserRepository; +import com.example.demo.user.service.UserDto; import com.example.demo.user.service.UserService; import com.example.demo.user.service.UserSessionService; import org.junit.jupiter.api.DisplayName; @@ -51,7 +52,9 @@ void testForDeleteFail() throws AccessDeniedException { //given - String[] friender= {"1", "jihwan"}; + Long id1 = Long.parseLong("1"); + UserDto friender = UserDto.create(id1,"jihwan"); + //when when(userService.findUserInfo()).thenReturn(friender); @@ -72,14 +75,17 @@ void testForAccept() throws AccessDeniedException { //given - String[] friender = {"1", "jihwan"}; - String[] friendee = {"2", "friendee"}; + Long id1 = Long.parseLong("1"); + UserDto friender = UserDto.create(id1,"jihwan"); + + Long id2 = Long.parseLong("1"); + UserDto friendee = UserDto.create(id2,"friendee"); - PersonId myId = PersonId.create(Long.parseLong(friender[0])); - PersonId friendId = PersonId.create(Long.parseLong(friendee[0])); + PersonId myId = PersonId.create(friender.getUserId()); + PersonId friendId = PersonId.create(friendee.getUserId()); - PersonName myName = PersonName.create(friender[1]); - PersonName friendName = PersonName.create(friendee[1]); + PersonName myName = PersonName.create(friender.getUsername()); + PersonName friendName = PersonName.create(friendee.getUsername()); Friender frienderMe = Friender.create(myId, myName); Friendee friendeeYou = Friendee.create(friendId, friendName); From 64c88b27edc82f960c0fceaeff4ef555860fff5e Mon Sep 17 00:00:00 2001 From: jhkim <62026666+horobito@users.noreply.github.com> Date: Wed, 5 May 2021 00:10:56 +0900 Subject: [PATCH 15/20] =?UTF-8?q?*=20FriendShipFindTest=20=EC=97=90=20User?= =?UTF-8?q?Dto=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../friend/service/FriendShipFindTest.java | 96 +++++++++++-------- 1 file changed, 58 insertions(+), 38 deletions(-) diff --git a/src/test/java/com/example/demo/friend/service/FriendShipFindTest.java b/src/test/java/com/example/demo/friend/service/FriendShipFindTest.java index fbb0bcd..34977fe 100644 --- a/src/test/java/com/example/demo/friend/service/FriendShipFindTest.java +++ b/src/test/java/com/example/demo/friend/service/FriendShipFindTest.java @@ -2,6 +2,7 @@ import com.example.demo.friend.domain.*; +import com.example.demo.user.service.UserDto; import com.example.demo.user.service.UserService; import org.junit.jupiter.api.DisplayName; @@ -33,6 +34,8 @@ public class FriendShipFindTest { @Mock UserService userService; + + // 성공 @DisplayName("친구관계 요청 확인 테스트1. 알맞은 요청 테스트 || 잘못된 페이지 번호 또는 크기 ") @Test @@ -44,20 +47,26 @@ void testForAccept() throws AccessDeniedException { //given - String[] person1Info = { "1", "person1"}; - String [] person2Info = { "2", "person2"}; - String [] person3Info = {"3", "person3"}; - String [] person4Info = {"4", "person4"}; - PersonId person1Id = PersonId.create(Long.parseLong(person1Info[0]) ); - PersonId person2Id = PersonId.create(Long.parseLong( person2Info[0])); - PersonId person3Id = PersonId.create(Long.parseLong(person3Info[0])); - PersonId person4Id = PersonId.create(Long.parseLong(person4Info[0])); + Long id1 = Long.parseLong("1"); + UserDto person1Info = UserDto.create(id1,"person1"); + Long id2 = Long.parseLong("2"); + UserDto person2Info = UserDto.create(id2,"person2"); + Long id3 = Long.parseLong("3"); + UserDto person3Info = UserDto.create(id3,"person3"); + Long id4 = Long.parseLong("4"); + UserDto person4Info = UserDto.create(id4,"person4"); + + + PersonId person1Id = PersonId.create(person1Info.getUserId() ); + PersonId person2Id = PersonId.create(person2Info.getUserId()); + PersonId person3Id = PersonId.create(person3Info.getUserId()); + PersonId person4Id = PersonId.create(person4Info.getUserId()); - PersonName person1Name = PersonName.create( person1Info[1]); - PersonName person2Name = PersonName.create( person2Info[1]); - PersonName person3Name = PersonName.create(person3Info[1]); - PersonName person4Name = PersonName.create(person4Info[1]); + PersonName person1Name = PersonName.create( person1Info.getUsername()); + PersonName person2Name = PersonName.create( person2Info.getUsername()); + PersonName person3Name = PersonName.create(person3Info.getUsername()); + PersonName person4Name = PersonName.create(person4Info.getUsername()); Friender friender1 = Friender.create(person1Id, person1Name); Friender friender2 = Friender.create(person2Id, person2Name); @@ -69,6 +78,7 @@ void testForAccept() throws AccessDeniedException { Friendee friendee3 = Friendee.create(person3Id, person3Name); Friendee friendee4 = Friendee.create(person4Id, person4Name); + Friendship forwardFriendship1 = Friendship.create(friender4, friendee1); forwardFriendship1.requestFriendShip(); @@ -122,20 +132,25 @@ void test2() throws AccessDeniedException { //given - String[] person1Info = { "1", "person1"}; - String [] person2Info = { "2", "person2"}; - String [] person3Info = {"3", "person3"}; - String [] person4Info = {"4", "person4"}; + Long id1 = Long.parseLong("1"); + UserDto person1Info = UserDto.create(id1,"person1"); + Long id2 = Long.parseLong("2"); + UserDto person2Info = UserDto.create(id2,"person2"); + Long id3 = Long.parseLong("3"); + UserDto person3Info = UserDto.create(id3,"person3"); + Long id4 = Long.parseLong("4"); + UserDto person4Info = UserDto.create(id4,"person4"); + - PersonId person1Id = PersonId.create(Long.parseLong(person1Info[0]) ); - PersonId person2Id = PersonId.create(Long.parseLong( person2Info[0])); - PersonId person3Id = PersonId.create(Long.parseLong(person3Info[0])); - PersonId person4Id = PersonId.create(Long.parseLong(person4Info[0])); + PersonId person1Id = PersonId.create(person1Info.getUserId() ); + PersonId person2Id = PersonId.create(person2Info.getUserId()); + PersonId person3Id = PersonId.create(person3Info.getUserId()); + PersonId person4Id = PersonId.create(person4Info.getUserId()); - PersonName person1Name = PersonName.create( person1Info[1]); - PersonName person2Name = PersonName.create( person2Info[1]); - PersonName person3Name = PersonName.create(person3Info[1]); - PersonName person4Name = PersonName.create(person4Info[1]); + PersonName person1Name = PersonName.create( person1Info.getUsername()); + PersonName person2Name = PersonName.create( person2Info.getUsername()); + PersonName person3Name = PersonName.create(person3Info.getUsername()); + PersonName person4Name = PersonName.create(person4Info.getUsername()); Friender friender1 = Friender.create(person1Id, person1Name); Friender friender2 = Friender.create(person2Id, person2Name); @@ -201,20 +216,25 @@ void testForSearchingFriendList1() throws AccessDeniedException { //given - String[] person1Info = { "1", "person1"}; - String [] person2Info = { "2", "person2"}; - String [] person3Info = {"3", "person3"}; - String [] person4Info = {"4", "person4"}; - - PersonId person1Id = PersonId.create(Long.parseLong(person1Info[0]) ); - PersonId person2Id = PersonId.create(Long.parseLong( person2Info[0])); - PersonId person3Id = PersonId.create(Long.parseLong(person3Info[0])); - PersonId person4Id = PersonId.create(Long.parseLong(person4Info[0])); - - PersonName person1Name = PersonName.create( person1Info[1]); - PersonName person2Name = PersonName.create( person2Info[1]); - PersonName person3Name = PersonName.create(person3Info[1]); - PersonName person4Name = PersonName.create(person4Info[1]); + Long id1 = Long.parseLong("1"); + UserDto person1Info = UserDto.create(id1,"person1"); + Long id2 = Long.parseLong("2"); + UserDto person2Info = UserDto.create(id2,"person2"); + Long id3 = Long.parseLong("3"); + UserDto person3Info = UserDto.create(id3,"person3"); + Long id4 = Long.parseLong("4"); + UserDto person4Info = UserDto.create(id4,"person4"); + + + PersonId person1Id = PersonId.create(person1Info.getUserId() ); + PersonId person2Id = PersonId.create(person2Info.getUserId()); + PersonId person3Id = PersonId.create(person3Info.getUserId()); + PersonId person4Id = PersonId.create(person4Info.getUserId()); + + PersonName person1Name = PersonName.create( person1Info.getUsername()); + PersonName person2Name = PersonName.create( person2Info.getUsername()); + PersonName person3Name = PersonName.create(person3Info.getUsername()); + PersonName person4Name = PersonName.create(person4Info.getUsername()); Friender friender1 = Friender.create(person1Id, person1Name); Friender friender2 = Friender.create(person2Id, person2Name); From 069c323815d0b12aacb15f544a8c40ee00eb668d Mon Sep 17 00:00:00 2001 From: jhkim <62026666+horobito@users.noreply.github.com> Date: Wed, 5 May 2021 00:12:28 +0900 Subject: [PATCH 16/20] =?UTF-8?q?*=20CommentLikeTest=20=EC=97=90=20UserDto?= =?UTF-8?q?=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/CommentLikeTest.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/example/demo/preferenceinfo/service/CommentLikeTest.java b/src/test/java/com/example/demo/preferenceinfo/service/CommentLikeTest.java index 97a434c..e3e62af 100644 --- a/src/test/java/com/example/demo/preferenceinfo/service/CommentLikeTest.java +++ b/src/test/java/com/example/demo/preferenceinfo/service/CommentLikeTest.java @@ -8,6 +8,7 @@ import com.example.demo.friend.domain.PersonId; import com.example.demo.preferenceinfo.domain.PreferenceInfo; import com.example.demo.preferenceinfo.domain.PreferenceInfoRepository; +import com.example.demo.user.service.UserDto; import com.example.demo.user.service.UserService; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -53,7 +54,8 @@ void test1() throws AccessDeniedException { commentService ); - String[] userInfo = {"1", "hello"}; + Long id1 = Long.parseLong("1"); + UserDto userInfo = UserDto.create(id1,"hello"); Long userId = Long.parseLong("1"); @@ -86,7 +88,8 @@ void test2() throws AccessDeniedException { commentService ); - String[] userInfo = {"1", "hello"}; + Long id1 = Long.parseLong("1"); + UserDto userInfo = UserDto.create(id1,"hello"); Long userId = Long.parseLong("1"); @@ -140,7 +143,8 @@ void test3() throws AccessDeniedException { commentService ); - String[] userInfo = {"1", "hello"}; + Long id1 = Long.parseLong("1"); + UserDto userInfo = UserDto.create(id1,"hello"); Long userId = Long.parseLong("1"); @@ -200,7 +204,8 @@ void test4() throws AccessDeniedException { commentService ); - String[] userInfo = {"1", "hello"}; + Long id1 = Long.parseLong("1"); + UserDto userInfo = UserDto.create(id1,"hello"); Long userId = Long.parseLong("1"); @@ -264,7 +269,8 @@ void test5() throws AccessDeniedException { commentService ); - String[] userInfo = {"1", "hello"}; + Long id1 = Long.parseLong("1"); + UserDto userInfo = UserDto.create(id1,"hello"); Long userId = Long.parseLong("1"); @@ -344,7 +350,8 @@ void test6() throws AccessDeniedException { commentService ); - String[] userInfo = {"1", "hello"}; + Long id1 = Long.parseLong("1"); + UserDto userInfo = UserDto.create(id1,"hello"); Long userId = Long.parseLong("1"); From 4c2d20dee5f5495225d1f0509b128a96a0c73e57 Mon Sep 17 00:00:00 2001 From: jhkim <62026666+horobito@users.noreply.github.com> Date: Wed, 5 May 2021 00:13:31 +0900 Subject: [PATCH 17/20] =?UTF-8?q?*=20FeedLikeTest=20=EC=97=90=20UserDto=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../preferenceinfo/service/FeedLikeTest.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/example/demo/preferenceinfo/service/FeedLikeTest.java b/src/test/java/com/example/demo/preferenceinfo/service/FeedLikeTest.java index 09496c6..0a36359 100644 --- a/src/test/java/com/example/demo/preferenceinfo/service/FeedLikeTest.java +++ b/src/test/java/com/example/demo/preferenceinfo/service/FeedLikeTest.java @@ -9,6 +9,7 @@ import com.example.demo.preferenceinfo.domain.PreferenceInfoRepository; import com.example.demo.preferenceinfo.domain.PreferenceLocation; import com.example.demo.preferenceinfo.domain.PreferenceStatus; +import com.example.demo.user.service.UserDto; import com.example.demo.user.service.UserService; import com.example.demo.user.service.UserSessionService; import org.junit.jupiter.api.DisplayName; @@ -55,7 +56,8 @@ void firstTest() throws AccessDeniedException { commentService ); - String[] userInfo = {"1", "hello"}; + Long id1 = Long.parseLong("1"); + UserDto userInfo = UserDto.create(id1,"hello"); //when @@ -81,7 +83,8 @@ void secondTest() throws AccessDeniedException { commentService ); - String[] userInfo = {"1", "hello"}; + Long id1 = Long.parseLong("1"); + UserDto userInfo = UserDto.create(id1,"hello"); WriterId writerId = WriterId.create(1L); WriterName writerName = WriterName.create("tempWriter"); @@ -120,7 +123,8 @@ void thirdTest() throws AccessDeniedException { commentService ); - String[] userInfo = {"1", "hello"}; + Long id1 = Long.parseLong("1"); + UserDto userInfo = UserDto.create(id1,"hello"); Long id = Long.parseLong("1"); @@ -160,8 +164,8 @@ void test4() throws AccessDeniedException, IllegalAccessException { commentService ); - String[] userInfo = {"1", "hello"}; - + Long id1 = Long.parseLong("1"); + UserDto userInfo = UserDto.create(id1,"hello"); Long userId = Long.parseLong("1"); Long friendId = Long.parseLong("3"); @@ -236,7 +240,8 @@ void test5() throws AccessDeniedException, IllegalAccessException { commentService ); - String[] userInfo = {"1", "hello"}; + Long id1 = Long.parseLong("1"); + UserDto userInfo = UserDto.create(id1,"hello"); Long userId = Long.parseLong("1"); From 1fb17f513aa01be25f248d639ad6ad5bf0a6ed60 Mon Sep 17 00:00:00 2001 From: jhkim <62026666+horobito@users.noreply.github.com> Date: Wed, 5 May 2021 00:30:09 +0900 Subject: [PATCH 18/20] =?UTF-8?q?*=20FeedService=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/feed/service/FeedService.java | 58 +++++++++++-------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/example/demo/feed/service/FeedService.java b/src/main/java/com/example/demo/feed/service/FeedService.java index 99036cd..2536ec6 100644 --- a/src/main/java/com/example/demo/feed/service/FeedService.java +++ b/src/main/java/com/example/demo/feed/service/FeedService.java @@ -49,17 +49,49 @@ public FeedDto findFeedDetailByFeedId(Long id) throws AccessDeniedException, Ill PersonId myId = PersonId.create(userInfo.getUserId()); PersonId friendId = PersonId.create(feed.getId()); - Friendship friendship = friendShipRepository.findFriendshipByFriender_FrienderIdAndFriendee_FriendeeId(myId, friendId); - + Friendship friendship = findFriendShip(myId, friendId); if (friendship==null || friendship.getFriendState()!=FriendShipState.ACCEPT){ throw new IllegalAccessException(); } + FeedDto feedDto = toFeedDto(feed); + return feedDto; + } + + + private Friendship findFriendShip(PersonId myId, PersonId friendId) { + return friendShipRepository.findFriendshipByFriender_FrienderIdAndFriendee_FriendeeId(myId, friendId); + } + + + public FeedDto makeFeedByContents(String insertedTitle, String insertedContent) throws AccessDeniedException { + + if (insertedTitle.length()==0){ + throw new IllegalArgumentException(); + } + + UserDto userInfo = userService.findUserInfo(); + Writer writer = createWriter(userInfo); + Feed feed = createFeed(insertedContent, insertedTitle, writer); + feedRepository.save(feed); FeedDto feedDto = toFeedDto(feed); return feedDto; + + } + + private Feed createFeed(String insertedContent, String insertedTitle ,Writer writer) { + Content content = Content.create(insertedContent); + Title title = Title.create(insertedTitle); + return Feed.create(writer, title, content); + } + + private Writer createWriter(UserDto userInfo) { + WriterId id = WriterId.create(userInfo.getUserId()); + WriterName wrtName = WriterName.create(userInfo.getUsername()); + return Writer.create(id, wrtName); } private FeedDto toFeedDto(Feed feed) { @@ -88,28 +120,6 @@ private CommentDto toCommentDto(Comment comment){ } - public FeedDto makeFeedByContents(String insertedTitle, String insertedContent) throws AccessDeniedException { - - if (insertedTitle.length()==0){ - throw new IllegalArgumentException(); - } - - UserDto userInfo = userService.findUserInfo(); - - WriterId id = WriterId.create(userInfo.getUserId()); - WriterName wrtName = WriterName.create(userInfo.getUsername()); - Writer writer = Writer.create(id, wrtName); - Content content = Content.create(insertedContent); - Title title = Title.create(insertedTitle); - Feed feed = Feed.create(writer, title, content); - feedRepository.save(feed); - - FeedDto feedDto = toFeedDto(feed); - return feedDto; - - } - - From fbc887bb1132ac6491f626233abf05da5ee36480 Mon Sep 17 00:00:00 2001 From: jhkim <62026666+horobito@users.noreply.github.com> Date: Wed, 5 May 2021 00:36:04 +0900 Subject: [PATCH 19/20] =?UTF-8?q?*=20CommentService=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/feed/service/CommentService.java | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/example/demo/feed/service/CommentService.java b/src/main/java/com/example/demo/feed/service/CommentService.java index 043a2d6..7d3bd83 100644 --- a/src/main/java/com/example/demo/feed/service/CommentService.java +++ b/src/main/java/com/example/demo/feed/service/CommentService.java @@ -35,33 +35,42 @@ public CommentDto makeCommentByFeedIdAndContents(Long feedId, String insertedCon if (insertedContent.length()==0 || feed==null){ throw new IllegalArgumentException(); } - UserDto userInfo = userService.findUserInfo(); - Long friendId = feed.getWriter().getId(); - Friendship friendship - = friendShipRepository.findFriendshipByFriender_FrienderIdAndFriendee_FriendeeId( - PersonId.create(friendId), - PersonId.create(userInfo.getUserId())); - + Friendship friendship = findFriendShip(feed, userInfo); if (friendship==null || friendship.getFriendState()!= FriendShipState.ACCEPT){ throw new IllegalAccessException(); } - - Content content = Content.create(insertedContent); - WriterId id = WriterId.create(userInfo.getUserId()); - WriterName wrtName = WriterName.create(userInfo.getUsername()); - Writer writer = Writer.create(id, wrtName); - Comment comment = Comment.create(writer, content); + Comment comment = createComment(insertedContent, userInfo); feed.enrollComment(comment); - CommentDto commentDto = toCommentDto(comment); + CommentDto commentDto = toCommentDto(comment); return commentDto; } + private Friendship findFriendShip(Feed feed, UserDto userInfo) throws AccessDeniedException { + Long friendId = feed.getWriter().getId(); + return friendShipRepository.findFriendshipByFriender_FrienderIdAndFriendee_FriendeeId( + PersonId.create(friendId), + PersonId.create(userInfo.getUserId())); + } + + + private Comment createComment(String insertedContent, UserDto userInfo) { + Content content = Content.create(insertedContent); + Writer writer = createWriter(userInfo); + return Comment.create(writer, content); + } + + private Writer createWriter(UserDto userInfo) { + WriterId id = WriterId.create(userInfo.getUserId()); + WriterName wrtName = WriterName.create(userInfo.getUsername()); + return Writer.create(id, wrtName); + } + private CommentDto toCommentDto(Comment comment) { return new CommentDto( comment.getId(), From 431088030c5fc91a3a250f2e48d3c8a7d870bd8f Mon Sep 17 00:00:00 2001 From: jhkim <62026666+horobito@users.noreply.github.com> Date: Wed, 5 May 2021 00:36:04 +0900 Subject: [PATCH 20/20] =?UTF-8?q?*=20=EA=B8=B0=EC=A1=B4=20security=20?= =?UTF-8?q?=EC=A7=80=EC=9A=B0=EA=B3=A0,=20=EC=83=88=EB=A1=9C=EC=9A=B4=20se?= =?UTF-8?q?curity=20=EC=A0=81=EC=9A=A9=20=EC=8B=9C=EB=8F=84=20(1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/feed/service/CommentService.java | 37 +-- .../friend/service/FriendShipService.java | 12 +- .../infrastructure/PasswordEncoderConfig.java | 17 ++ .../service/UserDetailsService.java | 45 ++++ .../mysecurity/service/UserSessionUtils.java | 22 ++ .../mysecurity/service/WebSecurityConfig.java | 47 ++++ .../infrastructure/PasswordEncoderConfig.java | 34 +-- .../ReadableRequestBodyWrapper.java | 138 +++++------ .../UserAuthenticationFilter.java | 234 +++++++++--------- .../infrastructure/WebSecurityConfig.java | 136 +++++----- .../security/service/UserDetailsService.java | 90 +++---- .../security/service/UserSessionUtils.java | 44 ++-- .../demo/user/controller/UserController.java | 22 +- .../demo/user/service/UserService.java | 6 +- .../demo/user/service/UserSessionService.java | 3 +- 15 files changed, 515 insertions(+), 372 deletions(-) create mode 100644 src/main/java/com/example/demo/mysecurity/infrastructure/PasswordEncoderConfig.java create mode 100644 src/main/java/com/example/demo/mysecurity/service/UserDetailsService.java create mode 100644 src/main/java/com/example/demo/mysecurity/service/UserSessionUtils.java create mode 100644 src/main/java/com/example/demo/mysecurity/service/WebSecurityConfig.java diff --git a/src/main/java/com/example/demo/feed/service/CommentService.java b/src/main/java/com/example/demo/feed/service/CommentService.java index 043a2d6..7d3bd83 100644 --- a/src/main/java/com/example/demo/feed/service/CommentService.java +++ b/src/main/java/com/example/demo/feed/service/CommentService.java @@ -35,33 +35,42 @@ public CommentDto makeCommentByFeedIdAndContents(Long feedId, String insertedCon if (insertedContent.length()==0 || feed==null){ throw new IllegalArgumentException(); } - UserDto userInfo = userService.findUserInfo(); - Long friendId = feed.getWriter().getId(); - Friendship friendship - = friendShipRepository.findFriendshipByFriender_FrienderIdAndFriendee_FriendeeId( - PersonId.create(friendId), - PersonId.create(userInfo.getUserId())); - + Friendship friendship = findFriendShip(feed, userInfo); if (friendship==null || friendship.getFriendState()!= FriendShipState.ACCEPT){ throw new IllegalAccessException(); } - - Content content = Content.create(insertedContent); - WriterId id = WriterId.create(userInfo.getUserId()); - WriterName wrtName = WriterName.create(userInfo.getUsername()); - Writer writer = Writer.create(id, wrtName); - Comment comment = Comment.create(writer, content); + Comment comment = createComment(insertedContent, userInfo); feed.enrollComment(comment); - CommentDto commentDto = toCommentDto(comment); + CommentDto commentDto = toCommentDto(comment); return commentDto; } + private Friendship findFriendShip(Feed feed, UserDto userInfo) throws AccessDeniedException { + Long friendId = feed.getWriter().getId(); + return friendShipRepository.findFriendshipByFriender_FrienderIdAndFriendee_FriendeeId( + PersonId.create(friendId), + PersonId.create(userInfo.getUserId())); + } + + + private Comment createComment(String insertedContent, UserDto userInfo) { + Content content = Content.create(insertedContent); + Writer writer = createWriter(userInfo); + return Comment.create(writer, content); + } + + private Writer createWriter(UserDto userInfo) { + WriterId id = WriterId.create(userInfo.getUserId()); + WriterName wrtName = WriterName.create(userInfo.getUsername()); + return Writer.create(id, wrtName); + } + private CommentDto toCommentDto(Comment comment) { return new CommentDto( comment.getId(), diff --git a/src/main/java/com/example/demo/friend/service/FriendShipService.java b/src/main/java/com/example/demo/friend/service/FriendShipService.java index 1b8cbc0..6086fd1 100644 --- a/src/main/java/com/example/demo/friend/service/FriendShipService.java +++ b/src/main/java/com/example/demo/friend/service/FriendShipService.java @@ -132,17 +132,21 @@ public List findRequestForMe(int page, int size) throws AccessDenied throw new IllegalArgumentException(); } - PersonId myId = PersonId.create(userService.findUserInfo().getUserId()); - List friendshipList = friendShipRepository.findAllByFriendee_FriendeeId(myId, PageRequest.of(page, size)) + List friendshipList = createFriendShipList(myId, page, size); + + return friendshipList; + } + + + private List createFriendShipList(PersonId myId, int page, int size) { + return friendShipRepository.findAllByFriendee_FriendeeId(myId, PageRequest.of(page, size)) .stream() .filter(friendship -> friendship.getFriendState()==FriendShipState.REQUEST) .map(Friendship::getFriender) .map(this::toFriendDto) .collect(Collectors.toList()); - - return friendshipList; } public Friendship createFriendship(Friender friender, Friendee friendee) { diff --git a/src/main/java/com/example/demo/mysecurity/infrastructure/PasswordEncoderConfig.java b/src/main/java/com/example/demo/mysecurity/infrastructure/PasswordEncoderConfig.java new file mode 100644 index 0000000..8a5e18e --- /dev/null +++ b/src/main/java/com/example/demo/mysecurity/infrastructure/PasswordEncoderConfig.java @@ -0,0 +1,17 @@ +package com.example.demo.mysecurity.infrastructure; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; + + +@Configuration +public class PasswordEncoderConfig { + + @Bean + public PasswordEncoder passwordEncoder(){ + return new BCryptPasswordEncoder(); + } + +} diff --git a/src/main/java/com/example/demo/mysecurity/service/UserDetailsService.java b/src/main/java/com/example/demo/mysecurity/service/UserDetailsService.java new file mode 100644 index 0000000..a469d36 --- /dev/null +++ b/src/main/java/com/example/demo/mysecurity/service/UserDetailsService.java @@ -0,0 +1,45 @@ +package com.example.demo.mysecurity.service; + + +import com.example.demo.user.domain.Authority; +import com.example.demo.user.domain.UserRepository; +import com.example.demo.user.domain.Username; +import lombok.RequiredArgsConstructor; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.SecurityUser; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; + +import java.util.Optional; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor +public class UserDetailsService implements org.springframework.security.core.userdetails.UserDetailsService { + + private final UserRepository userRepository; + + + + @Override + public UserDetails loadUserByUsername(String username){ + Username name = Username.create(username); + + Optional user1 = userRepository + .findUserByUserBasicInfo_Username(name) + .map(user -> new SecurityUser( + user.getId(), + user.getUserBasicInfo().getUsername(), + user.getUserBasicInfo().getPassword(), + user.getAuthorities() + .stream() + .map(Authority::getAuthority) + .map(SimpleGrantedAuthority::new) + .collect(Collectors.toSet()) + )); + return user1.orElseThrow( + ()-> new UsernameNotFoundException("Can't find by your username")); + } +} diff --git a/src/main/java/com/example/demo/mysecurity/service/UserSessionUtils.java b/src/main/java/com/example/demo/mysecurity/service/UserSessionUtils.java new file mode 100644 index 0000000..4fb2d08 --- /dev/null +++ b/src/main/java/com/example/demo/mysecurity/service/UserSessionUtils.java @@ -0,0 +1,22 @@ +package com.example.demo.mysecurity.service; + +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.core.userdetails.SecurityUser; + +import java.nio.file.AccessDeniedException; + +public class UserSessionUtils { + + private UserSessionUtils(){ + + } + + public static SecurityUser getSessionUser() throws AccessDeniedException { + Object detais = SecurityContextHolder.getContext().getAuthentication().getDetails(); + + if (!(detais instanceof SecurityUser)){ + throw new AccessDeniedException("유저 정보가 없습니다."); + } + return (SecurityUser) detais; + } +} diff --git a/src/main/java/com/example/demo/mysecurity/service/WebSecurityConfig.java b/src/main/java/com/example/demo/mysecurity/service/WebSecurityConfig.java new file mode 100644 index 0000000..3c43c80 --- /dev/null +++ b/src/main/java/com/example/demo/mysecurity/service/WebSecurityConfig.java @@ -0,0 +1,47 @@ +package com.example.demo.mysecurity.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.authentication.AuthenticationProvider; +import org.springframework.security.authentication.dao.DaoAuthenticationProvider; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.web.authentication.AuthenticationFilter; + +@Configuration +@RequiredArgsConstructor +public class WebSecurityConfig extends WebSecurityConfigurerAdapter { + + + private final UserDetailsService userDetailsService; + + private final PasswordEncoder passwordEncoder; + + + @Override + protected void configure(HttpSecurity httpSecurity) throws Exception{ + httpSecurity + .csrf().disable() + .authorizeRequests() + .antMatchers("/account/**") + .permitAll() + .anyRequest() + .authenticated(); + } + + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder); + } + + @Bean + @Override + public AuthenticationManager authenticationManagerBean() throws Exception { + return super.authenticationManagerBean(); + } +} diff --git a/src/main/java/com/example/demo/security/infrastructure/PasswordEncoderConfig.java b/src/main/java/com/example/demo/security/infrastructure/PasswordEncoderConfig.java index f2a8219..e12e505 100644 --- a/src/main/java/com/example/demo/security/infrastructure/PasswordEncoderConfig.java +++ b/src/main/java/com/example/demo/security/infrastructure/PasswordEncoderConfig.java @@ -1,17 +1,17 @@ -package com.example.demo.security.infrastructure; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.security.crypto.password.PasswordEncoder; - - -@Configuration -public class PasswordEncoderConfig { - - @Bean - public PasswordEncoder passwordEncoder(){ - return new BCryptPasswordEncoder(); - } - -} +//package com.example.demo.security.infrastructure; +// +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +//import org.springframework.security.crypto.password.PasswordEncoder; +// +// +//@Configuration +//public class PasswordEncoderConfig { +// +// @Bean +// public PasswordEncoder passwordEncoder(){ +// return new BCryptPasswordEncoder(); +// } +// +//} diff --git a/src/main/java/com/example/demo/security/infrastructure/ReadableRequestBodyWrapper.java b/src/main/java/com/example/demo/security/infrastructure/ReadableRequestBodyWrapper.java index 5402600..88d203f 100644 --- a/src/main/java/com/example/demo/security/infrastructure/ReadableRequestBodyWrapper.java +++ b/src/main/java/com/example/demo/security/infrastructure/ReadableRequestBodyWrapper.java @@ -1,69 +1,69 @@ -package com.example.demo.security.infrastructure; - -import com.google.common.io.ByteStreams; - -import javax.servlet.ReadListener; -import javax.servlet.ServletInputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletRequestWrapper; -import java.io.ByteArrayInputStream; -import java.io.IOException; - - - -public class ReadableRequestBodyWrapper extends HttpServletRequestWrapper { - - private final String requestBody; - private final byte[] bytes; - /** - * Constructs a request object wrapping the given request. - * - * @param request The request to wrap - * @throws IllegalArgumentException if the request is null - */ - public ReadableRequestBodyWrapper(HttpServletRequest request) throws IOException { - super(request); - this.bytes = ByteStreams.toByteArray(super.getInputStream()); - this.requestBody = new String(bytes); - } - - @Override - public ServletInputStream getInputStream() throws IOException { - ByteArrayInputStream bais = new ByteArrayInputStream(bytes); - return new WrapperInputStream(bais); - - } - - public String getRequestBody() { - return requestBody; - } - - private class WrapperInputStream extends ServletInputStream { - private final ByteArrayInputStream bais; - public WrapperInputStream(ByteArrayInputStream bais) { - this.bais = bais; - } - - @Override - public boolean isFinished() { - return true; - } - - @Override - public boolean isReady() { - return true; - } - - @Override - public void setReadListener(ReadListener listener) { - - } - - @Override - public int read() throws IOException { - return bais.read(); - } - } - - -} +//package com.example.demo.security.infrastructure; +// +//import com.google.common.io.ByteStreams; +// +//import javax.servlet.ReadListener; +//import javax.servlet.ServletInputStream; +//import javax.servlet.http.HttpServletRequest; +//import javax.servlet.http.HttpServletRequestWrapper; +//import java.io.ByteArrayInputStream; +//import java.io.IOException; +// +// +// +//public class ReadableRequestBodyWrapper extends HttpServletRequestWrapper { +// +// private final String requestBody; +// private final byte[] bytes; +// /** +// * Constructs a request object wrapping the given request. +// * +// * @param request The request to wrap +// * @throws IllegalArgumentException if the request is null +// */ +// public ReadableRequestBodyWrapper(HttpServletRequest request) throws IOException { +// super(request); +// this.bytes = ByteStreams.toByteArray(super.getInputStream()); +// this.requestBody = new String(bytes); +// } +// +// @Override +// public ServletInputStream getInputStream() throws IOException { +// ByteArrayInputStream bais = new ByteArrayInputStream(bytes); +// return new WrapperInputStream(bais); +// +// } +// +// public String getRequestBody() { +// return requestBody; +// } +// +// private class WrapperInputStream extends ServletInputStream { +// private final ByteArrayInputStream bais; +// public WrapperInputStream(ByteArrayInputStream bais) { +// this.bais = bais; +// } +// +// @Override +// public boolean isFinished() { +// return true; +// } +// +// @Override +// public boolean isReady() { +// return true; +// } +// +// @Override +// public void setReadListener(ReadListener listener) { +// +// } +// +// @Override +// public int read() throws IOException { +// return bais.read(); +// } +// } +// +// +//} diff --git a/src/main/java/com/example/demo/security/infrastructure/UserAuthenticationFilter.java b/src/main/java/com/example/demo/security/infrastructure/UserAuthenticationFilter.java index 8d3094f..81bc887 100644 --- a/src/main/java/com/example/demo/security/infrastructure/UserAuthenticationFilter.java +++ b/src/main/java/com/example/demo/security/infrastructure/UserAuthenticationFilter.java @@ -1,117 +1,117 @@ -package com.example.demo.security.infrastructure; - -import com.example.demo.user.controller.UserController; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.json.JsonParseException; -import org.springframework.security.authentication.AnonymousAuthenticationToken; -import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.AuthenticationException; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.web.AuthenticationEntryPoint; -import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; -import org.springframework.stereotype.Component; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - - - - -@Component -public class UserAuthenticationFilter extends BasicAuthenticationFilter { - - private final ObjectMapper objectMapper = new ObjectMapper(); - - - - @Autowired - public UserAuthenticationFilter(AuthenticationManager authenticationManager) { - super(authenticationManager); - } - - - public UserAuthenticationFilter(AuthenticationManager authenticationManager, AuthenticationEntryPoint authenticationEntryPoint) { - super(authenticationManager, authenticationEntryPoint); - } - - @Override - protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { - ReadableRequestBodyWrapper readableRequestBodyWrapper - = new ReadableRequestBodyWrapper(request); - - String requestBody = readableRequestBodyWrapper.getRequestBody(); - UserController.SignupParameter parameter; - try { - parameter= - objectMapper.readValue(requestBody, - UserController.SignupParameter.class); - }catch (JsonParseException e){ - chain.doFilter(request, response); - - return; - } - - String username = parameter.getUsername(); - String password = parameter.getPassword(); - - UsernamePasswordAuthenticationToken token - = new UsernamePasswordAuthenticationToken(username, password); - - try { - // 인증 요구되는 상황 - if (authenticationIsRequired(username)){ - Authentication authResult - = this.getAuthenticationManager().authenticate(token); - SecurityContextHolder.getContext().setAuthentication(authResult); - onSuccessfulAuthentication(request, response, authResult); - } - }catch (AuthenticationException ex){ - // 인증이 실패한 상황 - SecurityContextHolder.clearContext(); - onUnsuccessfulAuthentication(request, response, ex); - - chain.doFilter(request, response); - - return; - } - - chain.doFilter(request, response); - } - - private boolean authenticationIsRequired(String username) { - // Only reauthenticate if username doesn't match SecurityContextHolder and user - // isn't authenticated (see SEC-53) - Authentication existingAuth = SecurityContextHolder.getContext().getAuthentication(); - if (existingAuth == null || !existingAuth.isAuthenticated()) { - return true; - } - // Limit username comparison to providers which use usernames (ie - // UsernamePasswordAuthenticationToken) (see SEC-348) - if (existingAuth instanceof UsernamePasswordAuthenticationToken && !existingAuth.getName().equals(username)) { - return true; - } - // Handle unusual condition where an AnonymousAuthenticationToken is already - // present. This shouldn't happen very often, as BasicProcessingFitler is meant to - // be earlier in the filter chain than AnonymousAuthenticationFilter. - // Nevertheless, presence of both an AnonymousAuthenticationToken together with a - // BASIC authentication request header should indicate reauthentication using the - // BASIC protocol is desirable. This behaviour is also consistent with that - // provided by form and digest, both of which force re-authentication if the - // respective header is detected (and in doing so replace/ any existing - // AnonymousAuthenticationToken). See SEC-610. - return (existingAuth instanceof AnonymousAuthenticationToken); - } - - @Override - protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException { - if(request.getRequestURI().startsWith("/account/**")){ - return true; - } - return false; - } -} +//package com.example.demo.security.infrastructure; +// +//import com.example.demo.user.controller.UserController; +//import com.fasterxml.jackson.databind.ObjectMapper; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.boot.json.JsonParseException; +//import org.springframework.security.authentication.AnonymousAuthenticationToken; +//import org.springframework.security.authentication.AuthenticationManager; +//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +//import org.springframework.security.core.Authentication; +//import org.springframework.security.core.AuthenticationException; +//import org.springframework.security.core.context.SecurityContextHolder; +//import org.springframework.security.web.AuthenticationEntryPoint; +//import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; +//import org.springframework.stereotype.Component; +//import javax.servlet.FilterChain; +//import javax.servlet.ServletException; +//import javax.servlet.http.HttpServletRequest; +//import javax.servlet.http.HttpServletResponse; +//import java.io.IOException; +// +// +// +// +//@Component +//public class UserAuthenticationFilter extends BasicAuthenticationFilter { +// +// private final ObjectMapper objectMapper = new ObjectMapper(); +// +// +// +// @Autowired +// public UserAuthenticationFilter(AuthenticationManager authenticationManager) { +// super(authenticationManager); +// } +// +// +// public UserAuthenticationFilter(AuthenticationManager authenticationManager, AuthenticationEntryPoint authenticationEntryPoint) { +// super(authenticationManager, authenticationEntryPoint); +// } +// +// @Override +// protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { +// ReadableRequestBodyWrapper readableRequestBodyWrapper +// = new ReadableRequestBodyWrapper(request); +// +// String requestBody = readableRequestBodyWrapper.getRequestBody(); +// UserController.SignupParameter parameter; +// try { +// parameter= +// objectMapper.readValue(requestBody, +// UserController.SignupParameter.class); +// }catch (JsonParseException e){ +// chain.doFilter(request, response); +// +// return; +// } +// +// String username = parameter.getUsername(); +// String password = parameter.getPassword(); +// +// UsernamePasswordAuthenticationToken token +// = new UsernamePasswordAuthenticationToken(username, password); +// +// try { +// // 인증 요구되는 상황 +// if (authenticationIsRequired(username)){ +// Authentication authResult +// = this.getAuthenticationManager().authenticate(token); +// SecurityContextHolder.getContext().setAuthentication(authResult); +// onSuccessfulAuthentication(request, response, authResult); +// } +// }catch (AuthenticationException ex){ +// // 인증이 실패한 상황 +// SecurityContextHolder.clearContext(); +// onUnsuccessfulAuthentication(request, response, ex); +// +// chain.doFilter(request, response); +// +// return; +// } +// +// chain.doFilter(request, response); +// } +// +// private boolean authenticationIsRequired(String username) { +// // Only reauthenticate if username doesn't match SecurityContextHolder and user +// // isn't authenticated (see SEC-53) +// Authentication existingAuth = SecurityContextHolder.getContext().getAuthentication(); +// if (existingAuth == null || !existingAuth.isAuthenticated()) { +// return true; +// } +// // Limit username comparison to providers which use usernames (ie +// // UsernamePasswordAuthenticationToken) (see SEC-348) +// if (existingAuth instanceof UsernamePasswordAuthenticationToken && !existingAuth.getName().equals(username)) { +// return true; +// } +// // Handle unusual condition where an AnonymousAuthenticationToken is already +// // present. This shouldn't happen very often, as BasicProcessingFitler is meant to +// // be earlier in the filter chain than AnonymousAuthenticationFilter. +// // Nevertheless, presence of both an AnonymousAuthenticationToken together with a +// // BASIC authentication request header should indicate reauthentication using the +// // BASIC protocol is desirable. This behaviour is also consistent with that +// // provided by form and digest, both of which force re-authentication if the +// // respective header is detected (and in doing so replace/ any existing +// // AnonymousAuthenticationToken). See SEC-610. +// return (existingAuth instanceof AnonymousAuthenticationToken); +// } +// +// @Override +// protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException { +// if(request.getRequestURI().startsWith("/account/**")){ +// return true; +// } +// return false; +// } +//} diff --git a/src/main/java/com/example/demo/security/infrastructure/WebSecurityConfig.java b/src/main/java/com/example/demo/security/infrastructure/WebSecurityConfig.java index f71bbc4..20927f3 100644 --- a/src/main/java/com/example/demo/security/infrastructure/WebSecurityConfig.java +++ b/src/main/java/com/example/demo/security/infrastructure/WebSecurityConfig.java @@ -1,65 +1,71 @@ -package com.example.demo.security.infrastructure; - - -import com.example.demo.security.service.UserDetailsService; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.RequiredArgsConstructor; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.authentication.AuthenticationProvider; -import org.springframework.security.authentication.dao.DaoAuthenticationProvider; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.security.crypto.password.PasswordEncoder; - -@Configuration -@EnableWebSecurity -@RequiredArgsConstructor -public class WebSecurityConfig extends WebSecurityConfigurerAdapter { - - private final UserDetailsService userDetailsService; - - private final PasswordEncoder passwordEncoder; - - - - - - @Override - protected void configure(AuthenticationManagerBuilder auth) throws Exception { - auth.authenticationProvider(daoAuthenticationProvider()); - - } - - protected void configure(HttpSecurity http) throws Exception { -// super.configure(http); - http - .csrf().disable() - .authorizeRequests() - .antMatchers("/account/**") - .permitAll() - .anyRequest() - .authenticated() - .and() - .addFilter(new UserAuthenticationFilter(authenticationManagerBean())); - - } - - @Bean - @Override - public AuthenticationManager authenticationManagerBean() throws Exception{ - return super.authenticationManagerBean(); - } - - @Bean - public AuthenticationProvider daoAuthenticationProvider(){ - DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider(); - daoAuthenticationProvider.setPasswordEncoder(passwordEncoder); - daoAuthenticationProvider.setUserDetailsService(userDetailsService); - return daoAuthenticationProvider; - } -} +//package com.example.demo.security.infrastructure; +// +// +//import com.example.demo.security.service.UserDetailsService; +//import com.fasterxml.jackson.databind.ObjectMapper; +//import lombok.RequiredArgsConstructor; +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +//import org.springframework.security.authentication.AuthenticationManager; +//import org.springframework.security.authentication.AuthenticationProvider; +//import org.springframework.security.authentication.dao.DaoAuthenticationProvider; +//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +//import org.springframework.security.config.annotation.web.builders.HttpSecurity; +//import org.springframework.security.config.annotation.web.builders.WebSecurity; +//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +//import org.springframework.security.crypto.password.PasswordEncoder; +// +//@Configuration +//@EnableWebSecurity +//@RequiredArgsConstructor +//public class WebSecurityConfig extends WebSecurityConfigurerAdapter { +// +// private final UserDetailsService userDetailsService; +// +// private final PasswordEncoder passwordEncoder; +// +// +// +// +// +// @Override +// protected void configure(AuthenticationManagerBuilder auth) throws Exception { +// auth.authenticationProvider(daoAuthenticationProvider()); +// +// } +// +// @Override +// protected void configure(HttpSecurity http) throws Exception { +// http +// .csrf().disable() +// .authorizeRequests() +// .antMatchers("/account/signup", "/account/login") +// .permitAll() +// .anyRequest() +// .authenticated() +// .and() +// .addFilter(new UserAuthenticationFilter(authenticationManagerBean())); +// +// } +// +// @Override +// public void configure(WebSecurity web){ +// web.ignoring().antMatchers("/account/signup", "/account/login"); +// } +// +// @Bean +// @Override +// public AuthenticationManager authenticationManagerBean() throws Exception{ +// return super.authenticationManagerBean(); +// } +// +// @Bean +// public AuthenticationProvider daoAuthenticationProvider(){ +// DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider(); +// daoAuthenticationProvider.setPasswordEncoder(passwordEncoder); +// daoAuthenticationProvider.setUserDetailsService(userDetailsService); +// return daoAuthenticationProvider; +// } +//} diff --git a/src/main/java/com/example/demo/security/service/UserDetailsService.java b/src/main/java/com/example/demo/security/service/UserDetailsService.java index d07c65a..b6a201b 100644 --- a/src/main/java/com/example/demo/security/service/UserDetailsService.java +++ b/src/main/java/com/example/demo/security/service/UserDetailsService.java @@ -1,45 +1,45 @@ -package com.example.demo.security.service; - - -import com.example.demo.security.infrastructure.UserAuthenticationFilter; -import com.example.demo.user.domain.Authority; -import com.example.demo.user.domain.UserRepository; -import com.example.demo.user.domain.Username; -import lombok.RequiredArgsConstructor; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.userdetails.SecurityUser; -import org.springframework.security.core.userdetails.User; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.core.userdetails.UsernameNotFoundException; -import org.springframework.stereotype.Service; -import java.util.Optional; -import java.util.stream.Collectors; - -@Service -@RequiredArgsConstructor -public class UserDetailsService implements org.springframework.security.core.userdetails.UserDetailsService { - - private final UserRepository userRepository; - - - - @Override - public UserDetails loadUserByUsername(String username){ - Username name = Username.create(username); - - Optional user1 = userRepository - .findUserByUserBasicInfo_Username(name) - .map(user -> new SecurityUser( - user.getId(), - user.getUserBasicInfo().getUsername(), - user.getUserBasicInfo().getPassword(), - user.getAuthorities() - .stream() - .map(Authority::getAuthority) - .map(SimpleGrantedAuthority::new) - .collect(Collectors.toSet()) - )); - return user1.orElseThrow( - ()-> new UsernameNotFoundException("Can't find by your username")); - } -} +//package com.example.demo.security.service; +// +// +//import com.example.demo.security.infrastructure.UserAuthenticationFilter; +//import com.example.demo.user.domain.Authority; +//import com.example.demo.user.domain.UserRepository; +//import com.example.demo.user.domain.Username; +//import lombok.RequiredArgsConstructor; +//import org.springframework.security.core.authority.SimpleGrantedAuthority; +//import org.springframework.security.core.userdetails.SecurityUser; +//import org.springframework.security.core.userdetails.User; +//import org.springframework.security.core.userdetails.UserDetails; +//import org.springframework.security.core.userdetails.UsernameNotFoundException; +//import org.springframework.stereotype.Service; +//import java.util.Optional; +//import java.util.stream.Collectors; +// +//@Service +//@RequiredArgsConstructor +//public class UserDetailsService implements org.springframework.security.core.userdetails.UserDetailsService { +// +// private final UserRepository userRepository; +// +// +// +// @Override +// public UserDetails loadUserByUsername(String username){ +// Username name = Username.create(username); +// +// Optional user1 = userRepository +// .findUserByUserBasicInfo_Username(name) +// .map(user -> new SecurityUser( +// user.getId(), +// user.getUserBasicInfo().getUsername(), +// user.getUserBasicInfo().getPassword(), +// user.getAuthorities() +// .stream() +// .map(Authority::getAuthority) +// .map(SimpleGrantedAuthority::new) +// .collect(Collectors.toSet()) +// )); +// return user1.orElseThrow( +// ()-> new UsernameNotFoundException("Can't find by your username")); +// } +//} diff --git a/src/main/java/com/example/demo/security/service/UserSessionUtils.java b/src/main/java/com/example/demo/security/service/UserSessionUtils.java index 21e2f8c..98c2772 100644 --- a/src/main/java/com/example/demo/security/service/UserSessionUtils.java +++ b/src/main/java/com/example/demo/security/service/UserSessionUtils.java @@ -1,22 +1,22 @@ -package com.example.demo.security.service; - -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.core.userdetails.SecurityUser; - -import java.nio.file.AccessDeniedException; - -public class UserSessionUtils { - - private UserSessionUtils(){ - - } - - public static SecurityUser getSessionUser() throws AccessDeniedException { - Object detais = SecurityContextHolder.getContext().getAuthentication().getDetails(); - - if (!(detais instanceof SecurityUser)){ - throw new AccessDeniedException("유저 정보가 없습니다."); - } - return (SecurityUser) detais; - } -} +//package com.example.demo.security.service; +// +//import org.springframework.security.core.context.SecurityContextHolder; +//import org.springframework.security.core.userdetails.SecurityUser; +// +//import java.nio.file.AccessDeniedException; +// +//public class UserSessionUtils { +// +// private UserSessionUtils(){ +// +// } +// +// public static SecurityUser getSessionUser() throws AccessDeniedException { +// Object detais = SecurityContextHolder.getContext().getAuthentication().getDetails(); +// +// if (!(detais instanceof SecurityUser)){ +// throw new AccessDeniedException("유저 정보가 없습니다."); +// } +// return (SecurityUser) detais; +// } +//} diff --git a/src/main/java/com/example/demo/user/controller/UserController.java b/src/main/java/com/example/demo/user/controller/UserController.java index 82c0ecc..c8e0abb 100644 --- a/src/main/java/com/example/demo/user/controller/UserController.java +++ b/src/main/java/com/example/demo/user/controller/UserController.java @@ -2,27 +2,18 @@ -import com.example.demo.security.service.UserDetailsService; import com.example.demo.user.service.LoginRequest; import com.example.demo.user.service.SignupRequest; import com.example.demo.user.service.UserService; import lombok.RequiredArgsConstructor; import lombok.Value; -import org.springframework.web.bind.annotation.*; -import javax.servlet.Servlet; +import org.springframework.web.bind.annotation.*; import javax.servlet.ServletException; -import javax.servlet.ServletOutputStream; -import javax.servlet.ServletResponse; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; + import javax.servlet.http.HttpServletResponse; import java.io.IOException; -import java.io.PrintWriter; -import java.util.Collection; -import java.util.Locale; @RestController @RequestMapping("/account") @@ -56,8 +47,13 @@ public void signupWithAdminAccount(@RequestBody SignupParameter parameter){ } @PostMapping("/login") - public void Login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - userService.login(request, response); + public void Login(@RequestBody LoginRequest loginRequest, HttpServletResponse response) throws ServletException, IOException { + String username = loginRequest.getUsername(); + String password = loginRequest.getPassword(); + +// UsernamePasswordAuthenticationToken token +// = new UsernamePasswordAuthenticationToken(username, password); +// SecurityContextHolder.ge } @Value diff --git a/src/main/java/com/example/demo/user/service/UserService.java b/src/main/java/com/example/demo/user/service/UserService.java index 4c6d622..d5d7fea 100644 --- a/src/main/java/com/example/demo/user/service/UserService.java +++ b/src/main/java/com/example/demo/user/service/UserService.java @@ -4,18 +4,14 @@ -import com.example.demo.security.infrastructure.UserAuthenticationFilter; -import com.example.demo.security.service.UserDetailsService; import com.example.demo.user.domain.*; import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.servlet.FilterChain; import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; diff --git a/src/main/java/com/example/demo/user/service/UserSessionService.java b/src/main/java/com/example/demo/user/service/UserSessionService.java index c7ec2c3..80b6801 100644 --- a/src/main/java/com/example/demo/user/service/UserSessionService.java +++ b/src/main/java/com/example/demo/user/service/UserSessionService.java @@ -1,7 +1,8 @@ package com.example.demo.user.service; -import com.example.demo.security.service.UserSessionUtils; + +import com.example.demo.mysecurity.service.UserSessionUtils; import com.example.demo.user.domain.User; import com.example.demo.user.domain.UserRepository; import lombok.RequiredArgsConstructor;