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

OKTA-595091: Add setBcryptPasswordHash() to UserBuilder that takes encrypted hash string #963

Merged
merged 4 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>com.okta.sdk</groupId>
<artifactId>okta-sdk-root</artifactId>
<version>14.0.1-SNAPSHOT</version>
<version>14.1.0-SNAPSHOT</version>
</parent>

<artifactId>okta-sdk-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ default UserBuilder setGroups(String... groupIds) {

UserBuilder setNextLogin(UserNextLogin nextLogin);

UserBuilder setBcryptPasswordHash(String value);

UserBuilder setBcryptPasswordHash(String value, String salt, int workFactor);

UserBuilder setSha256PasswordHash(String value, String salt, String saltOrder);
Expand Down
2 changes: 1 addition & 1 deletion coverage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>com.okta.sdk</groupId>
<artifactId>okta-sdk-root</artifactId>
<version>14.0.1-SNAPSHOT</version>
<version>14.1.0-SNAPSHOT</version>
</parent>

<artifactId>okta-sdk-coverage</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>com.okta.sdk</groupId>
<artifactId>okta-sdk-root</artifactId>
<version>14.0.1-SNAPSHOT</version>
<version>14.1.0-SNAPSHOT</version>
</parent>

<artifactId>okta-sdk-examples</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion examples/quickstart/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>com.okta.sdk</groupId>
<artifactId>okta-sdk-examples</artifactId>
<version>14.0.1-SNAPSHOT</version>
<version>14.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>com.okta.sdk</groupId>
<artifactId>okta-sdk-root</artifactId>
<version>14.0.1-SNAPSHOT</version>
<version>14.1.0-SNAPSHOT</version>
</parent>

<artifactId>okta-sdk-impl</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.okta.sdk.impl.resource;

import com.okta.commons.lang.Assert;
import com.okta.commons.lang.Collections;
import com.okta.commons.lang.Strings;
import com.okta.sdk.resource.user.UserBuilder;
Expand Down Expand Up @@ -428,6 +429,17 @@ private UserCredentials createCredentialsIfNeeded(CreateUserRequest createUserRe
return createUserRequest.getCredentials();
}

public UserBuilder setBcryptPasswordHash(String value) {
Assert.notNull(value);
String[] tokenizedStr = value.split("\\$");
Assert.isTrue(tokenizedStr.length == 4);

int work = Integer.parseInt(tokenizedStr[2]);
String salt = tokenizedStr[3].substring(0, 22);
String hash = tokenizedStr[3].substring(22);
return setBcryptPasswordHash(hash, salt, work);
}

public UserBuilder setBcryptPasswordHash(String value, String salt, int workFactor) {
passwordHashProperties = new HashMap<>();
passwordHashProperties.put("algorithm", "BCRYPT");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2023-Present Okta, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.okta.sdk.impl.resource

import org.testng.annotations.Test

import static org.testng.Assert.assertEquals

/**
* @since 14.1.0
*/
class DefaultUserBuilderTest {

var userBuilder = new DefaultUserBuilder()

@Test
void testSetBcryptPasswordHash() {
userBuilder.setBcryptPasswordHash("\$2a\$10\$Ro0CUfOqk6cXEKf3dyaM7OhSCvnwM9s4wIX9JeLapehKK5YdLxKcm")

assertEquals(userBuilder.passwordHashProperties.size(), 4)
assertEquals(userBuilder.passwordHashProperties.salt, "Ro0CUfOqk6cXEKf3dyaM7O")
assertEquals(userBuilder.passwordHashProperties.workFactor, 10)
assertEquals(userBuilder.passwordHashProperties.value, "hSCvnwM9s4wIX9JeLapehKK5YdLxKcm")
assertEquals(userBuilder.passwordHashProperties.algorithm, "BCRYPT")
}
}
2 changes: 1 addition & 1 deletion integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>com.okta.sdk</groupId>
<artifactId>okta-sdk-root</artifactId>
<version>14.0.1-SNAPSHOT</version>
<version>14.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<groupId>com.okta.sdk</groupId>
<artifactId>okta-sdk-root</artifactId>
<version>14.0.1-SNAPSHOT</version>
<version>14.1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Okta Java SDK</name>
Expand Down Expand Up @@ -68,12 +68,12 @@
<dependency>
<groupId>com.okta.sdk</groupId>
<artifactId>okta-sdk-api</artifactId>
<version>14.0.1-SNAPSHOT</version>
<version>14.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.okta.sdk</groupId>
<artifactId>okta-sdk-impl</artifactId>
<version>14.0.1-SNAPSHOT</version>
<version>14.1.0-SNAPSHOT</version>
</dependency>

<!-- Other Okta Projects -->
Expand Down Expand Up @@ -103,14 +103,14 @@
<dependency>
<groupId>com.okta.sdk</groupId>
<artifactId>okta-sdk-integration-tests</artifactId>
<version>14.0.1-SNAPSHOT</version>
<version>14.1.0-SNAPSHOT</version>
</dependency>

<!-- Examples -->
<dependency>
<groupId>com.okta.sdk</groupId>
<artifactId>okta-sdk-examples-quickstart</artifactId>
<version>14.0.1-SNAPSHOT</version>
<version>14.1.0-SNAPSHOT</version>
</dependency>

<!-- Logging -->
Expand Down