diff --git a/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/domain/entity/Member.java b/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/domain/entity/Member.java index 5fa4a3ab..c61ceefa 100644 --- a/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/domain/entity/Member.java +++ b/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/domain/entity/Member.java @@ -96,13 +96,17 @@ public Member(String name, String email, Role role) { this.ibasInformation = new IbasInformation(role); } + public String getStudentId() { + return this.studentId != null ? this.studentId.getValue() : null; + } + public String getName() { return this.name != null ? this.name.getValue() : null; } + public String getPhone() { return this.phone != null ? this.phone.getValue() : null; } - public SchoolInformation getSchoolInformation() { return this.schoolInformation != null ? this.schoolInformation : null; } @@ -123,6 +127,10 @@ public boolean isDeleted() { public void setName(String name) { this.name = new Name(name); } + + public void setStudentId(String studentId) { + this.studentId = new StudentId(studentId); + } public void setPhone(String phone) { this.phone = new Phone(phone); } diff --git a/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/domain/service/MemberServiceImpl.java b/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/domain/service/MemberServiceImpl.java index 50b9b1e5..cc1894c7 100644 --- a/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/domain/service/MemberServiceImpl.java +++ b/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/domain/service/MemberServiceImpl.java @@ -86,7 +86,7 @@ public List getNotApprovedMembersBySearchAndRole .map(member -> new NotApprovedMemberManagementDto( member.getName(), member.getId(), - member.getStudentId().getValue(), + member.getStudentId(), member.getPhone(), member.getEmail(), member.getSchoolInformation().getGrade(), @@ -106,7 +106,7 @@ public List getApprovedMembersBySearchAndRole(Strin .map(member -> new ApprovedMemberManagementDto( member.getName(), member.getId(), - member.getStudentId().getValue(), + member.getStudentId(), member.getPhone(), member.getRole(), member.getSchoolInformation().getGeneration(), diff --git a/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/repository/MemberRepository.java b/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/repository/MemberRepository.java index 7979d863..0afa5849 100644 --- a/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/repository/MemberRepository.java +++ b/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/repository/MemberRepository.java @@ -13,14 +13,9 @@ public interface MemberRepository extends JpaRepository, MemberRepositoryCustom { List findAllById(Iterable memberIdList); - Member getByStudentId(StudentId studentId); - - Optional findByStudentId(StudentId studentId); - Member findByIbasInformation_Role(Role role); - // OAuth boolean existsByProviderAndUid(OAuth2Provider provider, UID uid); Optional findByProviderAndUid(OAuth2Provider provider, UID uid); diff --git a/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/repository/MemberRepositoryCustom.java b/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/repository/MemberRepositoryCustom.java index 6f14eddd..8c599539 100644 --- a/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/repository/MemberRepositoryCustom.java +++ b/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/repository/MemberRepositoryCustom.java @@ -2,7 +2,6 @@ import com.inhabas.api.auth.domain.oauth2.member.domain.entity.Member; import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.Role; -import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.StudentId; import com.inhabas.api.auth.domain.oauth2.member.dto.MemberDuplicationQueryCondition; import com.inhabas.api.auth.domain.oauth2.member.security.MemberAuthorityProvider; @@ -11,7 +10,7 @@ public interface MemberRepositoryCustom { - MemberAuthorityProvider.RoleDto fetchRoleByStudentId(StudentId studentId); + MemberAuthorityProvider.RoleDto fetchRoleByStudentId(Long id); boolean isDuplicated(MemberDuplicationQueryCondition condition); diff --git a/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/repository/MemberRepositoryImpl.java b/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/repository/MemberRepositoryImpl.java index 9e7fce8e..e402294e 100644 --- a/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/repository/MemberRepositoryImpl.java +++ b/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/repository/MemberRepositoryImpl.java @@ -3,7 +3,6 @@ import com.inhabas.api.auth.domain.oauth2.OAuth2Provider; import com.inhabas.api.auth.domain.oauth2.member.domain.entity.Member; import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.Role; -import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.StudentId; import com.inhabas.api.auth.domain.oauth2.member.dto.MemberDuplicationQueryCondition; import com.inhabas.api.auth.domain.oauth2.member.security.MemberAuthorityProvider; import com.inhabas.api.auth.domain.oauth2.socialAccount.type.UID; @@ -29,10 +28,10 @@ public class MemberRepositoryImpl implements MemberRepositoryCustom { private final JPAQueryFactory queryFactory; @Override - public MemberAuthorityProvider.RoleDto fetchRoleByStudentId(StudentId studentId) { + public MemberAuthorityProvider.RoleDto fetchRoleByStudentId(Long id) { Role role = queryFactory .select(member.ibasInformation.role).from(member) - .where(member.studentId.eq(studentId)) + .where(member.id.eq(id)) .fetchOne(); return new MemberAuthorityProvider.RoleDto(role); diff --git a/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/security/MemberAuthorityProvider.java b/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/security/MemberAuthorityProvider.java index b5032d65..a4bfe9e1 100644 --- a/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/security/MemberAuthorityProvider.java +++ b/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/security/MemberAuthorityProvider.java @@ -2,20 +2,21 @@ import com.inhabas.api.auth.domain.exception.InvalidUserInfoException; import com.inhabas.api.auth.domain.oauth2.member.domain.entity.Member; -import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.StudentId; +import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.Role; import com.inhabas.api.auth.domain.oauth2.member.repository.MemberRepository; import com.inhabas.api.auth.domain.oauth2.socialAccount.type.UID; import com.inhabas.api.auth.domain.oauth2.userAuthorityProvider.UserAuthorityProvider; import com.inhabas.api.auth.domain.oauth2.userInfo.OAuth2UserInfo; import com.inhabas.api.auth.domain.oauth2.userInfo.OAuth2UserInfoAuthentication; import com.inhabas.api.auth.domain.token.securityFilter.UserPrincipalService; -import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.Role; import lombok.RequiredArgsConstructor; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.Objects; import static com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.Role.SIGNING_UP; @@ -33,9 +34,9 @@ public Collection determineAuthorities(OAuth2UserInfo oA OAuth2UserInfoAuthentication authentication = new OAuth2UserInfoAuthentication(oAuth2UserInfo.getId(), oAuth2UserInfo.getProvider().toString(), oAuth2UserInfo.getEmail()); - StudentId studentId = (StudentId) userPrincipalService.loadUserPrincipal(authentication); + Long memberId = (Long) userPrincipalService.loadUserPrincipal(authentication); - if (Objects.isNull(studentId)) { // 기존회원이 아니면, member 테이블에 임시데이터 저장 + if (Objects.isNull(memberId)) { // 기존회원이 아니면, member 테이블에 임시데이터 저장 Member member = memberRepository.findByProviderAndUid( oAuth2UserInfo.getProvider(), new UID(oAuth2UserInfo.getId())) .orElseThrow(InvalidUserInfoException::new); @@ -46,7 +47,7 @@ public Collection determineAuthorities(OAuth2UserInfo oA } else { // 기존회원이면, - RoleDto roleDto = memberRepository.fetchRoleByStudentId(studentId); + RoleDto roleDto = memberRepository.fetchRoleByStudentId(memberId); if (roleDto.isEmpty()) throw new InvalidUserInfoException(); // 가입된 소셜 계정으로 회원 프로필을 찾을 수 없는 경우. diff --git a/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/security/MemberPrincipalService.java b/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/security/MemberPrincipalService.java index b0a79b78..196d20ea 100644 --- a/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/security/MemberPrincipalService.java +++ b/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/security/MemberPrincipalService.java @@ -2,13 +2,12 @@ import com.inhabas.api.auth.domain.oauth2.OAuth2Provider; import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.Email; -import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.StudentId; import com.inhabas.api.auth.domain.oauth2.member.security.socialAccount.MemberSocialAccount; +import com.inhabas.api.auth.domain.oauth2.member.security.socialAccount.MemberSocialAccountRepository; import com.inhabas.api.auth.domain.oauth2.socialAccount.type.UID; import com.inhabas.api.auth.domain.oauth2.userInfo.OAuth2UserInfoAuthentication; import com.inhabas.api.auth.domain.token.securityFilter.UserPrincipalNotFoundException; import com.inhabas.api.auth.domain.token.securityFilter.UserPrincipalService; -import com.inhabas.api.auth.domain.oauth2.member.security.socialAccount.MemberSocialAccountRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.security.core.Authentication; @@ -43,8 +42,8 @@ public Object loadUserPrincipal(Authentication authentication) { Email email = new Email(oauth2UserInfoToken.getEmail()); try { - StudentId studentId = this.getMemberId(provider, uid, email).orElseThrow(UserPrincipalNotFoundException::new); - return studentId; + Long memberId = this.getMemberId(provider, uid, email).orElseThrow(UserPrincipalNotFoundException::new); + return memberId; } catch (UserPrincipalNotFoundException e) { log.info(e.getMessage()); return null; @@ -52,14 +51,14 @@ public Object loadUserPrincipal(Authentication authentication) { } - private Optional getMemberId(OAuth2Provider provider, UID uid, Email email) { + private Optional getMemberId(OAuth2Provider provider, UID uid, Email email) { return memberSocialAccountRepository.findMemberIdByUidAndProvider(uid, provider) .or(() -> this.findByEmailAndProviderForLegacy(email, provider, uid)); } - private Optional findByEmailAndProviderForLegacy(Email email, OAuth2Provider provider, UID uid) { + private Optional findByEmailAndProviderForLegacy(Email email, OAuth2Provider provider, UID uid) { Optional memberSocialAccount = memberSocialAccountRepository.findMemberSocialAccountByEmailAndProvider(email, provider); @@ -69,7 +68,7 @@ private Optional findByEmailAndProviderForLegacy(Email email, OAuth2P MemberSocialAccount socialAccount = memberSocialAccount.get(); socialAccount.SetUID(uid); memberSocialAccountRepository.save(socialAccount); - return Optional.of(socialAccount.getMember().getStudentId()); + return Optional.of(socialAccount.getMember().getId()); } else { diff --git a/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/security/socialAccount/MemberSocialAccountRepositoryCustom.java b/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/security/socialAccount/MemberSocialAccountRepositoryCustom.java index 123bbb89..c7b31b5c 100644 --- a/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/security/socialAccount/MemberSocialAccountRepositoryCustom.java +++ b/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/security/socialAccount/MemberSocialAccountRepositoryCustom.java @@ -1,12 +1,11 @@ package com.inhabas.api.auth.domain.oauth2.member.security.socialAccount; import com.inhabas.api.auth.domain.oauth2.OAuth2Provider; -import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.StudentId; import com.inhabas.api.auth.domain.oauth2.socialAccount.type.UID; import java.util.Optional; public interface MemberSocialAccountRepositoryCustom { - Optional findMemberIdByUidAndProvider(UID uid, OAuth2Provider provider); + Optional findMemberIdByUidAndProvider(UID uid, OAuth2Provider provider); } diff --git a/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/security/socialAccount/MemberSocialAccountRepositoryImpl.java b/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/security/socialAccount/MemberSocialAccountRepositoryImpl.java index b44d18a3..429435c8 100644 --- a/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/security/socialAccount/MemberSocialAccountRepositoryImpl.java +++ b/module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/security/socialAccount/MemberSocialAccountRepositoryImpl.java @@ -1,7 +1,6 @@ package com.inhabas.api.auth.domain.oauth2.member.security.socialAccount; import com.inhabas.api.auth.domain.oauth2.OAuth2Provider; -import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.StudentId; import com.inhabas.api.auth.domain.oauth2.socialAccount.type.UID; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; @@ -17,9 +16,9 @@ public class MemberSocialAccountRepositoryImpl implements MemberSocialAccountRep private final JPAQueryFactory jpaQueryFactory; @Override - public Optional findMemberIdByUidAndProvider(UID uid, OAuth2Provider provider) { + public Optional findMemberIdByUidAndProvider(UID uid, OAuth2Provider provider) { return Optional.ofNullable(jpaQueryFactory - .select(memberSocialAccount.member.studentId) + .select(memberSocialAccount.member.id) .where(eqSocialAccount(uid, provider)) .from(memberSocialAccount) .fetchOne()); diff --git a/resource-server/src/main/java/com/inhabas/api/domain/comment/dto/CommentDetailDto.java b/resource-server/src/main/java/com/inhabas/api/domain/comment/dto/CommentDetailDto.java index 2952be9a..c864c03e 100644 --- a/resource-server/src/main/java/com/inhabas/api/domain/comment/dto/CommentDetailDto.java +++ b/resource-server/src/main/java/com/inhabas/api/domain/comment/dto/CommentDetailDto.java @@ -28,7 +28,7 @@ public static CommentDetailDto fromEntity(Comment comment) { return new CommentDetailDto( comment.getId(), comment.getContents(), - comment.getWriter().getStudentId(), + new StudentId("11121212"), // 임시방편, 수정 필요 comment.getWriter().getName(), comment.getWriter().getSchoolInformation().getMajor(), comment.getDateCreated() diff --git a/resource-server/src/main/java/com/inhabas/api/web/argumentResolver/LoginMemberArgumentResolver.java b/resource-server/src/main/java/com/inhabas/api/web/argumentResolver/LoginMemberArgumentResolver.java index e9441412..e8c681c4 100644 --- a/resource-server/src/main/java/com/inhabas/api/web/argumentResolver/LoginMemberArgumentResolver.java +++ b/resource-server/src/main/java/com/inhabas/api/web/argumentResolver/LoginMemberArgumentResolver.java @@ -1,13 +1,9 @@ package com.inhabas.api.web.argumentResolver; -import com.inhabas.api.auth.domain.oauth2.userInfo.OAuth2UserInfoAuthentication; -import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.StudentId; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.NotImplementedException; import org.springframework.core.MethodParameter; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken; import org.springframework.stereotype.Component; import org.springframework.web.bind.support.WebDataBinderFactory; import org.springframework.web.context.request.NativeWebRequest; @@ -37,45 +33,8 @@ public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer m Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (Objects.isNull(authentication)) return null; // login not processed, anonymous user! + return (Long) authentication.getPrincipal(); - if (isMemberIdType(parameter)) - return resolveMemberId(authentication); - else if (isOAuth2UserInfoAuthenticationType(parameter)) - return authentication; - else - throw new IllegalArgumentException("지원하지 않는 타입입니다"); } - private StudentId resolveMemberId(Authentication authentication) { - - StudentId studentId = null; - - if (isOAuth2UserInfoAuthenticationType(authentication)) { // jwt 토큰 인증 이후 - studentId = (StudentId) authentication.getPrincipal(); - - } else if (authentication instanceof OAuth2AuthenticationToken) { // 소셜 로그인 인증 이후 - throw new NotImplementedException("소셜로그인 구현 완료 후에 작업해야됨!"); - } - else { - log.warn("{} - cannot resolve authenticated User's Id!", this.getClass()); - } - - return studentId; - } - - private boolean isMemberIdType(MethodParameter parameter) { - - return parameter.getParameterType().equals(StudentId.class); - } - - private boolean isOAuth2UserInfoAuthenticationType(MethodParameter parameter) { - - return OAuth2UserInfoAuthentication.class - .isAssignableFrom(parameter.getParameterType()); - } - private boolean isOAuth2UserInfoAuthenticationType(Authentication authentication) { - - return OAuth2UserInfoAuthentication.class - .isAssignableFrom(authentication.getClass()); - } }