- dto?
google, kakao , github provider
public UserEntity(String socialId, String email, String level,
String name, String authorization, String providerType) {
this.socialId = socialId;
this.email = email;
this.level = level;
this.name = name;
this.authorization = authorization;
this.providerType = providerType;
this.lastAccessedAt = LocalDateTime.now();
this.isUse = true;
}
public UserEntity(UserEntity user) {
this.userId = user.getUserId();
this.name = user.getName();
this.socialId = user.getSocialId();
this.email = user.getEmail();
this.level = user.getLevel();
this.providerType = user.getProviderType();
this.authorization = user.getAuthorization();
this.lastAccessedAt = LocalDateTime.now();
this.isUse = true;
public GoogleProvider(OAuth2User user) {
this.socialId = user.getAttributes().get(“sub”)+"";
this.providerType = ProviderType.GOOGLE.name();
this.email = user.getAttributes().get(“email”)+"";
this.name = user.getAttributes().get(“name”)+"";
this.authorization = UserAuthorizationType.ROLE_GENERAL_USER.name();
this.level = LevelType.BRONZE.name();
this.isUse = true;
OAuth2UserServiceImplemenet
private Long userId;
private String name;
@Column(name = “social_id”)
private String socialId;
private String email;
private String level; // ⇒ ENUM 값으로 대체 필요
private String authorization; // ⇒ ENUM 값으로 대체 필요
private String providerType;
private LocalDateTime lastAccessedAt;
private boolean isUse;
interface
public interface ProviderOAuth {
UserEntity getUser();
}
github
@Override
public UserEntity getUser() {
return new UserEntity(socialId, email, level, name, authorization, providerType);
}
@Override
public UserEntity getUser() {
return new UserEntity(socialId, email, level, name, authorization, providerType);
}
kakao
public UserEntity getUser() {
return new UserEntity(socialId, email, level, name, authorization, providerType);
}
public class Provider {
final Map<ProviderType, UserEntity> user = new HashMap<>();
public Provider(OAuth2User oAuth2User){
KakaoProvider kakaoProvider = new KakaoProvider(oAuth2User);
GithubProvider githubProvider = new GithubProvider(oAuth2User);
GoogleProvider googleProvider = new GoogleProvider(oAuth2User);
this.user.put(ProviderType.KAKAO, kakaoProvider.getUser());
this.user.put(ProviderType.GITHUB, githubProvider.getUser());
this.user.put(ProviderType.GOOGLE, googleProvider.getUser());
}
public UserEntity getUser(ProviderType providerType){
return user.get(providerType);
}
}