Search in sources :

Example 21 with GroupPatch

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

the class GroupITCase method issue178.

@Test
public void issue178() {
    GroupTO groupTO = new GroupTO();
    String groupName = "torename" + getUUIDString();
    groupTO.setName(groupName);
    groupTO.setRealm("/");
    GroupTO actual = createGroup(groupTO).getEntity();
    assertNotNull(actual);
    assertEquals(groupName, actual.getName());
    GroupPatch groupPatch = new GroupPatch();
    groupPatch.setKey(actual.getKey());
    String renamedGroup = "renamed" + getUUIDString();
    groupPatch.setName(new StringReplacePatchItem.Builder().value(renamedGroup).build());
    actual = updateGroup(groupPatch).getEntity();
    assertNotNull(actual);
    assertEquals(renamedGroup, actual.getName());
}
Also used : StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 22 with GroupPatch

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

the class GroupITCase method create.

@Test
public void create() {
    GroupTO groupTO = getSampleTO("lastGroup");
    groupTO.getVirAttrs().add(attrTO("rvirtualdata", "rvirtualvalue"));
    groupTO.setGroupOwner("f779c0d4-633b-4be5-8f57-32eb478a3ca5");
    groupTO = createGroup(groupTO).getEntity();
    assertNotNull(groupTO);
    assertNotNull(groupTO.getVirAttr("rvirtualdata").get().getValues());
    assertFalse(groupTO.getVirAttr("rvirtualdata").get().getValues().isEmpty());
    assertEquals("rvirtualvalue", groupTO.getVirAttr("rvirtualdata").get().getValues().get(0));
    assertTrue(groupTO.getResources().contains(RESOURCE_NAME_LDAP));
    ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.GROUP.name(), groupTO.getKey());
    assertNotNull(connObjectTO);
    assertNotNull(connObjectTO.getAttr("owner"));
    // SYNCOPE-515: remove ownership
    GroupPatch groupPatch = new GroupPatch();
    groupPatch.setKey(groupTO.getKey());
    groupPatch.setGroupOwner(new StringReplacePatchItem());
    assertNull(updateGroup(groupPatch).getEntity().getGroupOwner());
}
Also used : StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 23 with GroupPatch

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

the class GroupITCase method createWithMandatorySchema.

