Search in sources :

Example 26 with GroupTO

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

the class GroupITCase method unassign.

@Test
public void unassign() {
    GroupTO groupTO = null;
    try {
        groupTO = createGroup(getSampleTO("unassign")).getEntity();
        assertNotNull(groupTO);
        assertNotNull(resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.GROUP.name(), groupTO.getKey()));
        DeassociationPatch deassociationPatch = new DeassociationPatch();
        deassociationPatch.setKey(groupTO.getKey());
        deassociationPatch.setAction(ResourceDeassociationAction.UNASSIGN);
        deassociationPatch.getResources().add(RESOURCE_NAME_LDAP);
        assertNotNull(groupService.deassociate(deassociationPatch).readEntity(BulkActionResult.class));
        groupTO = groupService.read(groupTO.getKey());
        assertNotNull(groupTO);
        assertTrue(groupTO.getResources().isEmpty());
        try {
            resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.GROUP.name(), groupTO.getKey());
            fail("This should not happen");
        } catch (Exception e) {
            assertNotNull(e);
        }
    } finally {
        if (groupTO != null) {
            groupService.delete(groupTO.getKey());
        }
    }
}
Also used : DeassociationPatch(org.apache.syncope.common.lib.patch.DeassociationPatch) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NamingException(javax.naming.NamingException) AccessControlException(java.security.AccessControlException) ForbiddenException(javax.ws.rs.ForbiddenException) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 27 with GroupTO

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

the class GroupITCase method capabilitiesOverride.

@Test
public void capabilitiesOverride() {
    // resource with no capability override
    ResourceTO ldap = resourceService.read(RESOURCE_NAME_LDAP);
    assertNotNull(ldap);
    assertFalse(ldap.isOverrideCapabilities());
    assertTrue(ldap.getCapabilitiesOverride().isEmpty());
    // connector with all required for create and update
    ConnInstanceTO conn = connectorService.read(ldap.getConnector(), null);
    assertNotNull(conn);
    assertTrue(conn.getCapabilities().contains(ConnectorCapability.CREATE));
    assertTrue(conn.getCapabilities().contains(ConnectorCapability.UPDATE));
    try {
        // 1. create succeeds
        GroupTO group = getSampleTO("syncope714");
        group.getPlainAttrs().add(attrTO("title", "first"));
        group.getResources().add(RESOURCE_NAME_LDAP);
        ProvisioningResult<GroupTO> result = createGroup(group);
        assertNotNull(result);
        assertEquals(1, result.getPropagationStatuses().size());
        assertEquals(RESOURCE_NAME_LDAP, result.getPropagationStatuses().get(0).getResource());
        assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
        group = result.getEntity();
        // 2. update succeeds
        GroupPatch patch = new GroupPatch();
        patch.setKey(group.getKey());
        patch.getPlainAttrs().add(new AttrPatch.Builder().operation(PatchOperation.ADD_REPLACE).attrTO(attrTO("title", "second")).build());
        result = updateGroup(patch);
        assertNotNull(result);
        assertEquals(1, result.getPropagationStatuses().size());
        assertEquals(RESOURCE_NAME_LDAP, result.getPropagationStatuses().get(0).getResource());
        assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
        group = result.getEntity();
        // 3. set capability override with only search allowed, but not enable
        ldap.getCapabilitiesOverride().add(ConnectorCapability.SEARCH);
        resourceService.update(ldap);
        ldap = resourceService.read(RESOURCE_NAME_LDAP);
        assertNotNull(ldap);
        assertFalse(ldap.isOverrideCapabilities());
        assertEquals(1, ldap.getCapabilitiesOverride().size());
        assertTrue(ldap.getCapabilitiesOverride().contains(ConnectorCapability.SEARCH));
        // 4. update succeeds again
        patch = new GroupPatch();
        patch.setKey(group.getKey());
        patch.getPlainAttrs().add(new AttrPatch.Builder().operation(PatchOperation.ADD_REPLACE).attrTO(attrTO("title", "third")).build());
        result = updateGroup(patch);
        assertNotNull(result);
        assertEquals(1, result.getPropagationStatuses().size());
        assertEquals(RESOURCE_NAME_LDAP, result.getPropagationStatuses().get(0).getResource());
        assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
        group = result.getEntity();
        // 5. enable capability override
        ldap.setOverrideCapabilities(true);
        resourceService.update(ldap);
        ldap = resourceService.read(RESOURCE_NAME_LDAP);
        assertNotNull(ldap);
        assertTrue(ldap.isOverrideCapabilities());
        assertEquals(1, ldap.getCapabilitiesOverride().size());
        assertTrue(ldap.getCapabilitiesOverride().contains(ConnectorCapability.SEARCH));
        // 6. update now fails
        patch = new GroupPatch();
        patch.setKey(group.getKey());
        patch.getPlainAttrs().add(new AttrPatch.Builder().operation(PatchOperation.ADD_REPLACE).attrTO(attrTO("title", "fourth")).build());
        result = updateGroup(patch);
        assertNotNull(result);
        assertEquals(1, result.getPropagationStatuses().size());
        assertEquals(RESOURCE_NAME_LDAP, result.getPropagationStatuses().get(0).getResource());
        assertEquals(PropagationTaskExecStatus.NOT_ATTEMPTED, result.getPropagationStatuses().get(0).getStatus());
    } finally {
        ldap.getCapabilitiesOverride().clear();
        ldap.setOverrideCapabilities(false);
        resourceService.update(ldap);
    }
}
Also used : ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 28 with GroupTO

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

