Search in sources :

Example 21 with AnyObjectPatch

use of org.apache.syncope.common.lib.patch.AnyObjectPatch in project syncope by apache.

the class AnyObjectLogic method update.

@Override
public ProvisioningResult<AnyObjectTO> update(final AnyObjectPatch anyObjectPatch, final boolean nullPriorityAsync) {
    AnyObjectTO anyObjectTO = binder.getAnyObjectTO(anyObjectPatch.getKey());
    Set<String> dynRealmsBefore = new HashSet<>(anyObjectTO.getDynRealms());
    Pair<AnyObjectPatch, List<LogicActions>> before = beforeUpdate(anyObjectPatch, anyObjectTO.getRealm());
    String realm = before.getLeft().getRealm() != null && StringUtils.isNotBlank(before.getLeft().getRealm().getValue()) ? before.getLeft().getRealm().getValue() : anyObjectTO.getRealm();
    Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(AnyEntitlement.UPDATE.getFor(anyObjectTO.getType())), realm);
    boolean authDynRealms = securityChecks(effectiveRealms, realm, before.getLeft().getKey());
    Pair<AnyObjectPatch, List<PropagationStatus>> updated = provisioningManager.update(anyObjectPatch, nullPriorityAsync);
    return afterUpdate(binder.getAnyObjectTO(updated.getLeft().getKey()), updated.getRight(), before.getRight(), authDynRealms, dynRealmsBefore);
}
Also used : AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) List(java.util.List) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch) HashSet(java.util.HashSet)

Example 22 with AnyObjectPatch

use of org.apache.syncope.common.lib.patch.AnyObjectPatch in project syncope by apache.

the class AnyObjectLogic method unassign.

@Override
public ProvisioningResult<AnyObjectTO> unassign(final String key, final Collection<String> resources, final boolean nullPriorityAsync) {
    // security checks
    AnyObjectTO anyObjectTO = binder.getAnyObjectTO(key);
    Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(AnyEntitlement.UPDATE.getFor(anyObjectTO.getType())), anyObjectTO.getRealm());
    securityChecks(effectiveRealms, anyObjectTO.getRealm(), anyObjectTO.getKey());
    AnyObjectPatch patch = new AnyObjectPatch();
    patch.setKey(key);
    patch.getResources().addAll(resources.stream().map(resource -> new StringPatchItem.Builder().operation(PatchOperation.DELETE).value(resource).build()).collect(Collectors.toList()));
    return update(patch, nullPriorityAsync);
}
Also used : AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch)

Example 23 with AnyObjectPatch

use of org.apache.syncope.common.lib.patch.AnyObjectPatch in project syncope by apache.

the class AnyOperationsTest method mindiff.

@Test
public void mindiff() {
    AnyObjectTO oldOne = new AnyObjectTO();
    oldOne.setName("name");
    oldOne.getPlainAttrs().add(new AttrTO.Builder().schema("plain").value("oldValue").build());
    oldOne.getPlainAttrs().add(new AttrTO.Builder().schema("encrypted").value("oldValue").build());
    AnyObjectTO newOne = new AnyObjectTO();
    newOne.setName("name");
    newOne.getPlainAttrs().add(new AttrTO.Builder().schema("plain").value("newValue").build());
    newOne.getPlainAttrs().add(new AttrTO.Builder().schema("encrypted").value("oldValue").build());
    AnyObjectPatch diff = AnyOperations.diff(newOne, oldOne, true);
    assertEquals(1, diff.getPlainAttrs().size());
    AttrPatch patch = diff.getPlainAttrs().iterator().next();
    assertEquals(PatchOperation.ADD_REPLACE, patch.getOperation());
    assertEquals("plain", patch.getAttrTO().getSchema());
}
Also used : AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) Test(org.junit.jupiter.api.Test)

Aggregations

AnyObjectPatch (org.apache.syncope.common.lib.patch.AnyObjectPatch)23 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)14 List (java.util.List)5 AttrPatch (org.apache.syncope.common.lib.patch.AttrPatch)5 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)5 Map (java.util.Map)4 Pair (org.apache.commons.lang3.tuple.Pair)4 GroupPatch (org.apache.syncope.common.lib.patch.GroupPatch)4 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)4 AttrTO (org.apache.syncope.common.lib.to.AttrTO)4 PatchOperation (org.apache.syncope.common.lib.types.PatchOperation)4 Test (org.junit.jupiter.api.Test)4 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Optional (java.util.Optional)3 Set (java.util.Set)3 SerializationUtils (org.apache.commons.lang3.SerializationUtils)3 StringUtils (org.apache.commons.lang3.StringUtils)3 AnyPatch (org.apache.syncope.common.lib.patch.AnyPatch)3 MembershipPatch (org.apache.syncope.common.lib.patch.MembershipPatch)3