Search in sources :

Example 1 with UserCredentials

use of com.okta.sdk.resource.user.UserCredentials 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;
}
Also used : RecoveryQuestionCredential(com.okta.sdk.resource.user.RecoveryQuestionCredential) User(com.okta.sdk.resource.user.User) UserProfile(com.okta.sdk.resource.user.UserProfile) PasswordCredential(com.okta.sdk.resource.user.PasswordCredential) UserCredentials(com.okta.sdk.resource.user.UserCredentials)

Aggregations

PasswordCredential (com.okta.sdk.resource.user.PasswordCredential)1 RecoveryQuestionCredential (com.okta.sdk.resource.user.RecoveryQuestionCredential)1 User (com.okta.sdk.resource.user.User)1 UserCredentials (com.okta.sdk.resource.user.UserCredentials)1 UserProfile (com.okta.sdk.resource.user.UserProfile)1