the class RESTITCase method noContent.

@Test
public void noContent() throws IOException {
    SyncopeClient noContentclient = clientFactory.create(ADMIN_UNAME, ADMIN_PWD);
    GroupService noContentService = noContentclient.prefer(noContentclient.getService(GroupService.class), Preference.RETURN_NO_CONTENT);
    GroupTO group = GroupITCase.getSampleTO("noContent");
    Response response = noContentService.create(group);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
    assertEquals(Preference.RETURN_NO_CONTENT.toString(), response.getHeaderString(RESTHeaders.PREFERENCE_APPLIED));
    assertEquals(StringUtils.EMPTY, IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8));
    group = getObject(response.getLocation(), GroupService.class, GroupTO.class);
    assertNotNull(group);
    GroupPatch groupPatch = new GroupPatch();
    groupPatch.setKey(group.getKey());
    groupPatch.getPlainAttrs().add(attrAddReplacePatch("badge", "xxxxxxxxxx"));
    response = noContentService.update(groupPatch);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
    assertEquals(Preference.RETURN_NO_CONTENT.toString(), response.getHeaderString(RESTHeaders.PREFERENCE_APPLIED));
    assertEquals(StringUtils.EMPTY, IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8));
    response = noContentService.delete(group.getKey());
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
    assertEquals(Preference.RETURN_NO_CONTENT.toString(), response.getHeaderString(RESTHeaders.PREFERENCE_APPLIED));
    assertEquals(StringUtils.EMPTY, IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8));
}
Also used : Response(javax.ws.rs.core.Response) InputStream(java.io.InputStream) GroupService(org.apache.syncope.common.rest.api.service.GroupService) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 29 with GroupTO

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

the class ResourceITCase method listConnObjects.

@Test
public void listConnObjects() {
    List<String> groupKeys = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        GroupTO group = GroupITCase.getSampleTO("group");
        group.getResources().add(RESOURCE_NAME_LDAP);
        group = createGroup(group).getEntity();
        groupKeys.add(group.getKey());
    }
    int totalRead = 0;
    Set<String> read = new HashSet<>();
    try {
        ConnObjectTOListQuery.Builder builder = new ConnObjectTOListQuery.Builder().size(10);
        PagedConnObjectTOResult list;
        do {
            list = null;
            boolean succeeded = false;
            // needed because ApacheDS seems to randomly fail when searching with cookie
            for (int i = 0; i < 5 && !succeeded; i++) {
                try {
                    list = resourceService.listConnObjects(RESOURCE_NAME_LDAP, AnyTypeKind.GROUP.name(), builder.build());
                    succeeded = true;
                } catch (SyncopeClientException e) {
                    assertEquals(ClientExceptionType.ConnectorException, e.getType());
                }
            }
            assertNotNull(list);
            totalRead += list.getResult().size();
            read.addAll(list.getResult().stream().map(input -> input.getAttr(ConnIdSpecialName.NAME).get().getValues().get(0)).collect(Collectors.toList()));
            if (list.getPagedResultsCookie() != null) {
                builder.pagedResultsCookie(list.getPagedResultsCookie());
            }
        } while (list.getPagedResultsCookie() != null);
        assertEquals(totalRead, read.size());
        assertTrue(totalRead >= 10);
    } finally {
        groupKeys.forEach(key -> {
            groupService.delete(key);
        });
    }
}
Also used : ArrayList(java.util.ArrayList) ConnObjectTOListQuery(org.apache.syncope.common.rest.api.beans.ConnObjectTOListQuery) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PagedConnObjectTOResult(org.apache.syncope.common.lib.to.PagedConnObjectTOResult) GroupTO(org.apache.syncope.common.lib.to.GroupTO) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 30 with GroupTO

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

