From 2f4b65a642d599f083a31bc3138a0416425794aa Mon Sep 17 00:00:00 2001 From: bflykky Date: Tue, 6 Aug 2024 18:54:28 +0900 Subject: [PATCH 1/3] =?UTF-8?q?refactor:=20spring=20ai=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=EC=A0=9D=ED=8A=B8=20=EC=9D=98=EC=A1=B4=EC=84=B1=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EA=B0=84=EC=86=8C=ED=99=94,=20commons-log?= =?UTF-8?q?ging=20exclude,=20=EB=AF=B8=EC=82=AC=EC=9A=A9=20=EC=9D=98?= =?UTF-8?q?=EC=A1=B4=EC=84=B1=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit platform 종속성 핸들러 메소드를 통해 의존성 설정을 간소화하였다. 어플리케이션 실행 시 발생하는 경고 로그에 따라, commons-logging:commons-logging을 exclude하였다. --- build.gradle | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/build.gradle b/build.gradle index 5ba01d2f..ba3b7ee7 100644 --- a/build.gradle +++ b/build.gradle @@ -17,16 +17,17 @@ configurations { compileOnly { extendsFrom annotationProcessor } + + configureEach { + exclude group: 'commons-logging', module: 'commons-logging' + } } repositories { mavenCentral() maven { url 'https://jitpack.io' } maven { url 'https://repo.spring.io/milestone' } -} - -ext { - set('springAiVersion', "1.0.0-M1") + maven { url 'https://repo.spring.io/snapshot' } } dependencies { @@ -39,13 +40,12 @@ dependencies { implementation 'io.jsonwebtoken:jjwt-api:0.12.5' runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.5' runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.12.5' - implementation 'commons-io:commons-io:2.6' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' // GPT 프롬프트 + implementation platform("org.springframework.ai:spring-ai-bom:1.0.0-SNAPSHOT") implementation 'org.springframework.ai:spring-ai-openai-spring-boot-starter' - // implementation 'io.github.flashvayne:chatgpt-spring-boot-starter:1.0.4' // redis implementation 'org.springframework.boot:spring-boot-starter-data-redis' @@ -61,9 +61,9 @@ dependencies { testImplementation 'org.springframework.security:spring-security-test' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' - //firebase + // firebase implementation 'com.google.firebase:firebase-admin:8.1.0' - //조사 처르를 쉽게 하기 위한 라이브러리 + // 조사 처르를 쉽게 하기 위한 라이브러리 implementation 'com.github.josa-moa:josa-moa:1.0.3' // AWS @@ -72,16 +72,10 @@ dependencies { implementation 'io.awspring.cloud:spring-cloud-aws-starter-s3' implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE' - //elasticsearch + // elasticsearch implementation 'org.springframework.data:spring-data-elasticsearch:' } -dependencyManagement { - imports { - mavenBom "org.springframework.ai:spring-ai-bom:${springAiVersion}" - } -} - tasks.named('test') { useJUnitPlatform() } \ No newline at end of file From 4cb3215eeb68e606d4af5735fe71381e3d8af830 Mon Sep 17 00:00:00 2001 From: bflykky Date: Tue, 6 Aug 2024 22:24:30 +0900 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=ED=9A=8C=EC=9B=90=EA=B0=80=EC=9E=85?= =?UTF-8?q?=20=EC=97=AC=EB=B6=80=20=ED=99=95=EC=9D=B8=20=EC=8B=9C=20authId?= =?UTF-8?q?=20=EB=B0=8F=20socialType=EC=9D=84=20=ED=86=B5=ED=95=B4=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8F=84=EB=A1=9D=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 --- .../umc/naoman/domain/member/repository/MemberRepository.java | 1 + .../com/umc/naoman/domain/member/service/MemberService.java | 2 +- .../umc/naoman/domain/member/service/MemberServiceImpl.java | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/umc/naoman/domain/member/repository/MemberRepository.java b/src/main/java/com/umc/naoman/domain/member/repository/MemberRepository.java index 38a83941..cb7db885 100644 --- a/src/main/java/com/umc/naoman/domain/member/repository/MemberRepository.java +++ b/src/main/java/com/umc/naoman/domain/member/repository/MemberRepository.java @@ -12,4 +12,5 @@ public interface MemberRepository extends JpaRepository { Optional findByEmail(String email); Optional findByAuthIdAndSocialType(String authId, SocialType socialType); Boolean existsByEmail(String email); + Boolean existsBySocialTypeAndAuthId(SocialType socialType, String authId); } diff --git a/src/main/java/com/umc/naoman/domain/member/service/MemberService.java b/src/main/java/com/umc/naoman/domain/member/service/MemberService.java index f9c26d15..880bf63f 100644 --- a/src/main/java/com/umc/naoman/domain/member/service/MemberService.java +++ b/src/main/java/com/umc/naoman/domain/member/service/MemberService.java @@ -13,7 +13,7 @@ public interface MemberService { Member findMember(Long memberId); Member findMember(String email); Member findMember(String authId, SocialType socialType); - CheckMemberRegistration checkRegistration(String email); + CheckMemberRegistration checkRegistration(LoginRequest request); LoginInfo signup(SignupRequest request); LoginInfo signup(String tempMemberInfo, MarketingAgreedRequest request); LoginInfo login(LoginRequest request); diff --git a/src/main/java/com/umc/naoman/domain/member/service/MemberServiceImpl.java b/src/main/java/com/umc/naoman/domain/member/service/MemberServiceImpl.java index c00337e7..a596b592 100644 --- a/src/main/java/com/umc/naoman/domain/member/service/MemberServiceImpl.java +++ b/src/main/java/com/umc/naoman/domain/member/service/MemberServiceImpl.java @@ -53,8 +53,8 @@ public Member findMember(String authId, SocialType socialType) { } @Override - public CheckMemberRegistration checkRegistration(String email) { - boolean isRegistered = memberRepository.existsByEmail(email); + public CheckMemberRegistration checkRegistration(LoginRequest request) { + boolean isRegistered = memberRepository.existsBySocialTypeAndAuthId(request.getSocialType(), request.getAuthId()); return new CheckMemberRegistration(isRegistered); } From 229b952094900dd4b5a9a9b80d08e03717048581 Mon Sep 17 00:00:00 2001 From: bflykky Date: Tue, 6 Aug 2024 22:28:23 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20OAuth2LoginSuccessHandler=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=ED=9A=8C=EC=9B=90=EA=B0=80=EC=9E=85=20=EC=97=AC?= =?UTF-8?q?=EB=B6=80=20=ED=99=95=EC=9D=B8=20=EC=8B=9C=20socialType,=20auth?= =?UTF-8?q?Id=EB=A1=9C=20=ED=8C=90=EB=B3=84=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/AuthController.java | 9 ++-- .../domain/member/service/MemberService.java | 9 ++-- .../member/service/MemberServiceImpl.java | 45 +++++++++---------- .../handler/OAuth2LoginSuccessHandler.java | 2 +- .../security/model/CustomOAuth2User.java | 9 +++- 5 files changed, 35 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/umc/naoman/domain/member/controller/AuthController.java b/src/main/java/com/umc/naoman/domain/member/controller/AuthController.java index 62c02d98..9a60aa71 100644 --- a/src/main/java/com/umc/naoman/domain/member/controller/AuthController.java +++ b/src/main/java/com/umc/naoman/domain/member/controller/AuthController.java @@ -63,11 +63,8 @@ public ResultResponse login(@Valid @RequestBody LoginRequest request) } @GetMapping("/check-registration") - @Operation(summary = "회원가입 여부 조회 API", description = "이메일을 통해, 해당 이메일을 가진 회원의 가입 여부를 조회하는 API입니다.") - @Parameters(value = { - @Parameter(name = "email", description = "회원가입 여부를 확인할 이메일을 입력해 주세요.") - }) - public ResultResponse checkSignup(@RequestParam("email") @Valid @Email String email) { - return ResultResponse.of(CHECK_MEMBER_REGISTRATION, memberService.checkRegistration(email)); + @Operation(summary = "회원가입 여부 조회 API", description = "authId와 플랫폼명을 통해, 해당 정보와 일치하는 회원의 가입 여부를 조회하는 API입니다.") + public ResultResponse checkSignup(@Valid @RequestBody LoginRequest request) { + return ResultResponse.of(CHECK_MEMBER_REGISTRATION, memberService.checkRegistration(request)); } } diff --git a/src/main/java/com/umc/naoman/domain/member/service/MemberService.java b/src/main/java/com/umc/naoman/domain/member/service/MemberService.java index 880bf63f..da9cca45 100644 --- a/src/main/java/com/umc/naoman/domain/member/service/MemberService.java +++ b/src/main/java/com/umc/naoman/domain/member/service/MemberService.java @@ -10,12 +10,11 @@ import com.umc.naoman.domain.member.entity.SocialType; public interface MemberService { - Member findMember(Long memberId); - Member findMember(String email); - Member findMember(String authId, SocialType socialType); - CheckMemberRegistration checkRegistration(LoginRequest request); - LoginInfo signup(SignupRequest request); LoginInfo signup(String tempMemberInfo, MarketingAgreedRequest request); + LoginInfo signup(SignupRequest request); LoginInfo login(LoginRequest request); + CheckMemberRegistration checkRegistration(LoginRequest request); MemberInfo getMyInfo(Member member); + Member findMember(Long memberId); + Member findMember(SocialType socialType, String authId); } diff --git a/src/main/java/com/umc/naoman/domain/member/service/MemberServiceImpl.java b/src/main/java/com/umc/naoman/domain/member/service/MemberServiceImpl.java index a596b592..0244e14c 100644 --- a/src/main/java/com/umc/naoman/domain/member/service/MemberServiceImpl.java +++ b/src/main/java/com/umc/naoman/domain/member/service/MemberServiceImpl.java @@ -34,30 +34,6 @@ public class MemberServiceImpl implements MemberService { @Value("${jwt.refresh-token-validity-in-seconds}") private Long REFRESH_TOKEN_VALIDITY_IN_SECONDS; - @Override - public Member findMember(Long memberId) { - return memberRepository.findById(memberId) - .orElseThrow(() -> new BusinessException(MEMBER_NOT_FOUND_BY_MEMBER_ID)); - } - - @Override - public Member findMember(String email) { - return memberRepository.findByEmail(email) - .orElseThrow(() -> new BusinessException(MEMBER_NOT_FOUND_BY_EMAIL)); - } - - @Override - public Member findMember(String authId, SocialType socialType) { - return memberRepository.findByAuthIdAndSocialType(authId, socialType) - .orElseThrow(() -> new BusinessException(MEMBER_NOT_FOUND_BY_AUTH_ID_AND_SOCIAL_TYPE)); - } - - @Override - public CheckMemberRegistration checkRegistration(LoginRequest request) { - boolean isRegistered = memberRepository.existsBySocialTypeAndAuthId(request.getSocialType(), request.getAuthId()); - return new CheckMemberRegistration(isRegistered); - } - @Override @Transactional public LoginInfo signup(SignupRequest request) { @@ -90,7 +66,7 @@ public LoginInfo signup(String tempMemberInfo, MarketingAgreedRequest request) { @Override public LoginInfo login(LoginRequest request) { - Member member = findMember(request.getAuthId(), request.getSocialType()); + Member member = findMember(request.getSocialType(), request.getAuthId()); Long memberId = member.getId(); String email = member.getEmail(); @@ -102,8 +78,27 @@ public LoginInfo login(LoginRequest request) { return memberConverter.toLoginInfo(memberId, accessToken, refreshToken); } + @Override + public CheckMemberRegistration checkRegistration(LoginRequest request) { + boolean isRegistered = memberRepository.existsBySocialTypeAndAuthId(request.getSocialType(), request.getAuthId()); + return new CheckMemberRegistration(isRegistered); + } + @Override public MemberInfo getMyInfo(Member member) { return memberConverter.toMemberInfo(member); } + + @Override + public Member findMember(Long memberId) { + return memberRepository.findById(memberId) + .orElseThrow(() -> new BusinessException(MEMBER_NOT_FOUND_BY_MEMBER_ID)); + } + + @Override + public Member findMember(SocialType socialType, String authId) { + return memberRepository.findByAuthIdAndSocialType(authId, socialType) + .orElseThrow(() -> new BusinessException(MEMBER_NOT_FOUND_BY_AUTH_ID_AND_SOCIAL_TYPE)); + } + } diff --git a/src/main/java/com/umc/naoman/global/security/handler/OAuth2LoginSuccessHandler.java b/src/main/java/com/umc/naoman/global/security/handler/OAuth2LoginSuccessHandler.java index a122b703..1673b05a 100644 --- a/src/main/java/com/umc/naoman/global/security/handler/OAuth2LoginSuccessHandler.java +++ b/src/main/java/com/umc/naoman/global/security/handler/OAuth2LoginSuccessHandler.java @@ -49,7 +49,7 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo CustomOAuth2User oAuth2User = (CustomOAuth2User) authentication.getPrincipal(); try { // 이미 회원가입된 회원인 경우 - Member member = memberService.findMember(oAuth2User.getEmail()); + Member member = memberService.findMember(oAuth2User.getProvider(), oAuth2User.getAuthId()); handleExistingMemberLogin(request, response, oAuth2User, member); } catch (BusinessException e) { // 회원가입되어 있지 않은 경우 handleMemberSignup(request, response, oAuth2User.getOAuthAttribute()); diff --git a/src/main/java/com/umc/naoman/global/security/model/CustomOAuth2User.java b/src/main/java/com/umc/naoman/global/security/model/CustomOAuth2User.java index 2d648620..2b3368d9 100644 --- a/src/main/java/com/umc/naoman/global/security/model/CustomOAuth2User.java +++ b/src/main/java/com/umc/naoman/global/security/model/CustomOAuth2User.java @@ -1,5 +1,6 @@ package com.umc.naoman.global.security.model; +import com.umc.naoman.domain.member.entity.SocialType; import com.umc.naoman.global.security.attribute.OAuthAttribute; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.oauth2.core.user.DefaultOAuth2User; @@ -20,7 +21,11 @@ public OAuthAttribute getOAuthAttribute() { return oAuthAttribute; } - public String getEmail() { - return this.oAuthAttribute.getEmail(); + public SocialType getProvider() { + return this.oAuthAttribute.getProvider(); + } + + public String getAuthId() { + return this.oAuthAttribute.getAuthId(); } }