Search in sources :

Example 41 with AnyObjectTO

use of org.apache.syncope.common.lib.to.AnyObjectTO in project syncope by apache.

the class AnyOperations method patch.

public static AnyObjectTO patch(final AnyObjectTO anyObjectTO, final AnyObjectPatch anyObjectPatch) {
    AnyObjectTO result = SerializationUtils.clone(anyObjectTO);
    patch(anyObjectTO, anyObjectPatch, result);
    if (anyObjectPatch.getName() != null) {
        result.setName(anyObjectPatch.getName().getValue());
    }
    // 1. relationships
    anyObjectPatch.getRelationships().forEach(relPatch -> {
        if (relPatch.getRelationshipTO() == null) {
            LOG.warn("Invalid {} specified: {}", RelationshipPatch.class.getName(), relPatch);
        } else {
            result.getRelationships().remove(relPatch.getRelationshipTO());
            if (relPatch.getOperation() == PatchOperation.ADD_REPLACE) {
                result.getRelationships().add(relPatch.getRelationshipTO());
            }
        }
    });
    // 2. memberships
    anyObjectPatch.getMemberships().forEach(membPatch -> {
        if (membPatch.getGroup() == null) {
            LOG.warn("Invalid {} specified: {}", MembershipPatch.class.getName(), membPatch);
        } else {
            Optional<MembershipTO> memb = result.getMemberships().stream().filter(membership -> membPatch.getGroup().equals(membership.getGroupKey())).findFirst();
            if (memb.isPresent()) {
                result.getMemberships().remove(memb.get());
            }
            if (membPatch.getOperation() == PatchOperation.ADD_REPLACE) {
                MembershipTO newMembershipTO = new MembershipTO.Builder().group(membPatch.getGroup()).build();
                // 3. plain attributes
                newMembershipTO.getPlainAttrs().addAll(membPatch.getPlainAttrs());
                // 4. virtual attributes
                newMembershipTO.getVirAttrs().addAll(membPatch.getVirAttrs());
                result.getMemberships().add(newMembershipTO);
            }
        }
    });
    return result;
}
Also used : StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) AttrTO(org.apache.syncope.common.lib.to.AttrTO) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch) LoggerFactory(org.slf4j.LoggerFactory) AnyTO(org.apache.syncope.common.lib.to.AnyTO) HashMap(java.util.HashMap) SerializationUtils(org.apache.commons.lang3.SerializationUtils) BooleanReplacePatchItem(org.apache.syncope.common.lib.patch.BooleanReplacePatchItem) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) RelationshipPatch(org.apache.syncope.common.lib.patch.RelationshipPatch) StringUtils(org.apache.commons.lang3.StringUtils) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) MembershipPatch(org.apache.syncope.common.lib.patch.MembershipPatch) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) AbstractReplacePatchItem(org.apache.syncope.common.lib.patch.AbstractReplacePatchItem) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) AnyPatch(org.apache.syncope.common.lib.patch.AnyPatch) Logger(org.slf4j.Logger) Collection(java.util.Collection) Set(java.util.Set) GroupTO(org.apache.syncope.common.lib.to.GroupTO) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) RelationshipTO(org.apache.syncope.common.lib.to.RelationshipTO) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) Optional(java.util.Optional) StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) UserTO(org.apache.syncope.common.lib.to.UserTO) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) MembershipPatch(org.apache.syncope.common.lib.patch.MembershipPatch) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) RelationshipPatch(org.apache.syncope.common.lib.patch.RelationshipPatch)

Example 42 with AnyObjectTO

use of org.apache.syncope.common.lib.to.AnyObjectTO in project syncope by apache.

the class AnyObjectLogic method delete.

@Override
public ProvisioningResult<AnyObjectTO> delete(final String key, final boolean nullPriorityAsync) {
    AnyObjectTO anyObject = binder.getAnyObjectTO(key);
    Pair<AnyObjectTO, List<LogicActions>> before = beforeDelete(anyObject);
    Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(AnyEntitlement.DELETE.getFor(before.getLeft().getType())), before.getLeft().getRealm());
    securityChecks(effectiveRealms, before.getLeft().getRealm(), before.getLeft().getKey());
    List<PropagationStatus> statuses = provisioningManager.delete(before.getLeft().getKey(), nullPriorityAsync);
    AnyObjectTO anyObjectTO = new AnyObjectTO();
    anyObjectTO.setKey(before.getLeft().getKey());
    return afterDelete(anyObjectTO, statuses, before.getRight());
}
Also used : AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) List(java.util.List)

Example 43 with AnyObjectTO

use of org.apache.syncope.common.lib.to.AnyObjectTO 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 44 with AnyObjectTO

use of org.apache.syncope.common.lib.to.AnyObjectTO 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 45 with AnyObjectTO

use of org.apache.syncope.common.lib.to.AnyObjectTO 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

AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)45 Test (org.junit.jupiter.api.Test)19 GroupTO (org.apache.syncope.common.lib.to.GroupTO)14 UserTO (org.apache.syncope.common.lib.to.UserTO)14 AnyObjectPatch (org.apache.syncope.common.lib.patch.AnyObjectPatch)13 AttrTO (org.apache.syncope.common.lib.to.AttrTO)10 List (java.util.List)9 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)8 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)8 Map (java.util.Map)7 Pair (org.apache.commons.lang3.tuple.Pair)6 AnyTO (org.apache.syncope.common.lib.to.AnyTO)6 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)6 Optional (java.util.Optional)5 Set (java.util.Set)5 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)5 AnyQuery (org.apache.syncope.common.rest.api.beans.AnyQuery)5 User (org.apache.syncope.core.persistence.api.entity.user.User)5 ArrayList (java.util.ArrayList)4 Response (javax.ws.rs.core.Response)4