Search in sources :

Example 6 with AnyObjectPatch

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

the class GroupITCase method aDynMembership.

@Test
public void aDynMembership() {
    String fiql = SyncopeClient.getAnyObjectSearchConditionBuilder("PRINTER").is("location").notNullValue().query();
    // 1. create group with a given aDynMembership condition
    GroupTO group = getBasicSampleTO("aDynMembership");
    group.getADynMembershipConds().put("PRINTER", fiql);
    group = createGroup(group).getEntity();
    assertEquals(fiql, group.getADynMembershipConds().get("PRINTER"));
    group = groupService.read(group.getKey());
    final String groupKey = group.getKey();
    assertEquals(fiql, group.getADynMembershipConds().get("PRINTER"));
    // verify that the condition is dynamically applied
    AnyObjectTO newAny = AnyObjectITCase.getSampleTO("aDynMembership");
    newAny.getResources().clear();
    newAny = createAnyObject(newAny).getEntity();
    assertNotNull(newAny.getPlainAttr("location"));
    List<MembershipTO> memberships = anyObjectService.read("fc6dbc3a-6c07-4965-8781-921e7401a4a5").getDynMemberships();
    assertTrue(memberships.stream().anyMatch(m -> m.getGroupKey().equals(groupKey)));
    memberships = anyObjectService.read("8559d14d-58c2-46eb-a2d4-a7d35161e8f8").getDynMemberships();
    assertTrue(memberships.stream().anyMatch(m -> m.getGroupKey().equals(groupKey)));
    memberships = anyObjectService.read(newAny.getKey()).getDynMemberships();
    assertTrue(memberships.stream().anyMatch(m -> m.getGroupKey().equals(groupKey)));
    // 2. update group and change aDynMembership condition
    fiql = SyncopeClient.getAnyObjectSearchConditionBuilder("PRINTER").is("location").nullValue().query();
    GroupPatch patch = new GroupPatch();
    patch.setKey(group.getKey());
    patch.getADynMembershipConds().put("PRINTER", fiql);
    group = updateGroup(patch).getEntity();
    assertEquals(fiql, group.getADynMembershipConds().get("PRINTER"));
    group = groupService.read(group.getKey());
    assertEquals(fiql, group.getADynMembershipConds().get("PRINTER"));
    // verify that the condition is dynamically applied
    AnyObjectPatch anyPatch = new AnyObjectPatch();
    anyPatch.setKey(newAny.getKey());
    anyPatch.getPlainAttrs().add(new AttrPatch.Builder().operation(PatchOperation.DELETE).attrTO(new AttrTO.Builder().schema("location").build()).build());
    newAny = updateAnyObject(anyPatch).getEntity();
    assertFalse(newAny.getPlainAttr("location").isPresent());
    memberships = anyObjectService.read("fc6dbc3a-6c07-4965-8781-921e7401a4a5").getDynMemberships();
    assertFalse(memberships.stream().anyMatch(m -> m.getGroupKey().equals(groupKey)));
    memberships = anyObjectService.read("8559d14d-58c2-46eb-a2d4-a7d35161e8f8").getDynMemberships();
    assertFalse(memberships.stream().anyMatch(m -> m.getGroupKey().equals(groupKey)));
    memberships = anyObjectService.read(newAny.getKey()).getDynMemberships();
    assertTrue(memberships.stream().anyMatch(m -> m.getGroupKey().equals(groupKey)));
}
Also used : StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NamingException(javax.naming.NamingException) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) ResourceDeassociationAction(org.apache.syncope.common.lib.types.ResourceDeassociationAction) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AttrSchemaType(org.apache.syncope.common.lib.types.AttrSchemaType) Map(java.util.Map) PagedResult(org.apache.syncope.common.lib.to.PagedResult) ExecTO(org.apache.syncope.common.lib.to.ExecTO) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult) MappingTO(org.apache.syncope.common.lib.to.MappingTO) SchemaType(org.apache.syncope.common.lib.types.SchemaType) UUID(java.util.UUID) GroupTO(org.apache.syncope.common.lib.to.GroupTO) GenericType(javax.ws.rs.core.GenericType) Test(org.junit.jupiter.api.Test) DerSchemaTO(org.apache.syncope.common.lib.to.DerSchemaTO) List(java.util.List) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) TypeExtensionTO(org.apache.syncope.common.lib.to.TypeExtensionTO) Response(javax.ws.rs.core.Response) DeassociationPatch(org.apache.syncope.common.lib.patch.DeassociationPatch) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AccessControlException(java.security.AccessControlException) NamingEnumeration(javax.naming.NamingEnumeration) TaskJob(org.apache.syncope.core.provisioning.java.job.TaskJob) SearchResult(javax.naming.directory.SearchResult) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) AnonymousAuthenticationHandler(org.apache.syncope.client.lib.AnonymousAuthenticationHandler) PropagationTaskExecStatus(org.apache.syncope.common.lib.types.PropagationTaskExecStatus) AttrTO(org.apache.syncope.common.lib.to.AttrTO) GroupService(org.apache.syncope.common.rest.api.service.GroupService) SyncopeService(org.apache.syncope.common.rest.api.service.SyncopeService) BulkMembersActionType(org.apache.syncope.common.lib.types.BulkMembersActionType) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) EntityTOUtils(org.apache.syncope.common.lib.EntityTOUtils) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch) SerializationUtils(org.apache.commons.lang3.SerializationUtils) SearchControls(javax.naming.directory.SearchControls) PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) AssociationPatch(org.apache.syncope.common.lib.patch.AssociationPatch) ItemTO(org.apache.syncope.common.lib.to.ItemTO) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AbstractITCase(org.apache.syncope.fit.AbstractITCase) AnyQuery(org.apache.syncope.common.rest.api.beans.AnyQuery) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) ForbiddenException(javax.ws.rs.ForbiddenException) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ResourceAssociationAction(org.apache.syncope.common.lib.types.ResourceAssociationAction) DirContext(javax.naming.directory.DirContext) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO) MappingPurpose(org.apache.syncope.common.lib.types.MappingPurpose) ConnectorCapability(org.apache.syncope.common.lib.types.ConnectorCapability) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) UserTO(org.apache.syncope.common.lib.to.UserTO) Collections(java.util.Collections) AnyOperations(org.apache.syncope.common.lib.AnyOperations) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) TaskType(org.apache.syncope.common.lib.types.TaskType) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 7 with AnyObjectPatch

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

