[삭제] 미사용 파일 삭제 - Front SocialUser
This commit is contained in:
@@ -1,29 +0,0 @@
|
|||||||
package app.module.core.config.adapters.persistence.entity;
|
|
||||||
|
|
||||||
import app.module.core.config.adapters.persistence.component.AuditEntity;
|
|
||||||
import app.module.core.config.application.enums.SocialType;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class FrontUserSocial extends AuditEntity {
|
|
||||||
|
|
||||||
private Integer seq;
|
|
||||||
|
|
||||||
private String userId;
|
|
||||||
|
|
||||||
private SocialType socialType;
|
|
||||||
|
|
||||||
private String socialId;
|
|
||||||
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private String ci;
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package app.module.core.config.adapters.web.security.domain;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Map;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
|
||||||
import org.springframework.security.oauth2.core.user.DefaultOAuth2User;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class SocialUser extends DefaultOAuth2User {
|
|
||||||
|
|
||||||
private final String username;
|
|
||||||
private final String password;
|
|
||||||
private final boolean enabled;
|
|
||||||
private final boolean accountNonExpired;
|
|
||||||
private final boolean credentialsNonExpired;
|
|
||||||
private final boolean accountNonLocked;
|
|
||||||
private final String nickname;
|
|
||||||
private final long remainPasswordDays;
|
|
||||||
|
|
||||||
public SocialUser(
|
|
||||||
Collection<? extends GrantedAuthority> authorities,
|
|
||||||
Map<String, Object> attributes,
|
|
||||||
String nameAttributeKey,
|
|
||||||
String username,
|
|
||||||
String password,
|
|
||||||
boolean enabled,
|
|
||||||
boolean accountNonExpired,
|
|
||||||
boolean credentialsNonExpired,
|
|
||||||
boolean accountNonLocked,
|
|
||||||
String nickname,
|
|
||||||
long remainPasswordDays) {
|
|
||||||
super(authorities, attributes, nameAttributeKey);
|
|
||||||
this.username = username;
|
|
||||||
this.password = password;
|
|
||||||
this.enabled = enabled;
|
|
||||||
this.accountNonExpired = accountNonExpired;
|
|
||||||
this.credentialsNonExpired = credentialsNonExpired;
|
|
||||||
this.accountNonLocked = accountNonLocked;
|
|
||||||
this.nickname = nickname;
|
|
||||||
this.remainPasswordDays = remainPasswordDays;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,8 +6,7 @@ import lombok.RequiredArgsConstructor;
|
|||||||
@Getter
|
@Getter
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public enum SignUpType {
|
public enum SignUpType {
|
||||||
NORMAL("일반 회원가입"),
|
NORMAL("일반 회원가입");
|
||||||
SOCIAL("소셜 로그인 회원가입");
|
|
||||||
|
|
||||||
private final String desc;
|
private final String desc;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
package app.module.core.config.application.enums;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public enum SocialType {
|
|
||||||
KAKAO("카카오 로그인", "kakao"),
|
|
||||||
NAVER("네이버 로그인", "naver"),
|
|
||||||
APPLE("애플 로그인", "apple");
|
|
||||||
|
|
||||||
private final String desc;
|
|
||||||
private final String registrationId;
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,13 @@
|
|||||||
package app.module.core.config.application.util;
|
package app.module.core.config.application.util;
|
||||||
|
|
||||||
import app.module.core.config.adapters.web.security.domain.SocialUser;
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpSession;
|
import jakarta.servlet.http.HttpSession;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -12,15 +17,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.security.core.Authentication;
|
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
|
||||||
import org.springframework.security.oauth2.core.user.DefaultOAuth2User;
|
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
|
||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class CommonUtil {
|
public class CommonUtil {
|
||||||
|
|
||||||
@@ -88,9 +84,6 @@ public class CommonUtil {
|
|||||||
|
|
||||||
if (principal instanceof UserDetails) {
|
if (principal instanceof UserDetails) {
|
||||||
username = ((UserDetails) principal).getUsername();
|
username = ((UserDetails) principal).getUsername();
|
||||||
} else if (principal instanceof DefaultOAuth2User) {
|
|
||||||
SocialUser socialUser = (SocialUser) principal;
|
|
||||||
username = socialUser.getUsername();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return username;
|
return username;
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
package app.module.front.config.application.security;
|
|
||||||
|
|
||||||
import app.module.core.config.application.enums.SocialType;
|
|
||||||
import app.module.front.usecase.user.social.processSocialLogin.ports.ProcessSocialLoginPortIn;
|
|
||||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.ProcessSocialLoginCmd;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Map;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.security.oauth2.client.userinfo.DefaultOAuth2UserService;
|
|
||||||
import org.springframework.security.oauth2.client.userinfo.OAuth2UserRequest;
|
|
||||||
import org.springframework.security.oauth2.client.userinfo.OAuth2UserService;
|
|
||||||
import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
|
|
||||||
import org.springframework.security.oauth2.core.user.OAuth2User;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Slf4j
|
|
||||||
public class CustomOAuth2UserService implements OAuth2UserService<OAuth2UserRequest, OAuth2User> {
|
|
||||||
|
|
||||||
private final ProcessSocialLoginPortIn processSocialLoginPortIn;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2AuthenticationException {
|
|
||||||
OAuth2UserService<OAuth2UserRequest, OAuth2User> delegate = new DefaultOAuth2UserService();
|
|
||||||
OAuth2User oAuth2User = delegate.loadUser(userRequest);
|
|
||||||
|
|
||||||
String registrationId = userRequest.getClientRegistration().getRegistrationId();
|
|
||||||
SocialType socialType =
|
|
||||||
Arrays.stream(SocialType.values())
|
|
||||||
.filter(type -> type.getRegistrationId().equals(registrationId))
|
|
||||||
.findFirst()
|
|
||||||
.orElseThrow(() -> new RuntimeException("Social type not found"));
|
|
||||||
String userNameAttributeName =
|
|
||||||
userRequest
|
|
||||||
.getClientRegistration()
|
|
||||||
.getProviderDetails()
|
|
||||||
.getUserInfoEndpoint()
|
|
||||||
.getUserNameAttributeName();
|
|
||||||
|
|
||||||
Map<String, Object> attributes = oAuth2User.getAttributes();
|
|
||||||
|
|
||||||
return processSocialLoginPortIn
|
|
||||||
.operate(new ProcessSocialLoginCmd(socialType, userNameAttributeName, attributes))
|
|
||||||
.orElseThrow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -31,7 +31,6 @@ public class FrontSecurityConfig {
|
|||||||
private final FrontDetailService frontDetailService;
|
private final FrontDetailService frontDetailService;
|
||||||
private final DataSource dataSource;
|
private final DataSource dataSource;
|
||||||
private final BCryptPasswordEncoder passwordEncoder;
|
private final BCryptPasswordEncoder passwordEncoder;
|
||||||
private final CustomOAuth2UserService customOAuth2UserService;
|
|
||||||
private final CustomAuthenticationEntryPoint customAuthenticationEntryPoint;
|
private final CustomAuthenticationEntryPoint customAuthenticationEntryPoint;
|
||||||
@Value("${app.front.session.maximum.num}")
|
@Value("${app.front.session.maximum.num}")
|
||||||
private Integer maxSessionNum;
|
private Integer maxSessionNum;
|
||||||
@@ -104,13 +103,7 @@ public class FrontSecurityConfig {
|
|||||||
session -> session.maximumSessions(maxSessionNum).maxSessionsPreventsLogin(false).expiredUrl("/login"))
|
session -> session.maximumSessions(maxSessionNum).maxSessionsPreventsLogin(false).expiredUrl("/login"))
|
||||||
.sessionManagement(
|
.sessionManagement(
|
||||||
session -> session.invalidSessionUrl("/login"))
|
session -> session.invalidSessionUrl("/login"))
|
||||||
.oauth2Login(
|
;
|
||||||
config ->
|
|
||||||
config
|
|
||||||
.loginPage("/login")
|
|
||||||
.userInfoEndpoint(
|
|
||||||
userInfoEndpointConfig ->
|
|
||||||
userInfoEndpointConfig.userService(customOAuth2UserService)));
|
|
||||||
|
|
||||||
return http.build();
|
return http.build();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
package app.module.front.config.application.util;
|
package app.module.front.config.application.util;
|
||||||
|
|
||||||
import app.module.core.config.adapters.web.security.domain.SocialUser;
|
|
||||||
import app.module.front.config.application.security.FrontHouseholdUser;
|
import app.module.front.config.application.security.FrontHouseholdUser;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.oauth2.core.user.DefaultOAuth2User;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
package app.module.front.usecase.user.social.parseSocialUser.ports;
|
|
||||||
|
|
||||||
import app.module.front.usecase.user.social.parseSocialUser.ports.application.domain.ParseSocialUserCmd;
|
|
||||||
import app.module.front.usecase.user.social.parseSocialUser.ports.application.domain.ParsedUserInfo;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public interface ParseSocialUserPortIn {
|
|
||||||
|
|
||||||
Optional<ParsedUserInfo> operate(ParseSocialUserCmd cmd);
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
package app.module.front.usecase.user.social.parseSocialUser.ports.application;
|
|
||||||
|
|
||||||
import app.module.front.usecase.user.social.parseSocialUser.ports.ParseSocialUserPortIn;
|
|
||||||
import app.module.front.usecase.user.social.parseSocialUser.ports.application.domain.KakaoUserInfo;
|
|
||||||
import app.module.front.usecase.user.social.parseSocialUser.ports.application.domain.NaverUserInfo;
|
|
||||||
import app.module.front.usecase.user.social.parseSocialUser.ports.application.domain.ParseSocialUserCmd;
|
|
||||||
import app.module.front.usecase.user.social.parseSocialUser.ports.application.domain.ParsedUserInfo;
|
|
||||||
import java.util.Optional;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Slf4j
|
|
||||||
class ParseSocialUserService implements ParseSocialUserPortIn {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<ParsedUserInfo> operate(ParseSocialUserCmd cmd) {
|
|
||||||
ParsedUserInfo parsedUserInfo = null;
|
|
||||||
|
|
||||||
switch (cmd.getSocialType()) {
|
|
||||||
case KAKAO -> {
|
|
||||||
parsedUserInfo = new KakaoUserInfo(cmd.getUserNameAttributeName(),
|
|
||||||
cmd.getAttributes());
|
|
||||||
}
|
|
||||||
case NAVER -> {
|
|
||||||
parsedUserInfo = new NaverUserInfo(cmd.getUserNameAttributeName(),
|
|
||||||
cmd.getAttributes());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parsedUserInfo != null) {
|
|
||||||
log.info("socialId: {}", parsedUserInfo.getSocialId());
|
|
||||||
log.info("nickname: {}", parsedUserInfo.getNickName());
|
|
||||||
log.info("name: {}", parsedUserInfo.getName());
|
|
||||||
log.info("ci: {}", parsedUserInfo.getCi());
|
|
||||||
log.info("birthday: {}", parsedUserInfo.getBirthday());
|
|
||||||
log.info("email: {}", parsedUserInfo.getEmail());
|
|
||||||
log.info("phone: {}", parsedUserInfo.getPhone());
|
|
||||||
}
|
|
||||||
|
|
||||||
return Optional.ofNullable(parsedUserInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,116 +0,0 @@
|
|||||||
package app.module.front.usecase.user.social.parseSocialUser.ports.application.domain;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class KakaoUserInfo implements ParsedUserInfo {
|
|
||||||
|
|
||||||
private final String userNameAttribute;
|
|
||||||
private final Map<String, Object> attributes;
|
|
||||||
|
|
||||||
public KakaoUserInfo(String userNameAttribute, Map<String, Object> attributes) {
|
|
||||||
this.userNameAttribute = userNameAttribute;
|
|
||||||
this.attributes = attributes;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSocialId() {
|
|
||||||
return String.valueOf(attributes.get(userNameAttribute));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public String getNickName() {
|
|
||||||
Map<String, Object> account = (Map<String, Object>) attributes.get("kakao_account");
|
|
||||||
Map<String, Object> profile = (Map<String, Object>) account.get("profile");
|
|
||||||
|
|
||||||
return (String) profile.get("nickname");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public String getName() {
|
|
||||||
Map<String, Object> account = (Map<String, Object>) attributes.get("kakao_account");
|
|
||||||
|
|
||||||
if (account == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 카카오 로그인 서비스 인증 전에 이름 정보는 전달되지 않는다.
|
|
||||||
if (account.get("name") == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (String) account.get("name");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public String getEmail() {
|
|
||||||
Map<String, Object> account = (Map<String, Object>) attributes.get("kakao_account");
|
|
||||||
|
|
||||||
if (account == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
String email = (String) account.get("email");
|
|
||||||
|
|
||||||
// 카카오 로그인 서비스 인증 전에 이메일 정보는 전달되지 않는다.
|
|
||||||
return Objects.requireNonNullElse(email, "NO-KAKAO-EMAIL@noemail.com");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public String getPhone() {
|
|
||||||
Map<String, Object> account = (Map<String, Object>) attributes.get("kakao_account");
|
|
||||||
|
|
||||||
if (account == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 카카오 로그인 서비스 인증 전에 phone 정보는 전달되지 않는다.
|
|
||||||
if (account.get("phone_number") == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// "0" + s.replaceAll("^\\+\\d{1,3}-?|-", "").trim();
|
|
||||||
return (String) account.get("phone_number");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public String getBirthday() {
|
|
||||||
Map<String, Object> account = (Map<String, Object>) attributes.get("kakao_account");
|
|
||||||
|
|
||||||
if (account == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
String birthyear = (String) account.get("birthyear");
|
|
||||||
String birthday = (String) account.get("birthday");
|
|
||||||
|
|
||||||
// 카카오 로그인 서비스 인증 전에 생년월일 정보는 전달되지 않는다.
|
|
||||||
if (birthyear == null || birthday == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return birthyear + birthday;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public String getCi() {
|
|
||||||
Map<String, Object> account = (Map<String, Object>) attributes.get("kakao_account");
|
|
||||||
|
|
||||||
if (account == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 카카오 로그인 서비스 인증 전에 CI 정보는 전달되지 않는다.
|
|
||||||
if (account.get("ci") == null || ((String) account.get("ci")).equals("")) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (String) account.get("ci");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
package app.module.front.usecase.user.social.parseSocialUser.ports.application.domain;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import lombok.ToString;
|
|
||||||
|
|
||||||
@ToString
|
|
||||||
public class NaverUserInfo implements ParsedUserInfo {
|
|
||||||
|
|
||||||
private final String userNameAttribute;
|
|
||||||
private final Map<String, Object> attributes;
|
|
||||||
|
|
||||||
public NaverUserInfo(String userNameAttribute, Map<String, Object> attributes) {
|
|
||||||
this.userNameAttribute = userNameAttribute;
|
|
||||||
this.attributes = attributes;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSocialId() {
|
|
||||||
return (String) getAttrs().get("id");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getNickName() {
|
|
||||||
return (String) getAttrs().get("nickname");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return (String) getAttrs().get("name");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getEmail() {
|
|
||||||
return (String) getAttrs().get("email");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPhone() {
|
|
||||||
String phone = (String) getAttrs().get("mobile");
|
|
||||||
return phone != null ? phone.replaceAll("-", "") : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getBirthday() {
|
|
||||||
String birthYear = (String) getAttrs().get("birthyear");
|
|
||||||
String birthday = (String) getAttrs().get("birthday");
|
|
||||||
return (birthYear + birthday).replaceAll("-", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getCi() {
|
|
||||||
// 네이버 로그인 서비스 인증 전에 CI 정보는 전달되지 않는다.
|
|
||||||
return (String) getAttrs().get("ci");
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private Map<String, Object> getAttrs() {
|
|
||||||
return (Map<String, Object>) attributes.get(userNameAttribute);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package app.module.front.usecase.user.social.parseSocialUser.ports.application.domain;
|
|
||||||
|
|
||||||
import app.module.core.config.application.enums.SocialType;
|
|
||||||
import java.util.Map;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@AllArgsConstructor
|
|
||||||
@EqualsAndHashCode
|
|
||||||
public class ParseSocialUserCmd {
|
|
||||||
|
|
||||||
private SocialType socialType;
|
|
||||||
private String userNameAttributeName;
|
|
||||||
private Map<String, Object> attributes;
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package app.module.front.usecase.user.social.parseSocialUser.ports.application.domain;
|
|
||||||
|
|
||||||
public interface ParsedUserInfo {
|
|
||||||
|
|
||||||
String getSocialId();
|
|
||||||
|
|
||||||
String getNickName();
|
|
||||||
|
|
||||||
String getName();
|
|
||||||
|
|
||||||
String getEmail();
|
|
||||||
|
|
||||||
String getPhone();
|
|
||||||
|
|
||||||
String getBirthday();
|
|
||||||
|
|
||||||
String getCi();
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package app.module.front.usecase.user.social.processSocialLogin.adapters.persistence;
|
|
||||||
|
|
||||||
import app.module.core.config.adapters.persistence.entity.FrontUserSocial;
|
|
||||||
import app.module.core.config.application.enums.SocialType;
|
|
||||||
import java.util.Optional;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface FrontUserSocialRepo {
|
|
||||||
|
|
||||||
Optional<FrontUserSocial> findBySocialTypeAndSocialId(SocialType socialType, String socialId);
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
package app.module.front.usecase.user.social.processSocialLogin.adapters.persistence;
|
|
||||||
|
|
||||||
import app.module.core.config.adapters.persistence.entity.FrontUserSocial;
|
|
||||||
import app.module.front.usecase.user.social.processSocialLogin.ports.ProcessSocialLoginPortOut;
|
|
||||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.CreateUserSocialCmd;
|
|
||||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.GetUserSocial;
|
|
||||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.GetUserSocialCmd;
|
|
||||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.ProcessSocialLogin;
|
|
||||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.ProcessSocialLoginCmd;
|
|
||||||
import java.util.Optional;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
class ProcessSocialLoginDao implements ProcessSocialLoginPortOut {
|
|
||||||
|
|
||||||
private final FrontUserSocialRepo frontUserSocialRepo;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<ProcessSocialLogin> operate(ProcessSocialLoginCmd cmd) {
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<GetUserSocial> findUserSocial(GetUserSocialCmd cmd) {
|
|
||||||
return frontUserSocialRepo
|
|
||||||
.findBySocialTypeAndSocialId(cmd.getSocialType(), cmd.getSocialId())
|
|
||||||
.flatMap(
|
|
||||||
frontSocialUser ->
|
|
||||||
Optional.of(
|
|
||||||
new GetUserSocial(
|
|
||||||
frontSocialUser.getSeq(),
|
|
||||||
frontSocialUser.getUserId(),
|
|
||||||
frontSocialUser.getSocialType(),
|
|
||||||
frontSocialUser.getSocialId(),
|
|
||||||
frontSocialUser.getEmail(),
|
|
||||||
frontSocialUser.getName(),
|
|
||||||
frontSocialUser.getCi())));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<GetUserSocial> createUserSocial(CreateUserSocialCmd cmd) {
|
|
||||||
// FrontUserSocial createUserSocial =
|
|
||||||
// frontUserSocialRepo.save(
|
|
||||||
// new FrontUserSocial(
|
|
||||||
// null,
|
|
||||||
// cmd.getUserId(),
|
|
||||||
// cmd.getSocialType(),
|
|
||||||
// cmd.getSocialId(),
|
|
||||||
// cmd.getEmail(),
|
|
||||||
// cmd.getName(),
|
|
||||||
// cmd.getCi()));
|
|
||||||
//
|
|
||||||
// return Optional.of(
|
|
||||||
// new GetUserSocial(
|
|
||||||
// createUserSocial.getSeq(),
|
|
||||||
// createUserSocial.getUserId(),
|
|
||||||
// createUserSocial.getSocialType(),
|
|
||||||
// createUserSocial.getSocialId(),
|
|
||||||
// createUserSocial.getEmail(),
|
|
||||||
// createUserSocial.getName(),
|
|
||||||
// createUserSocial.getCi()));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package app.module.front.usecase.user.social.processSocialLogin.ports;
|
|
||||||
|
|
||||||
import app.module.core.config.adapters.web.security.domain.SocialUser;
|
|
||||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.ProcessSocialLoginCmd;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public interface ProcessSocialLoginPortIn {
|
|
||||||
|
|
||||||
Optional<SocialUser> operate(ProcessSocialLoginCmd cmd);
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package app.module.front.usecase.user.social.processSocialLogin.ports;
|
|
||||||
|
|
||||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.CreateUserSocialCmd;
|
|
||||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.GetUserSocial;
|
|
||||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.GetUserSocialCmd;
|
|
||||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.ProcessSocialLogin;
|
|
||||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.ProcessSocialLoginCmd;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public interface ProcessSocialLoginPortOut {
|
|
||||||
|
|
||||||
Optional<ProcessSocialLogin> operate(ProcessSocialLoginCmd cmd);
|
|
||||||
|
|
||||||
Optional<GetUserSocial> findUserSocial(GetUserSocialCmd cmd);
|
|
||||||
|
|
||||||
Optional<GetUserSocial> createUserSocial(CreateUserSocialCmd cmd);
|
|
||||||
}
|
|
||||||
@@ -1,131 +0,0 @@
|
|||||||
package app.module.front.usecase.user.social.processSocialLogin.ports.application;
|
|
||||||
|
|
||||||
import app.module.core.config.adapters.web.security.domain.CorePrivilege;
|
|
||||||
import app.module.core.config.adapters.web.security.domain.CoreRole;
|
|
||||||
import app.module.core.config.adapters.web.security.domain.SocialUser;
|
|
||||||
import app.module.core.config.application.enums.SignUpType;
|
|
||||||
import app.module.core.usecase.user.createUser.ports.CreateUserPortIn;
|
|
||||||
import app.module.core.usecase.user.createUser.ports.application.domain.CreateUserCmd;
|
|
||||||
import app.module.core.usecase.user.findUser.ports.FindUserPortIn;
|
|
||||||
import app.module.core.usecase.user.findUser.ports.application.domain.FindUser;
|
|
||||||
import app.module.core.usecase.user.findUser.ports.application.domain.FindUserCmd;
|
|
||||||
import app.module.front.usecase.user.social.parseSocialUser.ports.ParseSocialUserPortIn;
|
|
||||||
import app.module.front.usecase.user.social.parseSocialUser.ports.application.domain.ParseSocialUserCmd;
|
|
||||||
import app.module.front.usecase.user.social.parseSocialUser.ports.application.domain.ParsedUserInfo;
|
|
||||||
import app.module.front.usecase.user.social.processSocialLogin.ports.ProcessSocialLoginPortIn;
|
|
||||||
import app.module.front.usecase.user.social.processSocialLogin.ports.ProcessSocialLoginPortOut;
|
|
||||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.CreateUserSocialCmd;
|
|
||||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.GetUserSocialCmd;
|
|
||||||
import app.module.front.usecase.user.social.processSocialLogin.ports.application.domain.ProcessSocialLoginCmd;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
class ProcessSocialLoginService implements ProcessSocialLoginPortIn {
|
|
||||||
|
|
||||||
private final ProcessSocialLoginPortOut portOut;
|
|
||||||
private final ParseSocialUserPortIn parseSocialUserPortIn;
|
|
||||||
private final FindUserPortIn findUserPortIn;
|
|
||||||
private final CreateUserPortIn createUserPortIn;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<SocialUser> operate(ProcessSocialLoginCmd cmd) {
|
|
||||||
|
|
||||||
// SNS Login Provider 가 제공하는 사용자 정보 파싱
|
|
||||||
Optional<ParsedUserInfo> parsedUserInfo =
|
|
||||||
parseSocialUserPortIn.operate(
|
|
||||||
new ParseSocialUserCmd(
|
|
||||||
cmd.getSocialType(), cmd.getUserNameAttributeName(), cmd.getAttributes()));
|
|
||||||
|
|
||||||
if (parsedUserInfo.isPresent()) {
|
|
||||||
ParsedUserInfo parsedUser = parsedUserInfo.get();
|
|
||||||
|
|
||||||
return portOut
|
|
||||||
.findUserSocial(new GetUserSocialCmd(cmd.getSocialType(), parsedUser.getSocialId()))
|
|
||||||
.flatMap(
|
|
||||||
getUserSocial ->
|
|
||||||
findUserPortIn
|
|
||||||
.operate(new FindUserCmd(getUserSocial.getUserId()))
|
|
||||||
.flatMap(findUser -> getSocialUserOpt(findUser, cmd)))
|
|
||||||
.or(
|
|
||||||
() -> {
|
|
||||||
// 신규 회원인 경우,
|
|
||||||
String uuid = UUID.randomUUID().toString();
|
|
||||||
|
|
||||||
return createUserPortIn
|
|
||||||
.operate(
|
|
||||||
new CreateUserCmd(
|
|
||||||
uuid,
|
|
||||||
"NO_PASSWD",
|
|
||||||
parsedUser.getEmail(),
|
|
||||||
parsedUser.getNickName(),
|
|
||||||
SignUpType.SOCIAL,
|
|
||||||
false,
|
|
||||||
0,
|
|
||||||
false,
|
|
||||||
Set.of("ROLE_GENERAL")))
|
|
||||||
.flatMap(
|
|
||||||
createUser ->
|
|
||||||
portOut.createUserSocial(
|
|
||||||
new CreateUserSocialCmd(
|
|
||||||
createUser.getId(),
|
|
||||||
cmd.getSocialType(),
|
|
||||||
parsedUser.getSocialId(),
|
|
||||||
createUser.getEmail(),
|
|
||||||
parsedUser.getName(),
|
|
||||||
parsedUser.getCi())))
|
|
||||||
.flatMap(
|
|
||||||
getUserSocial ->
|
|
||||||
findUserPortIn
|
|
||||||
.operate(new FindUserCmd(getUserSocial.getUserId()))
|
|
||||||
.flatMap(findUser -> getSocialUserOpt(findUser, cmd)));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Optional<SocialUser> getSocialUserOpt(FindUser findUser, ProcessSocialLoginCmd cmd) {
|
|
||||||
boolean accountLocked = Optional.ofNullable(findUser.getAccountLocked()).orElse(false);
|
|
||||||
boolean accountDisabled = Optional.ofNullable(findUser.getAccountDisabled()).orElse(false);
|
|
||||||
|
|
||||||
return Optional.of(
|
|
||||||
new SocialUser(
|
|
||||||
getAuthorities(findUser.getRoles()),
|
|
||||||
cmd.getAttributes(),
|
|
||||||
cmd.getUserNameAttributeName(),
|
|
||||||
findUser.getId(),
|
|
||||||
findUser.getPassword(),
|
|
||||||
!accountDisabled,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
!accountLocked,
|
|
||||||
findUser.getNickname(),
|
|
||||||
0L));
|
|
||||||
}
|
|
||||||
|
|
||||||
private Collection<? extends GrantedAuthority> getAuthorities(Collection<CoreRole> roles) {
|
|
||||||
return Stream.concat(getRoles(roles), getPrivileges(roles))
|
|
||||||
.map(SimpleGrantedAuthority::new)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
private Stream<String> getRoles(Collection<CoreRole> roles) {
|
|
||||||
return roles.stream().map(CoreRole::getId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Stream<String> getPrivileges(Collection<CoreRole> roles) {
|
|
||||||
return roles.stream()
|
|
||||||
.flatMap(roleOutput -> roleOutput.getPrivileges().stream())
|
|
||||||
.map(CorePrivilege::getId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
package app.module.front.usecase.user.social.processSocialLogin.ports.application.domain;
|
|
||||||
|
|
||||||
import app.module.core.config.application.enums.SocialType;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@AllArgsConstructor
|
|
||||||
@EqualsAndHashCode
|
|
||||||
public class CreateUserSocialCmd {
|
|
||||||
|
|
||||||
private String userId;
|
|
||||||
|
|
||||||
private SocialType socialType;
|
|
||||||
|
|
||||||
private String socialId;
|
|
||||||
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private String ci;
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package app.module.front.usecase.user.social.processSocialLogin.ports.application.domain;
|
|
||||||
|
|
||||||
import app.module.core.config.application.enums.SocialType;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@AllArgsConstructor
|
|
||||||
@EqualsAndHashCode
|
|
||||||
public class GetUserSocial {
|
|
||||||
|
|
||||||
private Integer seq;
|
|
||||||
|
|
||||||
private String userId;
|
|
||||||
|
|
||||||
private SocialType socialType;
|
|
||||||
|
|
||||||
private String socialId;
|
|
||||||
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private String ci;
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package app.module.front.usecase.user.social.processSocialLogin.ports.application.domain;
|
|
||||||
|
|
||||||
import app.module.core.config.application.enums.SocialType;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@AllArgsConstructor
|
|
||||||
@EqualsAndHashCode
|
|
||||||
public class GetUserSocialCmd {
|
|
||||||
|
|
||||||
private SocialType socialType;
|
|
||||||
private String socialId;
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package app.module.front.usecase.user.social.processSocialLogin.ports.application.domain;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@AllArgsConstructor
|
|
||||||
@EqualsAndHashCode
|
|
||||||
public class ProcessSocialLogin {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package app.module.front.usecase.user.social.processSocialLogin.ports.application.domain;
|
|
||||||
|
|
||||||
import app.module.core.config.application.enums.SocialType;
|
|
||||||
import java.util.Map;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@AllArgsConstructor
|
|
||||||
@EqualsAndHashCode
|
|
||||||
public class ProcessSocialLoginCmd {
|
|
||||||
|
|
||||||
private SocialType socialType;
|
|
||||||
private String userNameAttributeName;
|
|
||||||
private Map<String, Object> attributes;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user