Search in sources :

Example 16 with MappingTO

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

the class PushTaskITCase method issueSYNCOPE598.

@Test
public void issueSYNCOPE598() {
    // create a new group schema
    PlainSchemaTO schemaTO = new PlainSchemaTO();
    schemaTO.setKey("LDAPGroupName" + getUUIDString());
    schemaTO.setType(AttrSchemaType.String);
    schemaTO.setMandatoryCondition("true");
    schemaTO = createSchema(SchemaType.PLAIN, schemaTO);
    assertNotNull(schemaTO);
    AnyTypeClassTO typeClass = new AnyTypeClassTO();
    typeClass.setKey("SYNCOPE-598" + getUUIDString());
    typeClass.getPlainSchemas().add(schemaTO.getKey());
    anyTypeClassService.create(typeClass);
    // create a new sample group
    GroupTO groupTO = new GroupTO();
    groupTO.setName("all" + getUUIDString());
    groupTO.setRealm("/even");
    groupTO.getAuxClasses().add(typeClass.getKey());
    groupTO.getPlainAttrs().add(attrTO(schemaTO.getKey(), "all"));
    groupTO = createGroup(groupTO).getEntity();
    assertNotNull(groupTO);
    String resourceName = "resource-ldap-grouponly";
    ResourceTO newResourceTO = null;
    try {
        // Create resource ad-hoc
        ResourceTO resourceTO = new ResourceTO();
        resourceTO.setKey(resourceName);
        resourceTO.setConnector("74141a3b-0762-4720-a4aa-fc3e374ef3ef");
        ProvisionTO provisionTO = new ProvisionTO();
        provisionTO.setAnyType(AnyTypeKind.GROUP.name());
        provisionTO.setObjectClass(ObjectClass.GROUP_NAME);
        provisionTO.getAuxClasses().add(typeClass.getKey());
        resourceTO.getProvisions().add(provisionTO);
        MappingTO mapping = new MappingTO();
        provisionTO.setMapping(mapping);
        ItemTO item = new ItemTO();
        item.setExtAttrName("cn");
        item.setIntAttrName(schemaTO.getKey());
        item.setConnObjectKey(true);
        item.setPurpose(MappingPurpose.BOTH);
        mapping.setConnObjectKeyItem(item);
        mapping.setConnObjectLink("'cn=' + " + schemaTO.getKey() + " + ',ou=groups,o=isp'");
        Response response = resourceService.create(resourceTO);
        newResourceTO = getObject(response.getLocation(), ResourceService.class, ResourceTO.class);
        assertNotNull(newResourceTO);
        assertFalse(newResourceTO.getProvision(AnyTypeKind.USER.name()).isPresent());
        assertNotNull(newResourceTO.getProvision(AnyTypeKind.GROUP.name()).get().getMapping());
        // create push task ad-hoc
        PushTaskTO task = new PushTaskTO();
        task.setName("issueSYNCOPE598");
        task.setActive(true);
        task.setResource(resourceName);
        task.setSourceRealm(SyncopeConstants.ROOT_REALM);
        task.setPerformCreate(true);
        task.setPerformDelete(true);
        task.setPerformUpdate(true);
        task.setUnmatchingRule(UnmatchingRule.ASSIGN);
        task.setMatchingRule(MatchingRule.UPDATE);
        task.getFilters().put(AnyTypeKind.GROUP.name(), SyncopeClient.getGroupSearchConditionBuilder().is("name").equalTo(groupTO.getName()).query());
        response = taskService.create(TaskType.PUSH, task);
        PushTaskTO push = getObject(response.getLocation(), TaskService.class, PushTaskTO.class);
        assertNotNull(push);
        // execute the new task
        ExecTO exec = execProvisioningTask(taskService, TaskType.PUSH, push.getKey(), 50, false);
        assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(exec.getStatus()));
    } finally {
        groupService.delete(groupTO.getKey());
        if (newResourceTO != null) {
            resourceService.delete(resourceName);
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) MappingTO(org.apache.syncope.common.lib.to.MappingTO) ExecTO(org.apache.syncope.common.lib.to.ExecTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) PushTaskTO(org.apache.syncope.common.lib.to.PushTaskTO) ResourceService(org.apache.syncope.common.rest.api.service.ResourceService) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 17 with MappingTO

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

the class ResourceITCase method createOverridingProps.

@Test
public void createOverridingProps() {
    String resourceKey = "overriding-conn-conf-target-resource-create";
    ResourceTO resourceTO = new ResourceTO();
    ProvisionTO provisionTO = new ProvisionTO();
    provisionTO.setAnyType(AnyTypeKind.USER.name());
    provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME);
    resourceTO.getProvisions().add(provisionTO);
    MappingTO mapping = new MappingTO();
    provisionTO.setMapping(mapping);
    ItemTO item = new ItemTO();
    item.setExtAttrName("uid");
    item.setIntAttrName("userId");
    item.setPurpose(MappingPurpose.BOTH);
    mapping.add(item);
    item = new ItemTO();
    item.setExtAttrName("username");
    item.setIntAttrName("key");
    item.setConnObjectKey(true);
    item.setPurpose(MappingPurpose.BOTH);
    mapping.setConnObjectKeyItem(item);
    item = new ItemTO();
    item.setExtAttrName("fullname");
    item.setIntAttrName("cn");
    item.setConnObjectKey(false);
    item.setPurpose(MappingPurpose.PROPAGATION);
    mapping.add(item);
    resourceTO.setKey(resourceKey);
    resourceTO.setConnector("5ffbb4ac-a8c3-4b44-b699-11b398a1ba08");
    ConnConfProperty prop = new ConnConfProperty();
    ConnConfPropSchema schema = new ConnConfPropSchema();
    schema.setType("java.lang.String");
    schema.setName("endpoint");
    schema.setRequired(true);
    prop.setSchema(schema);
    prop.getValues().add("http://invalidurl/");
    Set<ConnConfProperty> connectorConfigurationProperties = new HashSet<>(Arrays.asList(prop));
    resourceTO.getConfOverride().addAll(connectorConfigurationProperties);
    Response response = resourceService.create(resourceTO);
    ResourceTO actual = getObject(response.getLocation(), ResourceService.class, ResourceTO.class);
    assertNotNull(actual);
    // check the existence
    actual = resourceService.read(resourceKey);
    assertNotNull(actual);
    assertNull(actual.getPropagationPriority());
}
Also used : Response(javax.ws.rs.core.Response) MappingTO(org.apache.syncope.common.lib.to.MappingTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO) ConnConfPropSchema(org.apache.syncope.common.lib.types.ConnConfPropSchema) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 18 with MappingTO

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

