Skip to content

Commit

Permalink
[SYNCOPE-1807] Propagate status changes coming from SCIM extension
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelGaro committed Feb 26, 2024
1 parent 4a71a5f commit a684566
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.syncope.core.logic;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -767,7 +768,10 @@ protected void setAttribute(
}
}

public Pair<UserUR, StatusR> toUserUpdate(final UserTO before, final SCIMPatchOperation op) {
public Pair<UserUR, StatusR> toUserUpdate(
final UserTO before,
final Collection<String> resources,
final SCIMPatchOperation op) {
StatusR statusR = null;

if (op.getPath() == null && op.getOp() != PatchOp.remove
Expand All @@ -779,6 +783,7 @@ public Pair<UserUR, StatusR> toUserUpdate(final UserTO before, final SCIMPatchOp
statusR = new StatusR.Builder(
before.getKey(),
after.isActive() ? StatusRType.REACTIVATE : StatusRType.SUSPEND).
resources(resources).
build();
}

Expand Down Expand Up @@ -825,6 +830,7 @@ public Pair<UserUR, StatusR> toUserUpdate(final UserTO before, final SCIMPatchOp
statusR = new StatusR.Builder(
before.getKey(),
(boolean) op.getValue().get(0) ? StatusRType.REACTIVATE : StatusRType.SUSPEND).
resources(resources).
build();
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.junit.jupiter.params.provider.MethodSource;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class SCIMDataBinderTest {
class SCIMDataBinderTest {

private SCIMDataBinder dataBinder;

Expand All @@ -61,6 +61,6 @@ void toUserUpdate(final String value) {
scimPatchPath.setAttribute("active");
operation.setPath(scimPatchPath);
operation.setValue(List.of(value));
assertDoesNotThrow(() -> dataBinder.toUserUpdate(new UserTO(), operation));
assertDoesNotThrow(() -> dataBinder.toUserUpdate(new UserTO(), List.of(), operation));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ public Response update(final String id, final SCIMPatchOp patch) {
}

patch.getOperations().forEach(op -> {
Pair<UserUR, StatusR> update = binder.toUserUpdate(userLogic.read(id), op);
Pair<UserUR, StatusR> update = binder.toUserUpdate(
userLogic.read(id),
userDAO.findAllResourceKeys(id),
op);
userLogic.update(update.getLeft(), false);
Optional.ofNullable(update.getRight()).ifPresent(statusR -> userLogic.status(statusR, false));
});
Expand Down

0 comments on commit a684566

Please sign in to comment.