Search in sources :

Example 1 with DeassociationPatch

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

the class GroupITCase method deprovision.

@Test
public void deprovision() {
    GroupTO groupTO = null;
    try {
        groupTO = createGroup(getSampleTO("deprovision")).getEntity();
        assertNotNull(groupTO);
        assertNotNull(groupTO.getKey());
        assertNotNull(resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.GROUP.name(), groupTO.getKey()));
        DeassociationPatch deassociationPatch = new DeassociationPatch.Builder().key(groupTO.getKey()).action(ResourceDeassociationAction.DEPROVISION).resource(RESOURCE_NAME_LDAP).build();
        assertNotNull(groupService.deassociate(deassociationPatch).readEntity(BulkActionResult.class));
        groupTO = groupService.read(groupTO.getKey());
        assertNotNull(groupTO);
        assertFalse(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 2 with DeassociationPatch

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

the class GroupITCase method deprovisionUnlinked.

@Test
public void deprovisionUnlinked() {
    GroupTO groupTO = getSampleTO("deprovision");
    groupTO.getResources().clear();
    try {
        groupTO = createGroup(groupTO).getEntity();
        assertNotNull(groupTO);
        try {
            resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.GROUP.name(), groupTO.getKey());
            fail("This should not happen");
        } catch (Exception e) {
            assertNotNull(e);
        }
        AssociationPatch associationPatch = new AssociationPatch.Builder().key(groupTO.getKey()).action(ResourceAssociationAction.PROVISION).resource(RESOURCE_NAME_LDAP).build();
        assertNotNull(groupService.associate(associationPatch).readEntity(BulkActionResult.class));
        groupTO = groupService.read(groupTO.getKey());
        assertTrue(groupTO.getResources().isEmpty());
        assertNotNull(resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.GROUP.name(), groupTO.getKey()));
        DeassociationPatch deassociationPatch = new DeassociationPatch.Builder().key(groupTO.getKey()).action(ResourceDeassociationAction.DEPROVISION).resource(RESOURCE_NAME_LDAP).build();
        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.getKey() != null) {
            groupService.delete(groupTO.getKey());
        }
    }
}
Also used : DeassociationPatch(org.apache.syncope.common.lib.patch.DeassociationPatch) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult) AssociationPatch(org.apache.syncope.common.lib.patch.AssociationPatch) 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 3 with DeassociationPatch

use of org.apache.syncope.common.lib.patch.DeassociationPatch 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 4 with DeassociationPatch

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

the class AbstractAnyRestClient method deprovision.

public BulkActionResult deprovision(final String etag, final String key, final List<StatusBean> statuses) {
    BulkActionResult result;
    synchronized (this) {
        AnyService<?> service = getService(etag, getAnyServiceClass());
        DeassociationPatch deassociationPatch = new DeassociationPatch.Builder().key(key).action(ResourceDeassociationAction.DEPROVISION).resources(StatusUtils.buildStatusPatch(statuses).getResources()).build();
        result = service.deassociate(deassociationPatch).readEntity(BulkActionResult.class);
        resetClient(getAnyServiceClass());
    }
    return result;
}
Also used : DeassociationPatch(org.apache.syncope.common.lib.patch.DeassociationPatch) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult)

Example 5 with DeassociationPatch

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

the class MembershipITCase method pull.

