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

[SYNCOPE-1824] ensuring linked account password validation on linked account (only) update #799

Merged
merged 1 commit into from
Jul 31, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ public UserWorkflowResult<Pair<UserUR, Boolean>> update(
// enforce password and account policies
enforcePolicies(
user,
userUR.getPassword() == null,
userUR.getPassword() == null && userUR.getLinkedAccounts().stream()
.allMatch(linkedAccountUR -> linkedAccountUR.getLinkedAccountTO().getPassword() == null),
Optional.ofNullable(userUR.getPassword()).map(PasswordPatch::getValue).orElse(null));
user = userDAO.save(user);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.List;
Expand Down Expand Up @@ -54,6 +55,7 @@
import org.apache.syncope.common.lib.to.TaskTO;
import org.apache.syncope.common.lib.to.UserTO;
import org.apache.syncope.common.lib.types.AnyTypeKind;
import org.apache.syncope.common.lib.types.ClientExceptionType;
import org.apache.syncope.common.lib.types.ExecStatus;
import org.apache.syncope.common.lib.types.IdMImplementationType;
import org.apache.syncope.common.lib.types.ImplementationEngine;
Expand Down Expand Up @@ -267,6 +269,20 @@ public void createWithoutLinkedAccountThenAddAndUpdatePassword() throws NamingEx
userUR = new UserUR();
userUR.setKey(user.getKey());
userUR.getLinkedAccounts().add(new LinkedAccountUR.Builder().linkedAccountTO(account).build());

// 4.1 SYNCOPE-1824 update with a wrong password, a error must be raised
account.setPassword("password");
try {
updateUser(userUR);
fail("Should not arrive here due to wrong linked account password");
} catch (SyncopeClientException sce) {
assertEquals(ClientExceptionType.InvalidUser, sce.getType());
assertEquals("InvalidUser [InvalidPassword: Password must be 10 or more characters in length.]",
sce.getMessage());
}

// set a correct password
account.setPassword("Password123");
user = updateUser(userUR).getEntity();
assertNotNull(user.getLinkedAccounts().get(0).getPassword());

Expand Down