Search in sources :

Example 61 with GroupTO

use of org.apache.syncope.common.lib.to.GroupTO 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 62 with GroupTO

use of org.apache.syncope.common.lib.to.GroupTO 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 63 with GroupTO

use of org.apache.syncope.common.lib.to.GroupTO 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 64 with GroupTO

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

the class GroupITCase method delete.

@Test
public void delete() {
    try {
        groupService.delete(UUID.randomUUID().toString());
    } catch (SyncopeClientException e) {
        assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus());
    }
    GroupTO groupTO = new GroupTO();
    groupTO.setName("toBeDeleted" + getUUIDString());
    groupTO.setRealm("/even");
    groupTO.getResources().add(RESOURCE_NAME_LDAP);
    groupTO = createGroup(groupTO).getEntity();
    assertNotNull(groupTO);
    GroupTO deletedGroup = deleteGroup(groupTO.getKey()).getEntity();
    assertNotNull(deletedGroup);
    try {
        groupService.read(deletedGroup.getKey());
    } catch (SyncopeClientException e) {
        assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus());
    }
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 65 with GroupTO

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

the class GroupITCase method assign.

@Test
public void assign() {
    GroupTO groupTO = getSampleTO("assign");
    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.ASSIGN).resource(RESOURCE_NAME_LDAP).build();
        assertNotNull(groupService.associate(associationPatch).readEntity(BulkActionResult.class));
        groupTO = groupService.read(groupTO.getKey());
        assertFalse(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)

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