@Test
public void pull() {
    // 0. create ad-hoc resource, with adequate mapping
    ResourceTO newResource = resourceService.read(RESOURCE_NAME_DBPULL);
    newResource.setKey(getUUIDString());
    ItemTO item = newResource.getProvision("USER").get().getMapping().getItems().stream().filter(object -> "firstname".equals(object.getIntAttrName())).findFirst().get();
    assertNotNull(item);
    assertEquals("ID", item.getExtAttrName());
    item.setIntAttrName("memberships[additional].aLong");
    item.setPurpose(MappingPurpose.BOTH);
    item = newResource.getProvision("USER").get().getMapping().getItems().stream().filter(object -> "fullname".equals(object.getIntAttrName())).findFirst().get();
    item.setPurpose(MappingPurpose.PULL);
    PullTaskTO newTask = null;
    try {
        newResource = createResource(newResource);
        assertNotNull(newResource);
        // 1. create user with new resource assigned
        UserTO user = UserITCase.getUniqueSampleTO("memb@apache.org");
        user.setRealm("/even/two");
        user.getPlainAttrs().remove(user.getPlainAttr("ctype").get());
        user.getResources().clear();
        user.getResources().add(newResource.getKey());
        MembershipTO membership = new MembershipTO.Builder().group("034740a9-fa10-453b-af37-dc7897e98fb1").build();
        membership.getPlainAttrs().add(new AttrTO.Builder().schema("aLong").value("5432").build());
        user.getMemberships().add(membership);
        user = createUser(user).getEntity();
        assertNotNull(user);
        // 2. verify that user was found on resource
        JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
        String idOnResource = queryForObject(jdbcTemplate, 50, "SELECT id FROM testpull WHERE id=?", String.class, "5432");
        assertEquals("5432", idOnResource);
        // 3. unlink user from resource, then remove it
        DeassociationPatch patch = new DeassociationPatch();
        patch.setKey(user.getKey());
        patch.setAction(ResourceDeassociationAction.UNLINK);
        patch.getResources().add(newResource.getKey());
        assertNotNull(userService.deassociate(patch).readEntity(BulkActionResult.class));
        userService.delete(user.getKey());
        // 4. create pull task and execute
        newTask = taskService.read(TaskType.PULL, "7c2242f4-14af-4ab5-af31-cdae23783655", true);
        newTask.setResource(newResource.getKey());
        newTask.setDestinationRealm("/even/two");
        Response response = taskService.create(TaskType.PULL, newTask);
        newTask = getObject(response.getLocation(), TaskService.class, PullTaskTO.class);
        assertNotNull(newTask);
        ExecTO execution = AbstractTaskITCase.execProvisioningTask(taskService, TaskType.PULL, newTask.getKey(), 50, false);
        assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
        // 5. verify that pulled user has
        PagedResult<UserTO> users = userService.search(new AnyQuery.Builder().realm("/").fiql(SyncopeClient.getUserSearchConditionBuilder().is("username").equalTo(user.getUsername()).query()).build());
        assertEquals(1, users.getTotalCount());
        assertEquals(1, users.getResult().get(0).getMemberships().size());
        assertEquals("5432", users.getResult().get(0).getMemberships().get(0).getPlainAttr("aLong").get().getValues().get(0));
    } catch (Exception e) {
        LOG.error("Unexpected error", e);
        fail(e.getMessage());
    } finally {
        if (newTask != null && !"83f7e85d-9774-43fe-adba-ccd856312994".equals(newTask.getKey())) {
            taskService.delete(TaskType.PULL, newTask.getKey());
        }
        resourceService.delete(newResource.getKey());
    }
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) TaskService(org.apache.syncope.common.rest.api.service.TaskService) PropagationTaskExecStatus(org.apache.syncope.common.lib.types.PropagationTaskExecStatus) AttrTO(org.apache.syncope.common.lib.to.AttrTO) Autowired(org.springframework.beans.factory.annotation.Autowired) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) ResourceDeassociationAction(org.apache.syncope.common.lib.types.ResourceDeassociationAction) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) SpringJUnitConfig(org.springframework.test.context.junit.jupiter.SpringJUnitConfig) MembershipPatch(org.apache.syncope.common.lib.patch.MembershipPatch) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) DataSource(javax.sql.DataSource) ItemTO(org.apache.syncope.common.lib.to.ItemTO) 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) PagedResult(org.apache.syncope.common.lib.to.PagedResult) ExecTO(org.apache.syncope.common.lib.to.ExecTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) TypeExtensionTO(org.apache.syncope.common.lib.to.TypeExtensionTO) Response(javax.ws.rs.core.Response) MappingPurpose(org.apache.syncope.common.lib.types.MappingPurpose) DeassociationPatch(org.apache.syncope.common.lib.patch.DeassociationPatch) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) UserTO(org.apache.syncope.common.lib.to.UserTO) TaskType(org.apache.syncope.common.lib.types.TaskType) ExecTO(org.apache.syncope.common.lib.to.ExecTO) TaskService(org.apache.syncope.common.rest.api.service.TaskService) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) ItemTO(org.apache.syncope.common.lib.to.ItemTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Response(javax.ws.rs.core.Response) DeassociationPatch(org.apache.syncope.common.lib.patch.DeassociationPatch) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult) Test(org.junit.jupiter.api.Test)

Aggregations

DeassociationPatch (org.apache.syncope.common.lib.patch.DeassociationPatch)13 BulkActionResult (org.apache.syncope.common.lib.to.BulkActionResult)13 Test (org.junit.jupiter.api.Test)10 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)7 UserTO (org.apache.syncope.common.lib.to.UserTO)6 AccessControlException (java.security.AccessControlException)5 GroupTO (org.apache.syncope.common.lib.to.GroupTO)5 NamingException (javax.naming.NamingException)3 ForbiddenException (javax.ws.rs.ForbiddenException)3 AssociationPatch (org.apache.syncope.common.lib.patch.AssociationPatch)2 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)2 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)2 Map (java.util.Map)1 DataSource (javax.sql.DataSource)1 Response (javax.ws.rs.core.Response)1 SyncopeClient (org.apache.syncope.client.lib.SyncopeClient)1 AttrPatch (org.apache.syncope.common.lib.patch.AttrPatch)1 MembershipPatch (org.apache.syncope.common.lib.patch.MembershipPatch)1 PasswordPatch (org.apache.syncope.common.lib.patch.PasswordPatch)1 AttrTO (org.apache.syncope.common.lib.to.AttrTO)1