From cf43e48af68b6f5d883cb0c515cf828d638b0856 Mon Sep 17 00:00:00 2001 From: ckkim817 Date: Sat, 6 Jul 2024 04:18:29 +0900 Subject: [PATCH 01/15] =?UTF-8?q?[REFACTOR/#10]=20querydsl=20->=20Spring?= =?UTF-8?q?=20Data=20JPA=EC=9D=98=20=EC=BF=BC=EB=A6=AC=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit findBySocialTypeAndSocialId --- .../member/repository/MemberRepository.java | 5 +++- .../repository/MemberRepositoryCustom.java | 13 -------- .../repository/MemberRepositoryImpl.java | 30 ------------------- 3 files changed, 4 insertions(+), 44 deletions(-) delete mode 100644 src/main/java/org/sopt/seonyakServer/domain/member/repository/MemberRepositoryCustom.java delete mode 100644 src/main/java/org/sopt/seonyakServer/domain/member/repository/MemberRepositoryImpl.java diff --git a/src/main/java/org/sopt/seonyakServer/domain/member/repository/MemberRepository.java b/src/main/java/org/sopt/seonyakServer/domain/member/repository/MemberRepository.java index 4feeb7c..a0ab262 100644 --- a/src/main/java/org/sopt/seonyakServer/domain/member/repository/MemberRepository.java +++ b/src/main/java/org/sopt/seonyakServer/domain/member/repository/MemberRepository.java @@ -1,7 +1,10 @@ package org.sopt.seonyakServer.domain.member.repository; +import java.util.Optional; import org.sopt.seonyakServer.domain.member.model.Member; +import org.sopt.seonyakServer.global.common.external.client.SocialType; import org.springframework.data.jpa.repository.JpaRepository; -public interface MemberRepository extends JpaRepository, MemberRepositoryCustom { +public interface MemberRepository extends JpaRepository { + Optional findBySocialTypeAndSocialId(SocialType socialType, String socialId); } diff --git a/src/main/java/org/sopt/seonyakServer/domain/member/repository/MemberRepositoryCustom.java b/src/main/java/org/sopt/seonyakServer/domain/member/repository/MemberRepositoryCustom.java deleted file mode 100644 index e9d9c52..0000000 --- a/src/main/java/org/sopt/seonyakServer/domain/member/repository/MemberRepositoryCustom.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.sopt.seonyakServer.domain.member.repository; - -import java.util.Optional; -import org.sopt.seonyakServer.domain.member.model.Member; -import org.sopt.seonyakServer.global.common.external.client.SocialType; - -public interface MemberRepositoryCustom { - - Optional findBySocialTypeAndSocialId( - final String socialId, - final SocialType socialType - ); -} diff --git a/src/main/java/org/sopt/seonyakServer/domain/member/repository/MemberRepositoryImpl.java b/src/main/java/org/sopt/seonyakServer/domain/member/repository/MemberRepositoryImpl.java deleted file mode 100644 index a9dc3a3..0000000 --- a/src/main/java/org/sopt/seonyakServer/domain/member/repository/MemberRepositoryImpl.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.sopt.seonyakServer.domain.member.repository; - -import static org.sopt.seonyakServer.domain.member.model.QMember.member; - -import com.querydsl.jpa.impl.JPAQueryFactory; -import java.util.Optional; -import lombok.RequiredArgsConstructor; -import org.sopt.seonyakServer.domain.member.model.Member; -import org.sopt.seonyakServer.global.common.external.client.SocialType; - -@RequiredArgsConstructor -public class MemberRepositoryImpl implements MemberRepositoryCustom { - - private final JPAQueryFactory jpaQueryFactory; - - @Override - public Optional findBySocialTypeAndSocialId( - final String socialId, - final SocialType socialType - ) { - return Optional.ofNullable( - jpaQueryFactory.selectFrom(member) - .where( - member.socialId.eq(socialId), - member.socialType.eq(socialType) - ) - .fetchOne() - ); - } -} From f5a35d6fbe0c5e299c33df43868dc81a8814c16d Mon Sep 17 00:00:00 2001 From: ckkim817 Date: Sat, 6 Jul 2024 04:19:30 +0900 Subject: [PATCH 02/15] =?UTF-8?q?[CHORE/#10]=20memberInfoResponse=20?= =?UTF-8?q?=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=20=EC=88=9C=EC=84=9C=20?= =?UTF-8?q?=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/service/MemberService.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java b/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java index 7f9aff8..a738521 100644 --- a/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java +++ b/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java @@ -34,9 +34,9 @@ public LoginSuccessResponse create( private LoginSuccessResponse getTokenDto(final MemberInfoResponse memberInfoResponse) { try { - if (isExistingMember(memberInfoResponse.socialId(), memberInfoResponse.socialType())) { + if (isExistingMember(memberInfoResponse.socialType(), memberInfoResponse.socialId())) { return getTokenByMemberId( - getBySocialId(memberInfoResponse.socialId(), memberInfoResponse.socialType()).getId() + getBySocialId(memberInfoResponse.socialType(), memberInfoResponse.socialId()).getId() ); } else { Long id = createMember(memberInfoResponse); @@ -45,7 +45,7 @@ private LoginSuccessResponse getTokenDto(final MemberInfoResponse memberInfoResp } } catch (DataIntegrityViolationException e) { // DB 무결성 제약 조건 위반 예외 return getTokenByMemberId( - getBySocialId(memberInfoResponse.socialId(), memberInfoResponse.socialType()).getId() + getBySocialId(memberInfoResponse.socialType(), memberInfoResponse.socialId()).getId() ); } } @@ -63,17 +63,17 @@ public MemberInfoResponse getMemberInfoResponse( } public boolean isExistingMember( - final String socialId, - final SocialType socialType + final SocialType socialType, + final String socialId ) { - return memberRepository.findBySocialTypeAndSocialId(socialId, socialType).isPresent(); + return memberRepository.findBySocialTypeAndSocialId(socialType, socialId).isPresent(); } public Member getBySocialId( - final String socialId, - final SocialType socialType + final SocialType socialType, + final String socialId ) { - Member member = memberRepository.findBySocialTypeAndSocialId(socialId, socialType).orElseThrow( + Member member = memberRepository.findBySocialTypeAndSocialId(socialType, socialId).orElseThrow( () -> new CustomException(ErrorType.NOT_FOUND_MEMBER_ERROR) ); From 1f747f46b31ed71bfe3f05f770cec08a503330f7 Mon Sep 17 00:00:00 2001 From: ckkim817 Date: Sat, 6 Jul 2024 04:29:19 +0900 Subject: [PATCH 03/15] =?UTF-8?q?[FIX/#10]=20=EC=9D=91=EB=8B=B5=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EC=BB=A8=EB=B2=A4=EC=85=98=20=EC=A4=80?= =?UTF-8?q?=EC=88=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/controller/MemberController.java | 6 +++--- .../global/exception/model/CustomException.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/sopt/seonyakServer/domain/member/controller/MemberController.java b/src/main/java/org/sopt/seonyakServer/domain/member/controller/MemberController.java index 46adb3a..82df8b3 100644 --- a/src/main/java/org/sopt/seonyakServer/domain/member/controller/MemberController.java +++ b/src/main/java/org/sopt/seonyakServer/domain/member/controller/MemberController.java @@ -4,8 +4,8 @@ import lombok.RequiredArgsConstructor; import org.sopt.seonyakServer.domain.member.dto.LoginSuccessResponse; import org.sopt.seonyakServer.domain.member.service.MemberService; -import org.sopt.seonyakServer.global.common.dto.ResponseDto; import org.sopt.seonyakServer.global.common.external.client.dto.MemberLoginRequest; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -20,12 +20,12 @@ public class MemberController { private final MemberService memberService; @PostMapping("/login") - public ResponseDto login( + public ResponseEntity login( @RequestParam final String authorizationCode, @RequestBody @Valid final MemberLoginRequest loginRequest ) { LoginSuccessResponse loginSuccessResponse = memberService.create(authorizationCode, loginRequest); - return ResponseDto.success(loginSuccessResponse); + return ResponseEntity.ok(loginSuccessResponse); } } diff --git a/src/main/java/org/sopt/seonyakServer/global/exception/model/CustomException.java b/src/main/java/org/sopt/seonyakServer/global/exception/model/CustomException.java index bb54bae..b88ec9e 100644 --- a/src/main/java/org/sopt/seonyakServer/global/exception/model/CustomException.java +++ b/src/main/java/org/sopt/seonyakServer/global/exception/model/CustomException.java @@ -4,7 +4,7 @@ import org.sopt.seonyakServer.global.exception.enums.ErrorType; @Getter -public class CustomException extends RuntimeException{ +public class CustomException extends RuntimeException { private final ErrorType errorType; public CustomException(ErrorType errorType) { From 6bfd0346fd33066d8e7e582695b12ae6f8945689 Mon Sep 17 00:00:00 2001 From: ckkim817 Date: Sat, 6 Jul 2024 07:05:00 +0900 Subject: [PATCH 04/15] =?UTF-8?q?[FIX/#10]=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=ED=83=80=EC=9E=85=20=EB=A9=94=EC=84=B8=EC=A7=80=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/auth/filter/JwtAuthenticationFilter.java | 2 +- .../common/external/client/google/GoogleSocialService.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/sopt/seonyakServer/global/auth/filter/JwtAuthenticationFilter.java b/src/main/java/org/sopt/seonyakServer/global/auth/filter/JwtAuthenticationFilter.java index 5f679fb..30d9eae 100644 --- a/src/main/java/org/sopt/seonyakServer/global/auth/filter/JwtAuthenticationFilter.java +++ b/src/main/java/org/sopt/seonyakServer/global/auth/filter/JwtAuthenticationFilter.java @@ -51,7 +51,7 @@ private String getJwtFromRequest(HttpServletRequest request) { if (StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer ")) { return bearerToken.substring("Bearer ".length()); } else if (StringUtils.hasText(bearerToken) && !bearerToken.startsWith("Bearer ")) { - throw new CustomException(ErrorType.INVALID_JWT_SIGNATURE); + throw new CustomException(ErrorType.BEARER_LOST_ERROR); } return null; diff --git a/src/main/java/org/sopt/seonyakServer/global/common/external/client/google/GoogleSocialService.java b/src/main/java/org/sopt/seonyakServer/global/common/external/client/google/GoogleSocialService.java index ae75b16..753038a 100644 --- a/src/main/java/org/sopt/seonyakServer/global/common/external/client/google/GoogleSocialService.java +++ b/src/main/java/org/sopt/seonyakServer/global/common/external/client/google/GoogleSocialService.java @@ -46,7 +46,7 @@ public MemberInfoResponse login( // 인가 코드로 Access Token 받아오기 accessToken = getOAuth2Authentication(authorizationCode, loginRequest.redirectUri()); } catch (FeignException e) { - throw new CustomException(ErrorType.EXPIRED_JWT_TOKEN); + throw new CustomException(ErrorType.EXPIRED_AUTHENTICATION_CODE); } GoogleUserInfoResponse response = getGoogleUserInfo(accessToken); From 715f8c1b599bf31038f1290b31707267e9271153 Mon Sep 17 00:00:00 2001 From: ckkim817 Date: Sat, 6 Jul 2024 07:28:21 +0900 Subject: [PATCH 05/15] =?UTF-8?q?[FIX/#10]=20=EC=BA=A1=EC=8A=90=ED=99=94?= =?UTF-8?q?=EB=A5=BC=20=EC=9C=84=ED=95=9C=20SocialType=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=EC=9E=90=20=EC=A0=91=EA=B7=BC=20=EC=A0=9C=EC=96=B4?= =?UTF-8?q?=EC=9E=90=20=EC=88=98=EC=A4=80=20=EC=B6=95=EC=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AllArgsConstructor -> RequiredArgsConstructor(access = AccessLevel.PRIVATE) --- .../global/common/external/client/SocialType.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/sopt/seonyakServer/global/common/external/client/SocialType.java b/src/main/java/org/sopt/seonyakServer/global/common/external/client/SocialType.java index 4242fbf..24aa224 100644 --- a/src/main/java/org/sopt/seonyakServer/global/common/external/client/SocialType.java +++ b/src/main/java/org/sopt/seonyakServer/global/common/external/client/SocialType.java @@ -1,10 +1,11 @@ package org.sopt.seonyakServer.global.common.external.client; -import lombok.AllArgsConstructor; +import lombok.AccessLevel; import lombok.Getter; +import lombok.RequiredArgsConstructor; @Getter -@AllArgsConstructor +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) public enum SocialType { GOOGLE("GOOGLE"), From 5deb6301818704307f12aa2d9f6e04d6899b342c Mon Sep 17 00:00:00 2001 From: ckkim817 Date: Sat, 6 Jul 2024 07:42:03 +0900 Subject: [PATCH 06/15] =?UTF-8?q?[DEL/#10]=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20LoginSuccessResponse=20=EC=9D=B8=EC=8A=A4=ED=84=B4?= =?UTF-8?q?=EC=8A=A4=20=EC=83=9D=EC=84=B1=20=EB=A1=9C=EC=A7=81=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/controller/MemberController.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/org/sopt/seonyakServer/domain/member/controller/MemberController.java b/src/main/java/org/sopt/seonyakServer/domain/member/controller/MemberController.java index 82df8b3..3439abd 100644 --- a/src/main/java/org/sopt/seonyakServer/domain/member/controller/MemberController.java +++ b/src/main/java/org/sopt/seonyakServer/domain/member/controller/MemberController.java @@ -24,8 +24,6 @@ public ResponseEntity login( @RequestParam final String authorizationCode, @RequestBody @Valid final MemberLoginRequest loginRequest ) { - LoginSuccessResponse loginSuccessResponse = memberService.create(authorizationCode, loginRequest); - - return ResponseEntity.ok(loginSuccessResponse); + return ResponseEntity.ok(memberService.create(authorizationCode, loginRequest)); } } From db20b2fda3b3d04a6177bc8192121280717b743c Mon Sep 17 00:00:00 2001 From: ckkim817 Date: Sat, 6 Jul 2024 18:53:24 +0900 Subject: [PATCH 07/15] =?UTF-8?q?[FIX/#10]=20Member=20DB=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=20=EC=8B=9C=20=ED=8A=B8=EB=9E=9C=EC=9E=AD=EC=85=98=20?= =?UTF-8?q?=EB=B3=B4=EC=9E=A5=EC=9D=84=20=EC=9C=84=ED=95=9C=20=EC=96=B4?= =?UTF-8?q?=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @Transactional --- .../sopt/seonyakServer/domain/member/service/MemberService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java b/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java index a738521..5dbb082 100644 --- a/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java +++ b/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java @@ -14,6 +14,7 @@ import org.sopt.seonyakServer.global.exception.model.CustomException; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @@ -80,6 +81,7 @@ public Member getBySocialId( return member; } + @Transactional public Long createMember(final MemberInfoResponse memberInfoResponse) { Member member = Member.of( memberInfoResponse.socialType(), From b7326f1aa0ac16e17b40bf14955456b82c3a78f2 Mon Sep 17 00:00:00 2001 From: ckkim817 Date: Sat, 6 Jul 2024 18:56:05 +0900 Subject: [PATCH 08/15] =?UTF-8?q?[REFACTOR/#10]=20=EC=84=B1=EB=8A=A5?= =?UTF-8?q?=EC=9D=84=20=EC=9C=84=ED=95=B4=20SocialType=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=A5=B8=20=EB=B6=84=EA=B8=B0=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EB=B0=A9=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit switch -> if문 --- .../domain/member/service/MemberService.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java b/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java index 5dbb082..2a88a7e 100644 --- a/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java +++ b/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java @@ -55,12 +55,10 @@ public MemberInfoResponse getMemberInfoResponse( final String authorizationCode, final MemberLoginRequest loginRequest ) { - switch (loginRequest.socialType()) { - case GOOGLE: - return googleSocialService.login(authorizationCode, loginRequest); - default: - throw new CustomException(ErrorType.INVALID_SOCIAL_TYPE_ERROR); + if (loginRequest.socialType() == SocialType.GOOGLE) { + return googleSocialService.login(authorizationCode, loginRequest); } + throw new CustomException(ErrorType.INVALID_SOCIAL_TYPE_ERROR); } public boolean isExistingMember( From 278a26971e8cfa803e35538375275e9cc676c8dc Mon Sep 17 00:00:00 2001 From: ckkim817 Date: Sat, 6 Jul 2024 19:15:51 +0900 Subject: [PATCH 09/15] =?UTF-8?q?[CORRECT/#10]=20=EB=AA=85=ED=99=95?= =?UTF-8?q?=ED=95=9C=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EB=AA=85=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20=EB=B0=98=ED=99=98?= =?UTF-8?q?=20=ED=83=80=EC=9E=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getBySocialId -> getMemberIdBySocialId --- .../domain/member/service/MemberService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java b/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java index 2a88a7e..a307219 100644 --- a/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java +++ b/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java @@ -37,7 +37,7 @@ private LoginSuccessResponse getTokenDto(final MemberInfoResponse memberInfoResp try { if (isExistingMember(memberInfoResponse.socialType(), memberInfoResponse.socialId())) { return getTokenByMemberId( - getBySocialId(memberInfoResponse.socialType(), memberInfoResponse.socialId()).getId() + getMemberIdBySocialId(memberInfoResponse.socialType(), memberInfoResponse.socialId()) ); } else { Long id = createMember(memberInfoResponse); @@ -46,7 +46,7 @@ private LoginSuccessResponse getTokenDto(final MemberInfoResponse memberInfoResp } } catch (DataIntegrityViolationException e) { // DB 무결성 제약 조건 위반 예외 return getTokenByMemberId( - getBySocialId(memberInfoResponse.socialType(), memberInfoResponse.socialId()).getId() + getMemberIdBySocialId(memberInfoResponse.socialType(), memberInfoResponse.socialId()) ); } } @@ -68,7 +68,7 @@ public boolean isExistingMember( return memberRepository.findBySocialTypeAndSocialId(socialType, socialId).isPresent(); } - public Member getBySocialId( + public Long getMemberIdBySocialId( final SocialType socialType, final String socialId ) { @@ -76,7 +76,7 @@ public Member getBySocialId( () -> new CustomException(ErrorType.NOT_FOUND_MEMBER_ERROR) ); - return member; + return member.getId(); } @Transactional From 375a2884385332bd45841ddf809e24bfa2abb099 Mon Sep 17 00:00:00 2001 From: ckkim817 Date: Sat, 6 Jul 2024 19:17:00 +0900 Subject: [PATCH 10/15] =?UTF-8?q?[FILE/#10]=20SocialType=20=ED=8F=B4?= =?UTF-8?q?=EB=8D=94=EB=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit global.common.external.client -> domain.member.model --- .../java/org/sopt/seonyakServer/domain/member/model/Member.java | 1 - .../external/client => domain/member/model}/SocialType.java | 2 +- .../domain/member/repository/MemberRepository.java | 2 +- .../sopt/seonyakServer/domain/member/service/MemberService.java | 2 +- .../global/common/external/client/dto/MemberInfoResponse.java | 2 +- .../global/common/external/client/dto/MemberLoginRequest.java | 2 +- .../common/external/client/google/GoogleSocialService.java | 2 +- .../global/common/external/client/service/SocialService.java | 2 +- 8 files changed, 7 insertions(+), 8 deletions(-) rename src/main/java/org/sopt/seonyakServer/{global/common/external/client => domain/member/model}/SocialType.java (79%) diff --git a/src/main/java/org/sopt/seonyakServer/domain/member/model/Member.java b/src/main/java/org/sopt/seonyakServer/domain/member/model/Member.java index 107cf81..354e650 100644 --- a/src/main/java/org/sopt/seonyakServer/domain/member/model/Member.java +++ b/src/main/java/org/sopt/seonyakServer/domain/member/model/Member.java @@ -11,7 +11,6 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import org.sopt.seonyakServer.global.common.external.client.SocialType; @Entity @Getter diff --git a/src/main/java/org/sopt/seonyakServer/global/common/external/client/SocialType.java b/src/main/java/org/sopt/seonyakServer/domain/member/model/SocialType.java similarity index 79% rename from src/main/java/org/sopt/seonyakServer/global/common/external/client/SocialType.java rename to src/main/java/org/sopt/seonyakServer/domain/member/model/SocialType.java index 24aa224..a776dfa 100644 --- a/src/main/java/org/sopt/seonyakServer/global/common/external/client/SocialType.java +++ b/src/main/java/org/sopt/seonyakServer/domain/member/model/SocialType.java @@ -1,4 +1,4 @@ -package org.sopt.seonyakServer.global.common.external.client; +package org.sopt.seonyakServer.domain.member.model; import lombok.AccessLevel; import lombok.Getter; diff --git a/src/main/java/org/sopt/seonyakServer/domain/member/repository/MemberRepository.java b/src/main/java/org/sopt/seonyakServer/domain/member/repository/MemberRepository.java index a0ab262..a5b91d8 100644 --- a/src/main/java/org/sopt/seonyakServer/domain/member/repository/MemberRepository.java +++ b/src/main/java/org/sopt/seonyakServer/domain/member/repository/MemberRepository.java @@ -2,7 +2,7 @@ import java.util.Optional; import org.sopt.seonyakServer.domain.member.model.Member; -import org.sopt.seonyakServer.global.common.external.client.SocialType; +import org.sopt.seonyakServer.domain.member.model.SocialType; import org.springframework.data.jpa.repository.JpaRepository; public interface MemberRepository extends JpaRepository { diff --git a/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java b/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java index a307219..ba385f3 100644 --- a/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java +++ b/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java @@ -3,10 +3,10 @@ import lombok.RequiredArgsConstructor; import org.sopt.seonyakServer.domain.member.dto.LoginSuccessResponse; import org.sopt.seonyakServer.domain.member.model.Member; +import org.sopt.seonyakServer.domain.member.model.SocialType; import org.sopt.seonyakServer.domain.member.repository.MemberRepository; import org.sopt.seonyakServer.global.auth.MemberAuthentication; import org.sopt.seonyakServer.global.auth.jwt.JwtTokenProvider; -import org.sopt.seonyakServer.global.common.external.client.SocialType; import org.sopt.seonyakServer.global.common.external.client.dto.MemberInfoResponse; import org.sopt.seonyakServer.global.common.external.client.dto.MemberLoginRequest; import org.sopt.seonyakServer.global.common.external.client.google.GoogleSocialService; diff --git a/src/main/java/org/sopt/seonyakServer/global/common/external/client/dto/MemberInfoResponse.java b/src/main/java/org/sopt/seonyakServer/global/common/external/client/dto/MemberInfoResponse.java index 5bfa9de..a0d6f12 100644 --- a/src/main/java/org/sopt/seonyakServer/global/common/external/client/dto/MemberInfoResponse.java +++ b/src/main/java/org/sopt/seonyakServer/global/common/external/client/dto/MemberInfoResponse.java @@ -1,7 +1,7 @@ package org.sopt.seonyakServer.global.common.external.client.dto; -import org.sopt.seonyakServer.global.common.external.client.SocialType; +import org.sopt.seonyakServer.domain.member.model.SocialType; public record MemberInfoResponse( SocialType socialType, diff --git a/src/main/java/org/sopt/seonyakServer/global/common/external/client/dto/MemberLoginRequest.java b/src/main/java/org/sopt/seonyakServer/global/common/external/client/dto/MemberLoginRequest.java index 4fcc31b..65ba4d5 100644 --- a/src/main/java/org/sopt/seonyakServer/global/common/external/client/dto/MemberLoginRequest.java +++ b/src/main/java/org/sopt/seonyakServer/global/common/external/client/dto/MemberLoginRequest.java @@ -1,7 +1,7 @@ package org.sopt.seonyakServer.global.common.external.client.dto; import jakarta.validation.constraints.NotNull; -import org.sopt.seonyakServer.global.common.external.client.SocialType; +import org.sopt.seonyakServer.domain.member.model.SocialType; public record MemberLoginRequest( String redirectUri, diff --git a/src/main/java/org/sopt/seonyakServer/global/common/external/client/google/GoogleSocialService.java b/src/main/java/org/sopt/seonyakServer/global/common/external/client/google/GoogleSocialService.java index 753038a..cb0b922 100644 --- a/src/main/java/org/sopt/seonyakServer/global/common/external/client/google/GoogleSocialService.java +++ b/src/main/java/org/sopt/seonyakServer/global/common/external/client/google/GoogleSocialService.java @@ -4,7 +4,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.sopt.seonyakServer.global.common.external.client.SocialType; +import org.sopt.seonyakServer.domain.member.model.SocialType; import org.sopt.seonyakServer.global.common.external.client.dto.GoogleUserInfoResponse; import org.sopt.seonyakServer.global.common.external.client.dto.MemberInfoResponse; import org.sopt.seonyakServer.global.common.external.client.dto.MemberLoginRequest; diff --git a/src/main/java/org/sopt/seonyakServer/global/common/external/client/service/SocialService.java b/src/main/java/org/sopt/seonyakServer/global/common/external/client/service/SocialService.java index acfa051..8c92d89 100644 --- a/src/main/java/org/sopt/seonyakServer/global/common/external/client/service/SocialService.java +++ b/src/main/java/org/sopt/seonyakServer/global/common/external/client/service/SocialService.java @@ -1,6 +1,6 @@ package org.sopt.seonyakServer.global.common.external.client.service; -import org.sopt.seonyakServer.global.common.external.client.SocialType; +import org.sopt.seonyakServer.domain.member.model.SocialType; import org.sopt.seonyakServer.global.common.external.client.dto.MemberInfoResponse; import org.sopt.seonyakServer.global.common.external.client.dto.MemberLoginRequest; From 7c11340b8ca0abe30a2ae83c8632cebc1488cd14 Mon Sep 17 00:00:00 2001 From: ckkim817 Date: Sun, 7 Jul 2024 00:33:55 +0900 Subject: [PATCH 11/15] =?UTF-8?q?[FIX/#10]=20=EC=8A=A4=ED=94=84=EB=A7=81?= =?UTF-8?q?=20@Transactional=EC=9D=98=20=EC=9E=90=EA=B8=B0=20=ED=98=B8?= =?UTF-8?q?=EC=B6=9C=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0=EC=9D=84=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MemberService + MemberManagementService --- .../service/MemberManagementService.java | 26 ++++++++++++++ .../domain/member/service/MemberService.java | 35 +++++++------------ 2 files changed, 38 insertions(+), 23 deletions(-) create mode 100644 src/main/java/org/sopt/seonyakServer/domain/member/service/MemberManagementService.java diff --git a/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberManagementService.java b/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberManagementService.java new file mode 100644 index 0000000..fed4614 --- /dev/null +++ b/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberManagementService.java @@ -0,0 +1,26 @@ +package org.sopt.seonyakServer.domain.member.service; + +import lombok.RequiredArgsConstructor; +import org.sopt.seonyakServer.domain.member.model.Member; +import org.sopt.seonyakServer.domain.member.repository.MemberRepository; +import org.sopt.seonyakServer.global.common.external.client.dto.MemberInfoResponse; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class MemberManagementService { + + private final MemberRepository memberRepository; + + @Transactional + public Long createMember(final MemberInfoResponse memberInfoResponse) { + Member member = Member.of( + memberInfoResponse.socialType(), + memberInfoResponse.socialId(), + memberInfoResponse.email() + ); + + return memberRepository.save(member).getId(); + } +} diff --git a/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java b/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java index ba385f3..ad677fb 100644 --- a/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java +++ b/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java @@ -14,7 +14,6 @@ import org.sopt.seonyakServer.global.exception.model.CustomException; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @@ -23,6 +22,7 @@ public class MemberService { private final MemberRepository memberRepository; private final JwtTokenProvider jwtTokenProvider; private final GoogleSocialService googleSocialService; + private final MemberManagementService memberManagementService; public LoginSuccessResponse create( final String authorizationCode, @@ -33,6 +33,16 @@ public LoginSuccessResponse create( ); } + public MemberInfoResponse getMemberInfoResponse( + final String authorizationCode, + final MemberLoginRequest loginRequest + ) { + if (loginRequest.socialType() == SocialType.GOOGLE) { + return googleSocialService.login(authorizationCode, loginRequest); + } + throw new CustomException(ErrorType.INVALID_SOCIAL_TYPE_ERROR); + } + private LoginSuccessResponse getTokenDto(final MemberInfoResponse memberInfoResponse) { try { if (isExistingMember(memberInfoResponse.socialType(), memberInfoResponse.socialId())) { @@ -40,7 +50,7 @@ private LoginSuccessResponse getTokenDto(final MemberInfoResponse memberInfoResp getMemberIdBySocialId(memberInfoResponse.socialType(), memberInfoResponse.socialId()) ); } else { - Long id = createMember(memberInfoResponse); + Long id = memberManagementService.createMember(memberInfoResponse); return getTokenByMemberId(id); } @@ -51,16 +61,6 @@ private LoginSuccessResponse getTokenDto(final MemberInfoResponse memberInfoResp } } - public MemberInfoResponse getMemberInfoResponse( - final String authorizationCode, - final MemberLoginRequest loginRequest - ) { - if (loginRequest.socialType() == SocialType.GOOGLE) { - return googleSocialService.login(authorizationCode, loginRequest); - } - throw new CustomException(ErrorType.INVALID_SOCIAL_TYPE_ERROR); - } - public boolean isExistingMember( final SocialType socialType, final String socialId @@ -79,17 +79,6 @@ public Long getMemberIdBySocialId( return member.getId(); } - @Transactional - public Long createMember(final MemberInfoResponse memberInfoResponse) { - Member member = Member.of( - memberInfoResponse.socialType(), - memberInfoResponse.socialId(), - memberInfoResponse.email() - ); - - return memberRepository.save(member).getId(); - } - public LoginSuccessResponse getTokenByMemberId(final Long id) { MemberAuthentication memberAuthentication = new MemberAuthentication(id, null, null); From 4f0e0413a6972f7ed82add6babe110394dc254c2 Mon Sep 17 00:00:00 2001 From: ckkim817 Date: Sun, 7 Jul 2024 00:59:57 +0900 Subject: [PATCH 12/15] =?UTF-8?q?[CHORE#/10]=20=EC=BB=A4=EC=8A=A4=ED=85=80?= =?UTF-8?q?=20=ED=95=84=ED=84=B0=20=EC=B2=B4=EC=9D=B8=20=EA=B3=BC=EC=A0=95?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=98=88=EC=99=B8=20=EB=B0=9C=EC=83=9D=20?= =?UTF-8?q?=EC=8B=9C=20=EC=BD=98=EC=86=94=EC=97=90=20=EB=A1=9C=EA=B7=B8=20?= =?UTF-8?q?=ED=91=9C=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/auth/filter/JwtAuthenticationFilter.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/org/sopt/seonyakServer/global/auth/filter/JwtAuthenticationFilter.java b/src/main/java/org/sopt/seonyakServer/global/auth/filter/JwtAuthenticationFilter.java index 30d9eae..315e6d0 100644 --- a/src/main/java/org/sopt/seonyakServer/global/auth/filter/JwtAuthenticationFilter.java +++ b/src/main/java/org/sopt/seonyakServer/global/auth/filter/JwtAuthenticationFilter.java @@ -9,6 +9,7 @@ import java.io.IOException; import lombok.NonNull; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.sopt.seonyakServer.global.auth.MemberAuthentication; import org.sopt.seonyakServer.global.auth.jwt.JwtTokenProvider; import org.sopt.seonyakServer.global.exception.enums.ErrorType; @@ -21,6 +22,7 @@ @Component @RequiredArgsConstructor +@Slf4j public class JwtAuthenticationFilter extends OncePerRequestFilter { private final JwtTokenProvider jwtTokenProvider; @@ -41,7 +43,13 @@ protected void doFilterInternal(@NonNull HttpServletRequest request, SecurityContextHolder.getContext().setAuthentication(authentication); } } catch (Exception exception) { + // SecurityConfig에서 permitAll을 적용해도, Spring Security의 필터 체인을 거치므로 + // 여기서 바로 Exception throw를 하게 되면 permitAll과 상관 없이 ExceptionTranslationFilter로 처리가 넘어간다. + // 따라서 예외를 직접 throw로 던져주는 것이 아닌, 발생시키기만 하고 다음 필터 호출로 이어지게끔 해야 하고, (doFilter) + // 이렇게 하면 API의 permitAll 적용 여부에 따라 ExceptionTranslationFilter를 거칠지 판단하게 된다. + log.error("JwtAuthentication Authentication Exception Occurs! - {}", exception.getMessage()); } + // 다음 필터로 요청 전달 (호출) filterChain.doFilter(request, response); } From a5108d9f768d301a2d2d28aabbfd7a3ff22f84fa Mon Sep 17 00:00:00 2001 From: ckkim817 Date: Sun, 7 Jul 2024 01:01:35 +0900 Subject: [PATCH 13/15] =?UTF-8?q?[CORRECT/#10]=20=EB=AA=85=ED=99=95?= =?UTF-8?q?=ED=95=9C=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EB=AA=85=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/auth/filter/JwtAuthenticationFilter.java | 2 +- .../sopt/seonyakServer/global/auth/jwt/JwtTokenProvider.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/sopt/seonyakServer/global/auth/filter/JwtAuthenticationFilter.java b/src/main/java/org/sopt/seonyakServer/global/auth/filter/JwtAuthenticationFilter.java index 315e6d0..f8538c5 100644 --- a/src/main/java/org/sopt/seonyakServer/global/auth/filter/JwtAuthenticationFilter.java +++ b/src/main/java/org/sopt/seonyakServer/global/auth/filter/JwtAuthenticationFilter.java @@ -35,7 +35,7 @@ protected void doFilterInternal(@NonNull HttpServletRequest request, final String token = getJwtFromRequest(request); if (jwtTokenProvider.validateToken(token) == VALID_JWT) { - Long memberId = jwtTokenProvider.getMemberFromJwt(token); + Long memberId = jwtTokenProvider.getMemberIdFromJwt(token); // authentication 객체 생성 -> principal에 유저정보를 담는다. MemberAuthentication authentication = new MemberAuthentication(memberId.toString(), null, null); diff --git a/src/main/java/org/sopt/seonyakServer/global/auth/jwt/JwtTokenProvider.java b/src/main/java/org/sopt/seonyakServer/global/auth/jwt/JwtTokenProvider.java index f127535..ac573fb 100644 --- a/src/main/java/org/sopt/seonyakServer/global/auth/jwt/JwtTokenProvider.java +++ b/src/main/java/org/sopt/seonyakServer/global/auth/jwt/JwtTokenProvider.java @@ -101,7 +101,7 @@ private Claims getBody(final String token) { .getBody(); } - public Long getMemberFromJwt(String token) { + public Long getMemberIdFromJwt(String token) { Claims claims = getBody(getTokenFromHeader(token)); return Long.valueOf(claims.get(MEMBER_ID).toString()); From 56f0d840b3e0a71459bbdd68791b129f785cad9e Mon Sep 17 00:00:00 2001 From: ckkim817 Date: Sun, 7 Jul 2024 01:03:29 +0900 Subject: [PATCH 14/15] =?UTF-8?q?[DEL/#10]=20=EC=A4=91=EB=B3=B5=EB=90=9C?= =?UTF-8?q?=20Bearer=20=EC=B2=98=EB=A6=AC=20=EA=B3=BC=EC=A0=95=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JwtAuthenticationFilter에 이미 존재 --- .../global/auth/jwt/JwtTokenProvider.java | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/sopt/seonyakServer/global/auth/jwt/JwtTokenProvider.java b/src/main/java/org/sopt/seonyakServer/global/auth/jwt/JwtTokenProvider.java index ac573fb..568cf04 100644 --- a/src/main/java/org/sopt/seonyakServer/global/auth/jwt/JwtTokenProvider.java +++ b/src/main/java/org/sopt/seonyakServer/global/auth/jwt/JwtTokenProvider.java @@ -13,12 +13,9 @@ import java.util.Date; import javax.crypto.SecretKey; import lombok.RequiredArgsConstructor; -import org.sopt.seonyakServer.global.exception.enums.ErrorType; -import org.sopt.seonyakServer.global.exception.model.CustomException; import org.springframework.beans.factory.annotation.Value; import org.springframework.security.core.Authentication; import org.springframework.stereotype.Component; -import org.springframework.util.StringUtils; @Component @RequiredArgsConstructor @@ -38,16 +35,6 @@ protected void init() { JWT_SECRET = Base64.getEncoder().encodeToString(JWT_SECRET.getBytes(StandardCharsets.UTF_8)); } - private String getTokenFromHeader(final String token) { - if (!StringUtils.hasText(token)) { - throw new CustomException(ErrorType.UN_LOGIN_ERROR); - } else if (StringUtils.hasText(token) && !token.startsWith("Bearer ")) { - throw new CustomException(ErrorType.BEARER_LOST_ERROR); - } - - return token.substring("Bearer ".length()); - } - public String issueAccessToken(final Authentication authentication) { return generateToken(authentication, ACCESS_TOKEN_EXPIRATION_TIME); } @@ -80,7 +67,7 @@ private SecretKey getSigningKey() { public JwtValidationType validateToken(String token) { try { - final Claims claims = getBody(getTokenFromHeader(token)); + final Claims claims = getBody(token); return JwtValidationType.VALID_JWT; } catch (MalformedJwtException ex) { return JwtValidationType.INVALID_JWT_TOKEN; @@ -102,7 +89,7 @@ private Claims getBody(final String token) { } public Long getMemberIdFromJwt(String token) { - Claims claims = getBody(getTokenFromHeader(token)); + Claims claims = getBody(token); return Long.valueOf(claims.get(MEMBER_ID).toString()); } From 96d99ff319e18c2cfe08f02c69853f07684c1eea Mon Sep 17 00:00:00 2001 From: ckkim817 Date: Sun, 7 Jul 2024 01:21:29 +0900 Subject: [PATCH 15/15] =?UTF-8?q?[CHORE/#10]=20=EC=A3=BC=EC=84=9D=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 --- .../domain/member/service/MemberManagementService.java | 1 + .../seonyakServer/domain/member/service/MemberService.java | 3 +++ .../global/auth/filter/CustomAccessDeniedHandler.java | 1 + .../global/auth/filter/CustomJwtAuthenticationEntryPoint.java | 1 + .../global/auth/filter/JwtAuthenticationFilter.java | 2 ++ .../seonyakServer/global/auth/security/SecurityConfig.java | 2 +- 6 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberManagementService.java b/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberManagementService.java index fed4614..4e3ca35 100644 --- a/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberManagementService.java +++ b/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberManagementService.java @@ -10,6 +10,7 @@ @Service @RequiredArgsConstructor public class MemberManagementService { + // 트랜잭션 작업을 관리할 서비스 클래스 (자기 호출 방지 및 단일 책임 원칙 준수) private final MemberRepository memberRepository; diff --git a/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java b/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java index ad677fb..873316b 100644 --- a/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java +++ b/src/main/java/org/sopt/seonyakServer/domain/member/service/MemberService.java @@ -24,6 +24,7 @@ public class MemberService { private final GoogleSocialService googleSocialService; private final MemberManagementService memberManagementService; + // JWT Access Token 생성 public LoginSuccessResponse create( final String authorizationCode, final MemberLoginRequest loginRequest @@ -33,6 +34,7 @@ public LoginSuccessResponse create( ); } + // 소셜 플랫폼으로부터 해당 유저 정보를 받아옴 public MemberInfoResponse getMemberInfoResponse( final String authorizationCode, final MemberLoginRequest loginRequest @@ -43,6 +45,7 @@ public MemberInfoResponse getMemberInfoResponse( throw new CustomException(ErrorType.INVALID_SOCIAL_TYPE_ERROR); } + // Access Token을 생성할 때, 해당 유저의 회원가입 여부를 판단 private LoginSuccessResponse getTokenDto(final MemberInfoResponse memberInfoResponse) { try { if (isExistingMember(memberInfoResponse.socialType(), memberInfoResponse.socialId())) { diff --git a/src/main/java/org/sopt/seonyakServer/global/auth/filter/CustomAccessDeniedHandler.java b/src/main/java/org/sopt/seonyakServer/global/auth/filter/CustomAccessDeniedHandler.java index 1513835..264333d 100644 --- a/src/main/java/org/sopt/seonyakServer/global/auth/filter/CustomAccessDeniedHandler.java +++ b/src/main/java/org/sopt/seonyakServer/global/auth/filter/CustomAccessDeniedHandler.java @@ -10,6 +10,7 @@ @Component public class CustomAccessDeniedHandler implements AccessDeniedHandler { + // 사용자가 인증은 되었지만 특정 리소스에 접근할 권한이 없을 때 호출 @Override public void handle(HttpServletRequest request, diff --git a/src/main/java/org/sopt/seonyakServer/global/auth/filter/CustomJwtAuthenticationEntryPoint.java b/src/main/java/org/sopt/seonyakServer/global/auth/filter/CustomJwtAuthenticationEntryPoint.java index 6f03929..2a81996 100644 --- a/src/main/java/org/sopt/seonyakServer/global/auth/filter/CustomJwtAuthenticationEntryPoint.java +++ b/src/main/java/org/sopt/seonyakServer/global/auth/filter/CustomJwtAuthenticationEntryPoint.java @@ -10,6 +10,7 @@ @Component @RequiredArgsConstructor public class CustomJwtAuthenticationEntryPoint implements AuthenticationEntryPoint { + // 사용자가 인증되지 않은 상태에서 보호된 리소스에 접근하려고 할 때 호출 @Override public void commence(HttpServletRequest request, diff --git a/src/main/java/org/sopt/seonyakServer/global/auth/filter/JwtAuthenticationFilter.java b/src/main/java/org/sopt/seonyakServer/global/auth/filter/JwtAuthenticationFilter.java index f8538c5..dcfb42c 100644 --- a/src/main/java/org/sopt/seonyakServer/global/auth/filter/JwtAuthenticationFilter.java +++ b/src/main/java/org/sopt/seonyakServer/global/auth/filter/JwtAuthenticationFilter.java @@ -27,6 +27,7 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter { private final JwtTokenProvider jwtTokenProvider; + // 각 HTTP 요청에 대해 토큰이 유효한지 확인하고, 유효하다면 해당 사용자를 인증 설정하는 필터링 로직 @Override protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, @@ -53,6 +54,7 @@ protected void doFilterInternal(@NonNull HttpServletRequest request, filterChain.doFilter(request, response); } + // Authorization 헤더에서 JWT 토큰을 추출 private String getJwtFromRequest(HttpServletRequest request) { String bearerToken = request.getHeader("Authorization"); diff --git a/src/main/java/org/sopt/seonyakServer/global/auth/security/SecurityConfig.java b/src/main/java/org/sopt/seonyakServer/global/auth/security/SecurityConfig.java index 9704152..40f7290 100644 --- a/src/main/java/org/sopt/seonyakServer/global/auth/security/SecurityConfig.java +++ b/src/main/java/org/sopt/seonyakServer/global/auth/security/SecurityConfig.java @@ -15,7 +15,7 @@ @Configuration @RequiredArgsConstructor -@EnableWebSecurity // web Security를 사용할 수 있게 +@EnableWebSecurity // WebSecurity를 사용할 수 있게 public class SecurityConfig { private final JwtAuthenticationFilter jwtAuthenticationFilter;