the class ResourceITCase method issueSYNCOPE645.

public void issueSYNCOPE645() {
    ResourceTO resource = new ResourceTO();
    resource.setKey("ws-target-resource-basic-save-invalid");
    String connector = resourceService.read("ws-target-resource-1").getConnector();
    resource.setConnector(connector);
    ProvisionTO provision = new ProvisionTO();
    provision.setAnyType(AnyTypeKind.USER.name());
    provision.setObjectClass("__ACCOUNT__");
    resource.getProvisions().add(provision);
    MappingTO mapping = new MappingTO();
    provision.setMapping(mapping);
    ItemTO item = new ItemTO();
    item.setIntAttrName("icon");
    item.setExtAttrName("icon");
    item.setPurpose(MappingPurpose.BOTH);
    mapping.setConnObjectKeyItem(item);
    // save the resource
    try {
        resourceService.create(resource);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.InvalidMapping, e.getType());
    }
}
Also used : MappingTO(org.apache.syncope.common.lib.to.MappingTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO)

Example 19 with MappingTO

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

the class ResourceITCase method buildResourceTO.

private ResourceTO buildResourceTO(final String resourceKey) {
    ResourceTO resourceTO = new ResourceTO();
    resourceTO.setKey(resourceKey);
    resourceTO.setConnector("5ffbb4ac-a8c3-4b44-b699-11b398a1ba08");
    ProvisionTO provisionTO = new ProvisionTO();
    provisionTO.setAnyType(AnyTypeKind.USER.name());
    provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME);
    resourceTO.getProvisions().add(provisionTO);
    MappingTO mapping = new MappingTO();
    provisionTO.setMapping(mapping);
    ItemTO item = new ItemTO();
    item.setExtAttrName("userId");
    item.setIntAttrName("userId");
    item.setPurpose(MappingPurpose.BOTH);
    mapping.add(item);
    item = new ItemTO();
    item.setExtAttrName("username");
    item.setIntAttrName("key");
    item.setPurpose(MappingPurpose.BOTH);
    mapping.setConnObjectKeyItem(item);
    item = new ItemTO();
    item.setExtAttrName("fullname");
    item.setIntAttrName("cn");
    item.setConnObjectKey(false);
    item.setPurpose(MappingPurpose.PROPAGATION);
    mapping.add(item);
    return resourceTO;
}
Also used : MappingTO(org.apache.syncope.common.lib.to.MappingTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO)

Example 20 with MappingTO

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

Aggregations

MappingTO (org.apache.syncope.common.lib.to.MappingTO)23 ItemTO (org.apache.syncope.common.lib.to.ItemTO)21 ProvisionTO (org.apache.syncope.common.lib.to.ProvisionTO)21 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)21 Test (org.junit.jupiter.api.Test)17 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)10 Response (javax.ws.rs.core.Response)8 HashSet (java.util.HashSet)6 AnyTypeClassTO (org.apache.syncope.common.lib.to.AnyTypeClassTO)5 GroupTO (org.apache.syncope.common.lib.to.GroupTO)5 ResourceService (org.apache.syncope.common.rest.api.service.ResourceService)5 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 OrgUnitTO (org.apache.syncope.common.lib.to.OrgUnitTO)4 UserTO (org.apache.syncope.common.lib.to.UserTO)4 ConnConfProperty (org.apache.syncope.common.lib.types.ConnConfProperty)4 MappingPurpose (org.apache.syncope.common.lib.types.MappingPurpose)3 ObjectClass (org.identityconnectors.framework.common.objects.ObjectClass)3 ParseException (java.text.ParseException)2 Collections (java.util.Collections)2