Search in sources :

Example 66 with GroupTO

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

the class GroupITCase method bulkMembersAction.

@Test
public void bulkMembersAction() throws InterruptedException {
    // 1. create group without resources
    GroupTO groupTO = getBasicSampleTO("forProvision");
    groupTO = createGroup(groupTO).getEntity();
    // 2. create user with such group assigned
    UserTO userTO = UserITCase.getUniqueSampleTO("forProvision@syncope.apache.org");
    userTO.getMemberships().add(new MembershipTO.Builder().group(groupTO.getKey()).build());
    userTO = createUser(userTO).getEntity();
    // 3. modify the group by assiging the LDAP resource
    GroupPatch groupPatch = new GroupPatch();
    groupPatch.setKey(groupTO.getKey());
    groupPatch.getResources().add(new StringPatchItem.Builder().value(RESOURCE_NAME_LDAP).build());
    ProvisioningResult<GroupTO> groupUpdateResult = updateGroup(groupPatch);
    groupTO = groupUpdateResult.getEntity();
    PropagationStatus propStatus = groupUpdateResult.getPropagationStatuses().get(0);
    assertEquals(RESOURCE_NAME_LDAP, propStatus.getResource());
    assertEquals(PropagationTaskExecStatus.SUCCESS, propStatus.getStatus());
    // 4. verify that the user above is not found on LDAP
    try {
        resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), userTO.getKey());
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.NotFound, e.getType());
    }
    try {
        // 5. bulk provision group members
        ExecTO exec = groupService.bulkMembersAction(groupTO.getKey(), BulkMembersActionType.PROVISION);
        assertNotNull(exec.getRefKey());
        int i = 0;
        int maxit = 50;
        // wait for task exec completion (executions incremented)
        SchedTaskTO taskTO;
        do {
            Thread.sleep(1000);
            taskTO = taskService.read(TaskType.SCHEDULED, exec.getRefKey(), true);
            assertNotNull(taskTO);
            assertNotNull(taskTO.getExecutions());
            i++;
        } while (taskTO.getExecutions().isEmpty() && i < maxit);
        assertFalse(taskTO.getExecutions().isEmpty());
        assertEquals(TaskJob.Status.SUCCESS.name(), taskTO.getExecutions().get(0).getStatus());
        // 6. verify that the user above is now fond on LDAP
        ConnObjectTO userOnLdap = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), userTO.getKey());
        assertNotNull(userOnLdap);
    } finally {
        groupService.delete(groupTO.getKey());
        userService.delete(userTO.getKey());
    }
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) Test(org.junit.jupiter.api.Test)

Example 67 with GroupTO

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

the class GroupITCase method provision.

@Test
public void provision() {
    GroupTO groupTO = getSampleTO("provision");
    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()));
    } finally {
        if (groupTO.getKey() != null) {
            groupService.delete(groupTO.getKey());
        }
    }
}
Also used : 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 68 with GroupTO

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

the class GroupITCase method getSampleTO.

public static GroupTO getSampleTO(final String name) {
    GroupTO groupTO = getBasicSampleTO(name);
    groupTO.getPlainAttrs().add(attrTO("icon", "anIcon"));
    groupTO.getResources().add(RESOURCE_NAME_LDAP);
    return groupTO;
}
Also used : GroupTO(org.apache.syncope.common.lib.to.GroupTO)

Example 69 with GroupTO

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

the class GroupITCase method createWithInternationalCharacters.

@Test
public void createWithInternationalCharacters() {
    GroupTO groupTO = getSampleTO("räksmörgås");
    groupTO = createGroup(groupTO).getEntity();
    assertNotNull(groupTO);
}
Also used : GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 70 with GroupTO

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

the class GroupITCase method typeExtensions.

@Test
public void typeExtensions() {
    TypeExtensionTO typeExtension = new TypeExtensionTO();
    typeExtension.setAnyType(AnyTypeKind.USER.name());
    typeExtension.getAuxClasses().add("csv");
    GroupTO groupTO = getBasicSampleTO("typeExtensions");
    groupTO.getTypeExtensions().add(typeExtension);
    groupTO = createGroup(groupTO).getEntity();
    assertNotNull(groupTO);
    assertEquals(1, groupTO.getTypeExtensions().size());
    assertEquals(1, groupTO.getTypeExtension(AnyTypeKind.USER.name()).get().getAuxClasses().size());
    assertTrue(groupTO.getTypeExtension(AnyTypeKind.USER.name()).get().getAuxClasses().contains("csv"));
    typeExtension = new TypeExtensionTO();
    typeExtension.setAnyType(AnyTypeKind.USER.name());
    typeExtension.getAuxClasses().add("csv");
    typeExtension.getAuxClasses().add("other");
    GroupPatch groupPatch = new GroupPatch();
    groupPatch.setKey(groupTO.getKey());
    groupPatch.getTypeExtensions().add(typeExtension);
    groupTO = updateGroup(groupPatch).getEntity();
    assertNotNull(groupTO);
    assertEquals(1, groupTO.getTypeExtensions().size());
    assertEquals(2, groupTO.getTypeExtension(AnyTypeKind.USER.name()).get().getAuxClasses().size());
    assertTrue(groupTO.getTypeExtension(AnyTypeKind.USER.name()).get().getAuxClasses().contains("csv"));
    assertTrue(groupTO.getTypeExtension(AnyTypeKind.USER.name()).get().getAuxClasses().contains("other"));
}
Also used : TypeExtensionTO(org.apache.syncope.common.lib.to.TypeExtensionTO) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

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