the class CreateProducer method process.

@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
    if ((exchange.getIn().getBody() instanceof WorkflowResult)) {
        Object actual = exchange.getProperty("actual");
        Set<String> excludedResources = exchange.getProperty("excludedResources", Set.class);
        Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
        if (actual instanceof UserTO) {
            WorkflowResult<Pair<String, Boolean>> created = (WorkflowResult<Pair<String, Boolean>>) exchange.getIn().getBody();
            List<PropagationTaskTO> tasks = getPropagationManager().getUserCreateTasks(created.getResult().getKey(), ((UserTO) actual).getPassword(), created.getResult().getValue(), created.getPropByRes(), ((UserTO) actual).getVirAttrs(), excludedResources);
            PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
            exchange.getOut().setBody(Pair.of(created.getResult().getKey(), propagationReporter.getStatuses()));
        } else if (actual instanceof AnyTO) {
            WorkflowResult<String> created = (WorkflowResult<String>) exchange.getIn().getBody();
            if (actual instanceof GroupTO && isPull()) {
                Map<String, String> groupOwnerMap = exchange.getProperty("groupOwnerMap", Map.class);
                Optional<AttrTO> groupOwner = ((GroupTO) actual).getPlainAttr(StringUtils.EMPTY);
                if (groupOwner.isPresent()) {
                    groupOwnerMap.put(created.getResult(), groupOwner.get().getValues().iterator().next());
                }
                List<PropagationTaskTO> tasks = getPropagationManager().getCreateTasks(AnyTypeKind.GROUP, created.getResult(), created.getPropByRes(), ((AnyTO) actual).getVirAttrs(), excludedResources);
                getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
                exchange.getOut().setBody(Pair.of(created.getResult(), null));
            } else {
                List<PropagationTaskTO> tasks = getPropagationManager().getCreateTasks(actual instanceof AnyObjectTO ? AnyTypeKind.ANY_OBJECT : AnyTypeKind.GROUP, created.getResult(), created.getPropByRes(), ((AnyTO) actual).getVirAttrs(), excludedResources);
                PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
                exchange.getOut().setBody(Pair.of(created.getResult(), propagationReporter.getStatuses()));
            }
        }
    }
}
Also used : AnyTO(org.apache.syncope.common.lib.to.AnyTO) WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) Optional(java.util.Optional) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) GroupTO(org.apache.syncope.common.lib.to.GroupTO) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) UserTO(org.apache.syncope.common.lib.to.UserTO) List(java.util.List) Map(java.util.Map) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

GroupTO (org.apache.syncope.common.lib.to.GroupTO)90 Test (org.junit.jupiter.api.Test)47 UserTO (org.apache.syncope.common.lib.to.UserTO)34 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)27 GroupPatch (org.apache.syncope.common.lib.patch.GroupPatch)23 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)17 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)16 List (java.util.List)15 AttrTO (org.apache.syncope.common.lib.to.AttrTO)15 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)14 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)14 Response (javax.ws.rs.core.Response)13 NamingException (javax.naming.NamingException)12 PropagationStatus (org.apache.syncope.common.lib.to.PropagationStatus)12 Map (java.util.Map)11 ForbiddenException (javax.ws.rs.ForbiddenException)11 AccessControlException (java.security.AccessControlException)10 BulkActionResult (org.apache.syncope.common.lib.to.BulkActionResult)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 Collections (java.util.Collections)9