Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java Mgmt SDK - Incorrect method param type in UserBuilder::setProvider() #567

Merged
merged 4 commits into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions MIGRATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,17 @@ 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)`

### Package `com.okta.sdk.resource.impl.DefaultUserBuilder`
sergiishamrai-okta marked this conversation as resolved.
Show resolved Hide resolved

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)
sergiishamrai-okta marked this conversation as resolved.
Show resolved Hide resolved
authenticationProvider.setName(AuthenticationProviderType.FEDERATION.toString())
authenticationProvider.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.toString())
sergiishamrai-okta marked this conversation as resolved.
Show resolved Hide resolved
}

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

Expand Down