the class UpdateProducer method process.

@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
    if ((exchange.getIn().getBody() instanceof WorkflowResult)) {
        Object actual = exchange.getProperty("actual");
        Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
        Set<String> excludedResources = exchange.getProperty("excludedResources", Set.class);
        if (actual instanceof UserPatch || isPull()) {
            WorkflowResult<Pair<UserPatch, Boolean>> updated = (WorkflowResult<Pair<UserPatch, Boolean>>) exchange.getIn().getBody();
            List<PropagationTaskTO> tasks;
            if (isPull()) {
                boolean passwordNotNull = updated.getResult().getKey().getPassword() != null;
                tasks = getPropagationManager().getUserUpdateTasks(updated, passwordNotNull, excludedResources);
            } else {
                tasks = getPropagationManager().getUserUpdateTasks(updated);
            }
            PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
            exchange.getOut().setBody(Pair.of(updated.getResult().getLeft(), propagationReporter.getStatuses()));
        } else if (actual instanceof AnyPatch) {
            WorkflowResult<? extends AnyPatch> updated = (WorkflowResult<? extends AnyPatch>) exchange.getIn().getBody();
            List<PropagationTaskTO> tasks = getPropagationManager().getUpdateTasks(actual instanceof AnyObjectPatch ? AnyTypeKind.ANY_OBJECT : AnyTypeKind.GROUP, updated.getResult().getKey(), false, null, updated.getPropByRes(), ((AnyPatch) actual).getVirAttrs(), excludedResources);
            PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
            exchange.getOut().setBody(Pair.of(updated.getResult(), propagationReporter.getStatuses()));
        }
    }
}
Also used : WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) AnyPatch(org.apache.syncope.common.lib.patch.AnyPatch) List(java.util.List) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch) Pair(org.apache.commons.lang3.tuple.Pair)

Example 8 with AnyObjectPatch

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

the class AnyObjectLogic method link.

@Override
public AnyObjectTO link(final String key, final Collection<String> resources) {
    // 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.ADD_REPLACE).value(resource).build()).collect(Collectors.toList()));
    return binder.getAnyObjectTO(provisioningManager.link(patch));
}
Also used : AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch)

Example 9 with AnyObjectPatch

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

the class AnyObjectLogic method unlink.

@Override
public AnyObjectTO unlink(final String key, final Collection<String> resources) {
    // 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 binder.getAnyObjectTO(provisioningManager.unlink(patch));
}
Also used : AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch)

Example 10 with AnyObjectPatch

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

the class AnyObjectLogic method assign.

@Override
public ProvisioningResult<AnyObjectTO> assign(final String key, final Collection<String> resources, final boolean changepwd, final String password, 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.ADD_REPLACE).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)

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