Skip to content

Commit

Permalink
Java Mgmt SDK - Incorrect method param type in UserBuilder::setProvid…
Browse files Browse the repository at this point in the history
…er() (#567)

UserBuilder.setProvider method updated
  • Loading branch information
sergiishamrai-okta authored Mar 29, 2021
1 parent c1ce4fb commit 7a8bf76
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
5 changes: 5 additions & 0 deletions MIGRATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@ Below methods have been added.
- `ForgotPasswordResponse forgotPasswordSetNewPassword(UserCredentials userCredentials, Boolean sendEmail)`
- `ForgotPasswordResponse forgotPasswordSetNewPassword(UserCredentials userCredentials)`

### Package `com.okta.sdk.resource.user.UserBuilder`

Below method has undergone a signature change.
- `UserBuilder setProvider(Boolean provider)` signature changed to `UserBuilder setProvider(AuthenticationProvider provider)`

## Migrating from 2.x.x to 3.0.0

Version 3.0.0 of this SDK introduces a number of breaking changes from previous versions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static UserBuilder instance() {

UserBuilder setActive(Boolean active);

UserBuilder setProvider(Boolean provider);
UserBuilder setProvider(AuthenticationProvider provider);

UserBuilder setType(UserType userType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.okta.sdk.client.Client;
import com.okta.commons.lang.Collections;
import com.okta.commons.lang.Strings;
import com.okta.sdk.resource.user.AuthenticationProvider;
import com.okta.sdk.resource.user.PasswordCredentialHook;
import com.okta.sdk.resource.user.RecoveryQuestionCredential;
import com.okta.sdk.resource.user.UserBuilder;
Expand Down Expand Up @@ -48,7 +49,7 @@ public class DefaultUserBuilder implements UserBuilder {
private String lastName;
private String mobilePhone;
private Boolean active;
private Boolean provider;
private AuthenticationProvider provider;
private UserType userType;
private String userTypeId;
private UserNextLogin nextLogin;
Expand Down Expand Up @@ -117,7 +118,7 @@ public UserBuilder setActive(Boolean active) {
return this;
}

public UserBuilder setProvider(Boolean provider) {
public UserBuilder setProvider(AuthenticationProvider provider) {
this.provider = provider;
return this;
}
Expand Down Expand Up @@ -210,6 +211,11 @@ else if (userType != null) {
createCredentialsIfNeeded(createUserRequest, client).setRecoveryQuestion(question);
}

// authentication provider
if (provider != null) {
createCredentialsIfNeeded(createUserRequest, client).setProvider(provider);
}

// user password
if (password != null && password.length > 0) {

Expand Down Expand Up @@ -280,6 +286,6 @@ private UserBuilder setShaPasswordHash(String shaAlgorithm, String value, String

@Override
public User buildAndCreate(Client client) {
return client.createUser(build(client), active, provider, nextLogin);
return client.createUser(build(client), active, provider != null, nextLogin);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class DefaultUserBuilderTest {
.setNextLogin(UserNextLogin.CHANGEPASSWORD)
.buildAndCreate(client)

verify(client).createUser(eq(createUserRequest), eq(null), eq(null), eq(UserNextLogin.CHANGEPASSWORD))
verify(client).createUser(eq(createUserRequest), eq(null), eq(false), eq(UserNextLogin.CHANGEPASSWORD))
verify(profile).setFirstName("Joe")
verify(profile).setLastName("Coder")
verify(profile).setEmail("joe.coder@example.com")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.okta.sdk.resource.policy.PasswordPolicySettings
import com.okta.sdk.resource.policy.PolicyNetworkCondition
import com.okta.sdk.resource.role.AssignRoleRequest
import com.okta.sdk.resource.role.RoleType
import com.okta.sdk.resource.user.AuthenticationProvider
import com.okta.sdk.resource.user.AuthenticationProviderType
import com.okta.sdk.resource.user.ChangePasswordRequest
import com.okta.sdk.resource.user.ForgotPasswordResponse
Expand Down Expand Up @@ -823,6 +824,33 @@ class UsersIT extends ITSupport implements CrudTestSupport {
assertThat response.get("provider")["name"], equalTo("OKTA")
}

@Test
void userWithAuthenticationProviderTest() {

def firstName = 'John'
def lastName = 'Forgot-Password'
def email = "john-${uniqueTestName}@example.com"

def authenticationProvider = client.instantiate(AuthenticationProvider)
.setName(AuthenticationProviderType.FEDERATION.name())
.setType(AuthenticationProviderType.FEDERATION)

// 1. Create a user
User user = UserBuilder.instance()
.setEmail(email)
.setFirstName(firstName)
.setLastName(lastName)
.setLogin(email)
.setProvider(authenticationProvider)
.buildAndCreate(client)
registerForCleanup(user)
validateUser(user, firstName, lastName, email)

assertThat user.getCredentials(), notNullValue()
assertThat user.getCredentials().getProvider().getType(), is(AuthenticationProviderType.FEDERATION)
assertThat user.getCredentials().getProvider().getName(), equalTo(AuthenticationProviderType.FEDERATION.name())
}

private void ensureCustomProperties() {
def userSchemaUri = "/api/v1/meta/schemas/user/default"

Expand Down

0 comments on commit 7a8bf76

Please sign in to comment.