Skip to content

Commit

Permalink
[SYNCOPE-1824] ensuring linked account password validation on linked …
Browse files Browse the repository at this point in the history
…account (only) update (#799)
  • Loading branch information
andrea-patricelli authored Jul 31, 2024
1 parent b95574e commit be12989
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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

0 comments on commit be12989

Please sign in to comment.