@Test
public void createWithMandatorySchema() {
    // 1. create a mandatory schema
    PlainSchemaTO badge = new PlainSchemaTO();
    badge.setKey("badge" + getUUIDString());
    badge.setMandatoryCondition("true");
    schemaService.create(SchemaType.PLAIN, badge);
    // 2. create a group *without* an attribute for that schema: it works
    GroupTO groupTO = getSampleTO("lastGroup");
    assertFalse(groupTO.getPlainAttr(badge.getKey()).isPresent());
    groupTO = createGroup(groupTO).getEntity();
    assertNotNull(groupTO);
    assertFalse(groupTO.getPlainAttr(badge.getKey()).isPresent());
    // 3. add the new mandatory schema to the default group type
    AnyTypeTO type = anyTypeService.read(AnyTypeKind.GROUP.name());
    String typeClassName = type.getClasses().get(0);
    AnyTypeClassTO typeClass = anyTypeClassService.read(typeClassName);
    typeClass.getPlainSchemas().add(badge.getKey());
    anyTypeClassService.update(typeClass);
    typeClass = anyTypeClassService.read(typeClassName);
    assertTrue(typeClass.getPlainSchemas().contains(badge.getKey()));
    try {
        // 4. update group: failure since no values are provided and it is mandatory
        GroupPatch groupPatch = new GroupPatch();
        groupPatch.setKey(groupTO.getKey());
        try {
            updateGroup(groupPatch);
            fail("This should not happen");
        } catch (SyncopeClientException e) {
            assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
        }
        // 5. also add an actual attribute for badge - it will work
        groupPatch.getPlainAttrs().add(attrAddReplacePatch(badge.getKey(), "xxxxxxxxxx"));
        groupTO = updateGroup(groupPatch).getEntity();
        assertNotNull(groupTO);
        assertNotNull(groupTO.getPlainAttr(badge.getKey()));
    } finally {
        // restore the original group class
        typeClass.getPlainSchemas().remove(badge.getKey());
        anyTypeClassService.update(typeClass);
        typeClass = anyTypeClassService.read(typeClassName);
        assertFalse(typeClass.getPlainSchemas().contains(badge.getKey()));
    }
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 24 with GroupPatch

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

the class GroupITCase method issueSYNCOPE632.

@Test
public void issueSYNCOPE632() {
    DerSchemaTO orig = schemaService.read(SchemaType.DERIVED, "displayProperty");
    DerSchemaTO modified = SerializationUtils.clone(orig);
    modified.setExpression("icon + '_' + show");
    GroupTO groupTO = GroupITCase.getSampleTO("lastGroup");
    try {
        schemaService.update(SchemaType.DERIVED, modified);
        // 0. create group
        groupTO.getPlainAttrs().add(attrTO("icon", "anIcon"));
        groupTO.getPlainAttrs().add(attrTO("show", "true"));
        groupTO.getResources().clear();
        groupTO = createGroup(groupTO).getEntity();
        assertNotNull(groupTO);
        // 1. create new LDAP resource having ConnObjectKey mapped to a derived attribute
        ResourceTO newLDAP = resourceService.read(RESOURCE_NAME_LDAP);
        newLDAP.setKey("new-ldap");
        newLDAP.setPropagationPriority(0);
        for (ProvisionTO provision : newLDAP.getProvisions()) {
            provision.getVirSchemas().clear();
        }
        MappingTO mapping = newLDAP.getProvision(AnyTypeKind.GROUP.name()).get().getMapping();
        ItemTO connObjectKey = mapping.getConnObjectKeyItem();
        connObjectKey.setIntAttrName("displayProperty");
        connObjectKey.setPurpose(MappingPurpose.PROPAGATION);
        mapping.setConnObjectKeyItem(connObjectKey);
        mapping.setConnObjectLink("'cn=' + displayProperty + ',ou=groups,o=isp'");
        ItemTO description = new ItemTO();
        description.setIntAttrName("key");
        description.setExtAttrName("description");
        description.setPurpose(MappingPurpose.PROPAGATION);
        mapping.add(description);
        newLDAP = createResource(newLDAP);
        assertNotNull(newLDAP);
        // 2. update group and give the resource created above
        GroupPatch patch = new GroupPatch();
        patch.setKey(groupTO.getKey());
        patch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value("new-ldap").build());
        groupTO = updateGroup(patch).getEntity();
        assertNotNull(groupTO);
        // 3. update the group
        GroupPatch groupPatch = new GroupPatch();
        groupPatch.setKey(groupTO.getKey());
        groupPatch.getPlainAttrs().add(attrAddReplacePatch("icon", "anotherIcon"));
        groupTO = updateGroup(groupPatch).getEntity();
        assertNotNull(groupTO);
        // 4. check that a single group exists in LDAP for the group created and updated above
        int entries = 0;
        DirContext ctx = null;
        try {
            ctx = getLdapResourceDirContext(null, null);
            SearchControls ctls = new SearchControls();
            ctls.setReturningAttributes(new String[] { "*", "+" });
            ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
            NamingEnumeration<SearchResult> result = ctx.search("ou=groups,o=isp", "(description=" + groupTO.getKey() + ")", ctls);
            while (result.hasMore()) {
                result.next();
                entries++;
            }
        } catch (Exception e) {
        // ignore
        } finally {
            if (ctx != null) {
                try {
                    ctx.close();
                } catch (NamingException e) {
                // ignore
                }
            }
        }
        assertEquals(1, entries);
    } finally {
        schemaService.update(SchemaType.DERIVED, orig);
        if (groupTO.getKey() != null) {
            groupService.delete(groupTO.getKey());
        }
        resourceService.delete("new-ldap");
    }
}
Also used : SearchResult(javax.naming.directory.SearchResult) DirContext(javax.naming.directory.DirContext) ItemTO(org.apache.syncope.common.lib.to.ItemTO) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) 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) MappingTO(org.apache.syncope.common.lib.to.MappingTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) DerSchemaTO(org.apache.syncope.common.lib.to.DerSchemaTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) SearchControls(javax.naming.directory.SearchControls) NamingException(javax.naming.NamingException) Test(org.junit.jupiter.api.Test)

Example 25 with GroupPatch

use of org.apache.syncope.common.lib.patch.GroupPatch 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)

Aggregations

GroupPatch (org.apache.syncope.common.lib.patch.GroupPatch)33 GroupTO (org.apache.syncope.common.lib.to.GroupTO)23 Test (org.junit.jupiter.api.Test)15 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)7 StringReplacePatchItem (org.apache.syncope.common.lib.patch.StringReplacePatchItem)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 List (java.util.List)5 AttrPatch (org.apache.syncope.common.lib.patch.AttrPatch)5 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)5 GroupService (org.apache.syncope.common.rest.api.service.GroupService)5 ForbiddenException (javax.ws.rs.ForbiddenException)4 Response (javax.ws.rs.core.Response)4 SyncopeClient (org.apache.syncope.client.lib.SyncopeClient)4 StringPatchItem (org.apache.syncope.common.lib.patch.StringPatchItem)4 AnyTypeClassTO (org.apache.syncope.common.lib.to.AnyTypeClassTO)4 AttrTO (org.apache.syncope.common.lib.to.AttrTO)4 AccessControlException (java.security.AccessControlException)3 Collections (java.util.Collections)3 Map (java.util.Map)3 NamingException (javax.naming.NamingException)3