|
|
@ -6,7 +6,7 @@ import com.xit.core.oauth2.oauth.entity.ProviderType;
|
|
|
|
import com.xit.core.oauth2.oauth.entity.RoleType;
|
|
|
|
import com.xit.core.oauth2.oauth.entity.RoleType;
|
|
|
|
import com.xit.core.oauth2.oauth.entity.UserPrincipal;
|
|
|
|
import com.xit.core.oauth2.oauth.entity.UserPrincipal;
|
|
|
|
import com.xit.core.oauth2.oauth.exception.OAuthProviderMissMatchException;
|
|
|
|
import com.xit.core.oauth2.oauth.exception.OAuthProviderMissMatchException;
|
|
|
|
import com.xit.core.oauth2.oauth.info.OAuth2UserInfo;
|
|
|
|
import com.xit.core.oauth2.oauth.info.AbstractOAuth2UserInfo;
|
|
|
|
import com.xit.core.oauth2.oauth.info.OAuth2UserInfoFactory;
|
|
|
|
import com.xit.core.oauth2.oauth.info.OAuth2UserInfoFactory;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
import org.springframework.security.authentication.InternalAuthenticationServiceException;
|
|
|
|
import org.springframework.security.authentication.InternalAuthenticationServiceException;
|
|
|
@ -46,7 +46,7 @@ public class CustomOAuth2UserService extends DefaultOAuth2UserService {
|
|
|
|
// TODO :: 적용 여부 파악 필요
|
|
|
|
// TODO :: 적용 여부 파악 필요
|
|
|
|
ProviderType providerType = ProviderType.valueOf(userRequest.getClientRegistration().getRegistrationId().toUpperCase());
|
|
|
|
ProviderType providerType = ProviderType.valueOf(userRequest.getClientRegistration().getRegistrationId().toUpperCase());
|
|
|
|
|
|
|
|
|
|
|
|
OAuth2UserInfo userInfo = OAuth2UserInfoFactory.getOAuth2UserInfo(providerType, user.getAttributes());
|
|
|
|
AbstractOAuth2UserInfo userInfo = OAuth2UserInfoFactory.getOAuth2UserInfo(providerType, user.getAttributes());
|
|
|
|
CmmUser savedUser = null;
|
|
|
|
CmmUser savedUser = null;
|
|
|
|
Optional<CmmUser> optionalCmmUser = userRepository.findByUserId(userInfo.getId());
|
|
|
|
Optional<CmmUser> optionalCmmUser = userRepository.findByUserId(userInfo.getId());
|
|
|
|
|
|
|
|
|
|
|
@ -79,7 +79,7 @@ public class CustomOAuth2UserService extends DefaultOAuth2UserService {
|
|
|
|
return UserPrincipal.create(savedUser, user.getAttributes());
|
|
|
|
return UserPrincipal.create(savedUser, user.getAttributes());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private CmmUser createUser(OAuth2UserInfo userInfo, ProviderType providerType) {
|
|
|
|
private CmmUser createUser(AbstractOAuth2UserInfo userInfo, ProviderType providerType) {
|
|
|
|
CmmUser user = new CmmUser(
|
|
|
|
CmmUser user = new CmmUser(
|
|
|
|
userInfo.getId(),
|
|
|
|
userInfo.getId(),
|
|
|
|
userInfo.getName(),
|
|
|
|
userInfo.getName(),
|
|
|
@ -99,7 +99,7 @@ public class CustomOAuth2UserService extends DefaultOAuth2UserService {
|
|
|
|
return userRepository.saveAndFlush(user);
|
|
|
|
return userRepository.saveAndFlush(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void updateUser(CmmUser user, OAuth2UserInfo userInfo) {
|
|
|
|
private void updateUser(CmmUser user, AbstractOAuth2UserInfo userInfo) {
|
|
|
|
if (Objects.nonNull(userInfo.getName()) && !Objects.equals(userInfo.getName(), user.getUserName())) {
|
|
|
|
if (Objects.nonNull(userInfo.getName()) && !Objects.equals(userInfo.getName(), user.getUserName())) {
|
|
|
|
user.setUserName(userInfo.getName());
|
|
|
|
user.setUserName(userInfo.getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|