use of com.okta.sdk.resource.user.UserProfile in project okta-sdk-java by okta.
the class DefaultUserBuilder method build.
private User build(Client client) {
User user = client.instantiate(User.class);
user.setProfile(client.instantiate(UserProfile.class));
UserProfile userProfile = user.getProfile();
if (Strings.hasText(firstName))
userProfile.setFirstName(firstName);
if (Strings.hasText(lastName))
userProfile.setLastName(lastName);
if (Strings.hasText(email))
userProfile.setEmail(email);
if (Strings.hasText(secondEmail))
userProfile.setSecondEmail(secondEmail);
if (Strings.hasText(mobilePhone))
userProfile.setMobilePhone(mobilePhone);
if (Strings.hasText(login)) {
userProfile.setLogin(login);
} else {
userProfile.setLogin(email);
}
if (!Collections.isEmpty(groupIds)) {
if (user instanceof AbstractResource) {
((AbstractResource) user).setProperty("groupIds", groupIds, true);
} else {
throw new IllegalArgumentException("'User' is not an instance of 'AbstractResource', so 'groupIds' cannot be set. This would only happen if the implementation of 'User' has been customized.");
}
}
userProfile.putAll(customProfileAttributes);
if (password != null && password.length > 0 || Strings.hasText(securityQuestion)) {
UserCredentials credentials = client.instantiate(UserCredentials.class);
user.setCredentials(credentials);
if (Strings.hasText(securityQuestion)) {
RecoveryQuestionCredential question = client.instantiate(RecoveryQuestionCredential.class);
question.setQuestion(securityQuestion);
question.setAnswer(securityQuestionAnswer);
credentials.setRecoveryQuestion(question);
}
if (password != null && password.length > 0) {
PasswordCredential passwordCredential = client.instantiate(PasswordCredential.class);
credentials.setPassword(passwordCredential.setValue(password));
}
}
return user;
}
Aggregations