Search in sources :

Example 6 with DerSchemaTO

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

the class SchemaDataBinderImpl method getDerSchemaTO.

@Override
public DerSchemaTO getDerSchemaTO(final DerSchema schema) {
    DerSchemaTO schemaTO = new DerSchemaTO();
    BeanUtils.copyProperties(schema, schemaTO, IGNORE_PROPERTIES);
    schemaTO.setAnyTypeClass(schema.getAnyTypeClass() == null ? null : schema.getAnyTypeClass().getKey());
    return schemaTO;
}
Also used : DerSchemaTO(org.apache.syncope.common.lib.to.DerSchemaTO)

Example 7 with DerSchemaTO

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

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

the class DerSchemaITCase method issueSYNCOPE323.

@Test
public void issueSYNCOPE323() {
    DerSchemaTO actual = schemaService.read(SchemaType.DERIVED, "rderiveddata");
    assertNotNull(actual);
    try {
        createSchema(SchemaType.DERIVED, actual);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(Response.Status.CONFLICT, e.getType().getResponseStatus());
        assertEquals(ClientExceptionType.EntityExists, e.getType());
    }
    actual.setKey(null);
    try {
        createSchema(SchemaType.DERIVED, actual);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(Response.Status.BAD_REQUEST, e.getType().getResponseStatus());
        assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
    }
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) DerSchemaTO(org.apache.syncope.common.lib.to.DerSchemaTO) Test(org.junit.jupiter.api.Test)

Example 9 with DerSchemaTO

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

the class DerSchemaITCase method create.

@Test
public void create() {
    DerSchemaTO schema = new DerSchemaTO();
    schema.setKey("derived");
    schema.setExpression("derived_sx + '_' + derived_dx");
    DerSchemaTO actual = createSchema(SchemaType.DERIVED, schema);
    assertNotNull(actual);
    actual = schemaService.read(SchemaType.DERIVED, actual.getKey());
    assertNotNull(actual);
    assertEquals(actual.getExpression(), "derived_sx + '_' + derived_dx");
}
Also used : DerSchemaTO(org.apache.syncope.common.lib.to.DerSchemaTO) Test(org.junit.jupiter.api.Test)

Example 10 with DerSchemaTO

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

the class DerSchemaITCase method read.

@Test
public void read() {
    DerSchemaTO derivedSchemaTO = schemaService.read(SchemaType.DERIVED, "cn");
    assertNotNull(derivedSchemaTO);
}
Also used : DerSchemaTO(org.apache.syncope.common.lib.to.DerSchemaTO) Test(org.junit.jupiter.api.Test)

Aggregations

DerSchemaTO (org.apache.syncope.common.lib.to.DerSchemaTO)14 Test (org.junit.jupiter.api.Test)8 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)7 PlainSchemaTO (org.apache.syncope.common.lib.to.PlainSchemaTO)4 VirSchemaTO (org.apache.syncope.common.lib.to.VirSchemaTO)3 ArrayList (java.util.ArrayList)2 DerSchema (org.apache.syncope.core.persistence.api.entity.DerSchema)2 PlainSchema (org.apache.syncope.core.persistence.api.entity.PlainSchema)2 VirSchema (org.apache.syncope.core.persistence.api.entity.VirSchema)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 AccessControlException (java.security.AccessControlException)1 NamingException (javax.naming.NamingException)1 DirContext (javax.naming.directory.DirContext)1 SearchControls (javax.naming.directory.SearchControls)1 SearchResult (javax.naming.directory.SearchResult)1 ForbiddenException (javax.ws.rs.ForbiddenException)1 Response (javax.ws.rs.core.Response)1 GroupPatch (org.apache.syncope.common.lib.patch.GroupPatch)1 AnyTypeClassTO (org.apache.syncope.common.lib.to.AnyTypeClassTO)1 AnyTypeTO (org.apache.syncope.common.lib.to.AnyTypeTO)1