Search in sources :

Example 11 with ConnObjectTO

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

the class AnyDirectoryPanel method customResultBody.

@Override
@SuppressWarnings("unchecked")
protected Panel customResultBody(final String panelId, final AnyWrapper<A> item, final Serializable result) {
    if (!(result instanceof ProvisioningResult)) {
        throw new IllegalStateException("Unsupported result type");
    }
    return new StatusPanel(panelId, ((ProvisioningResult<A>) result).getEntity(), new ListModel<>(new ArrayList<>()), ((ProvisioningResult<A>) result).getPropagationStatuses().stream().map(input -> {
        ConnObjectTO before = input.getBeforeObj();
        ConnObjectWrapper afterObjWrapper = new ConnObjectWrapper(((ProvisioningResult<A>) result).getEntity(), input.getResource(), input.getAfterObj());
        return Pair.of(before, afterObjWrapper);
    }).collect(Collectors.toList()), pageRef);
}
Also used : ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) ArrayList(java.util.ArrayList) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) StatusPanel(org.apache.syncope.client.console.wizards.any.StatusPanel) ConnObjectWrapper(org.apache.syncope.client.console.commons.status.ConnObjectWrapper)

Example 12 with ConnObjectTO

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

the class AnyObjectITCase method create.

@Test
public void create() {
    AnyObjectTO anyObjectTO = getSampleTO("create");
    anyObjectTO = createAnyObject(anyObjectTO).getEntity();
    assertNotNull(anyObjectTO);
    ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_DBSCRIPTED, anyObjectTO.getType(), anyObjectTO.getKey());
    assertNotNull(connObjectTO);
    assertNotNull(connObjectTO.getAttr("LOCATION"));
    assertEquals(anyObjectTO.getPlainAttr("location").get().getValues(), connObjectTO.getAttr("LOCATION").get().getValues());
}
Also used : AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) Test(org.junit.jupiter.api.Test)

Example 13 with ConnObjectTO

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

the class PropagationTaskITCase method propagationJEXLTransformer.

@Test
public void propagationJEXLTransformer() {
    // 0. Set propagation JEXL MappingItemTransformer
    ResourceTO resource = resourceService.read(RESOURCE_NAME_DBSCRIPTED);
    ResourceTO originalResource = SerializationUtils.clone(resource);
    ProvisionTO provision = resource.getProvision("PRINTER").get();
    assertNotNull(provision);
    Optional<ItemTO> mappingItem = provision.getMapping().getItems().stream().filter(item -> "location".equals(item.getIntAttrName())).findFirst();
    assertTrue(mappingItem.isPresent());
    assertTrue(mappingItem.get().getTransformers().isEmpty());
    String suffix = getUUIDString();
    mappingItem.get().setPropagationJEXLTransformer("value + '" + suffix + "'");
    try {
        resourceService.update(resource);
        // 1. create printer on external resource
        AnyObjectTO anyObjectTO = AnyObjectITCase.getSampleTO("propagationJEXLTransformer");
        String originalLocation = anyObjectTO.getPlainAttr("location").get().getValues().get(0);
        assertFalse(originalLocation.endsWith(suffix));
        anyObjectTO = createAnyObject(anyObjectTO).getEntity();
        assertNotNull(anyObjectTO);
        // 2. verify that JEXL MappingItemTransformer was applied during propagation
        // (location ends with given suffix on external resource)
        ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_DBSCRIPTED, anyObjectTO.getType(), anyObjectTO.getKey());
        assertFalse(anyObjectTO.getPlainAttr("location").get().getValues().get(0).endsWith(suffix));
        assertTrue(connObjectTO.getAttr("LOCATION").get().getValues().get(0).endsWith(suffix));
    } finally {
        resourceService.update(originalResource);
    }
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ExecuteQuery(org.apache.syncope.common.rest.api.beans.ExecuteQuery) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) TaskTO(org.apache.syncope.common.lib.to.TaskTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) SerializationUtils(org.apache.commons.lang3.SerializationUtils) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) ArrayList(java.util.ArrayList) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ItemTO(org.apache.syncope.common.lib.to.ItemTO) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PagedResult(org.apache.syncope.common.lib.to.PagedResult) ExecTO(org.apache.syncope.common.lib.to.ExecTO) TaskQuery(org.apache.syncope.common.rest.api.beans.TaskQuery) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ExecQuery(org.apache.syncope.common.rest.api.beans.ExecQuery) Test(org.junit.jupiter.api.Test) List(java.util.List) MappingPurpose(org.apache.syncope.common.lib.types.MappingPurpose) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) BulkAction(org.apache.syncope.common.lib.to.BulkAction) UserTO(org.apache.syncope.common.lib.to.UserTO) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) TaskType(org.apache.syncope.common.lib.types.TaskType) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO) Test(org.junit.jupiter.api.Test)

Example 14 with ConnObjectTO

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

the class PullTaskITCase method reconcileFromScriptedSQL.

@Test
public void reconcileFromScriptedSQL() throws IOException {
    // 0. reset sync token and set MappingItemTransformer
    ResourceTO resource = resourceService.read(RESOURCE_NAME_DBSCRIPTED);
    ResourceTO originalResource = SerializationUtils.clone(resource);
    ProvisionTO provision = resource.getProvision("PRINTER").get();
    assertNotNull(provision);
    ItemTO mappingItem = provision.getMapping().getItems().stream().filter(object -> "location".equals(object.getIntAttrName())).findFirst().get();
    assertNotNull(mappingItem);
    final String prefix = "PREFIX_";
    ImplementationTO transformer = new ImplementationTO();
    transformer.setKey("PrefixItemTransformer");
    transformer.setEngine(ImplementationEngine.GROOVY);
    transformer.setType(ImplementationType.ITEM_TRANSFORMER);
    transformer.setBody(IOUtils.toString(getClass().getResourceAsStream("/PrefixItemTransformer.groovy"), StandardCharsets.UTF_8));
    Response response = implementationService.create(transformer);
    transformer = implementationService.read(transformer.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
    assertNotNull(transformer);
    mappingItem.getTransformers().clear();
    mappingItem.getTransformers().add(transformer.getKey());
    try {
        resourceService.update(resource);
        resourceService.removeSyncToken(resource.getKey(), provision.getAnyType());
        // insert a deleted record in the external resource (SYNCOPE-923), which will be returned
        // as sync event prior to the CREATE_OR_UPDATE events generated by the actions below (before pull)
        JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
        jdbcTemplate.update("INSERT INTO TESTPRINTER (id, printername, location, deleted, lastmodification) VALUES (?,?,?,?,?)", UUID.randomUUID().toString(), "Mysterious Printer", "Nowhere", true, new Date());
        // 1. create printer on external resource
        AnyObjectTO anyObjectTO = AnyObjectITCase.getSampleTO("pull");
        String originalLocation = anyObjectTO.getPlainAttr("location").get().getValues().get(0);
        assertFalse(originalLocation.startsWith(prefix));
        anyObjectTO = createAnyObject(anyObjectTO).getEntity();
        assertNotNull(anyObjectTO);
        // 2. verify that PrefixMappingItemTransformer was applied during propagation
        // (location starts with given prefix on external resource)
        ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_DBSCRIPTED, anyObjectTO.getType(), anyObjectTO.getKey());
        assertFalse(anyObjectTO.getPlainAttr("location").get().getValues().get(0).startsWith(prefix));
        assertTrue(connObjectTO.getAttr("LOCATION").get().getValues().get(0).startsWith(prefix));
        // 3. unlink any existing printer and delete from Syncope (printer is now only on external resource)
        PagedResult<AnyObjectTO> matchingPrinters = anyObjectService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getAnyObjectSearchConditionBuilder("PRINTER").is("location").equalTo("pull*").query()).build());
        assertTrue(matchingPrinters.getSize() > 0);
        for (AnyObjectTO printer : matchingPrinters.getResult()) {
            anyObjectService.deassociate(new DeassociationPatch.Builder().key(printer.getKey()).action(ResourceDeassociationAction.UNLINK).resource(RESOURCE_NAME_DBSCRIPTED).build());
            anyObjectService.delete(printer.getKey());
        }
        // ensure that the pull task does not have the DELETE capability (SYNCOPE-923)
        PullTaskTO pullTask = taskService.read(TaskType.PULL, "30cfd653-257b-495f-8665-281281dbcb3d", false);
        assertNotNull(pullTask);
        assertFalse(pullTask.isPerformDelete());
        // 4. pull
        execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
        // 5. verify that printer was re-created in Syncope (implies that location does not start with given prefix,
        // hence PrefixItemTransformer was applied during pull)
        matchingPrinters = anyObjectService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getAnyObjectSearchConditionBuilder("PRINTER").is("location").equalTo("pull*").query()).build());
        assertTrue(matchingPrinters.getSize() > 0);
        // 6. verify that synctoken was updated
        assertNotNull(resourceService.read(RESOURCE_NAME_DBSCRIPTED).getProvision(anyObjectTO.getType()).get().getSyncToken());
    } finally {
        resourceService.update(originalResource);
    }
}
Also used : JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) ItemTO(org.apache.syncope.common.lib.to.ItemTO) Date(java.util.Date) ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) DeassociationPatch(org.apache.syncope.common.lib.patch.DeassociationPatch) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) AnyQuery(org.apache.syncope.common.rest.api.beans.AnyQuery) Test(org.junit.jupiter.api.Test)

Example 15 with ConnObjectTO

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

the class PullTaskITCase method issueSYNCOPE1062.

@Test
public void issueSYNCOPE1062() {
    GroupTO propagationGroup = null;
    PullTaskTO pullTask = null;
    UserTO user = null;
    GroupTO group = null;
    try {
        // 1. create group with resource for propagation
        propagationGroup = GroupITCase.getBasicSampleTO("SYNCOPE1062");
        propagationGroup.getResources().add(RESOURCE_NAME_DBPULL);
        propagationGroup = createGroup(propagationGroup).getEntity();
        // 2. create pull task for another resource, with user template assigning the group above
        pullTask = new PullTaskTO();
        pullTask.setDestinationRealm(SyncopeConstants.ROOT_REALM);
        pullTask.setName("SYNCOPE1062");
        pullTask.setActive(true);
        pullTask.setPerformCreate(true);
        pullTask.setPerformUpdate(true);
        pullTask.setPullMode(PullMode.FULL_RECONCILIATION);
        pullTask.setResource(RESOURCE_NAME_LDAP);
        UserTO template = new UserTO();
        template.getAuxClasses().add("minimal group");
        template.getMemberships().add(new MembershipTO.Builder().group(propagationGroup.getKey()).build());
        template.getPlainAttrs().add(attrTO("firstname", "'fixed'"));
        pullTask.getTemplates().put(AnyTypeKind.USER.name(), template);
        Response taskResponse = taskService.create(TaskType.PULL, pullTask);
        pullTask = getObject(taskResponse.getLocation(), TaskService.class, PullTaskTO.class);
        assertNotNull(pullTask);
        assertFalse(pullTask.getTemplates().isEmpty());
        // 3. exec the pull task
        ExecTO execution = execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
        assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
        // the user is successfully pulled...
        user = userService.read("pullFromLDAP");
        assertNotNull(user);
        assertEquals("pullFromLDAP@syncope.apache.org", user.getPlainAttr("email").get().getValues().get(0));
        group = groupService.read("testLDAPGroup");
        assertNotNull(group);
        ConnObjectTO connObject = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
        assertNotNull(connObject);
        assertEquals("pullFromLDAP@syncope.apache.org", connObject.getAttr("mail").get().getValues().get(0));
        AttrTO userDn = connObject.getAttr(Name.NAME).get();
        assertNotNull(userDn);
        assertEquals(1, userDn.getValues().size());
        assertNotNull(getLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, userDn.getValues().get(0)));
        // ...and propagated
        PagedResult<TaskTO> propagationTasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).resource(RESOURCE_NAME_DBPULL).anyTypeKind(AnyTypeKind.USER).entityKey(user.getKey()).build());
        assertEquals(1, propagationTasks.getSize());
        // 4. update the user on the external resource
        updateLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, userDn.getValues().get(0), Pair.of("mail", "pullFromLDAP2@syncope.apache.org"));
        connObject = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
        assertNotNull(connObject);
        assertEquals("pullFromLDAP2@syncope.apache.org", connObject.getAttr("mail").get().getValues().get(0));
        // 5. exec the pull task again
        execution = execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
        assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
        // the internal is updated...
        user = userService.read("pullFromLDAP");
        assertNotNull(user);
        assertEquals("pullFromLDAP2@syncope.apache.org", user.getPlainAttr("email").get().getValues().get(0));
        // ...and propagated
        propagationTasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).resource(RESOURCE_NAME_DBPULL).anyTypeKind(AnyTypeKind.USER).entityKey(user.getKey()).build());
        assertEquals(2, propagationTasks.getSize());
    } catch (Exception e) {
        LOG.error("Unexpected during issueSYNCOPE1062()", e);
        fail(e.getMessage());
    } finally {
        if (pullTask != null) {
            taskService.delete(TaskType.PULL, pullTask.getKey());
        }
        if (propagationGroup != null) {
            groupService.delete(propagationGroup.getKey());
        }
        if (group != null) {
            groupService.delete(group.getKey());
        }
        if (user != null) {
            userService.delete(user.getKey());
        }
    }
}
Also used : TaskTO(org.apache.syncope.common.lib.to.TaskTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) ExecTO(org.apache.syncope.common.lib.to.ExecTO) TaskService(org.apache.syncope.common.rest.api.service.TaskService) AttrTO(org.apache.syncope.common.lib.to.AttrTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) IOException(java.io.IOException) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Response(javax.ws.rs.core.Response) UserTO(org.apache.syncope.common.lib.to.UserTO) TaskQuery(org.apache.syncope.common.rest.api.beans.TaskQuery) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) Test(org.junit.jupiter.api.Test)

Aggregations

ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)31 Test (org.junit.jupiter.api.Test)24 UserTO (org.apache.syncope.common.lib.to.UserTO)20 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)11 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)9 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)9 GroupTO (org.apache.syncope.common.lib.to.GroupTO)9 ArrayList (java.util.ArrayList)8 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)8 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)7 Response (javax.ws.rs.core.Response)6 AttrTO (org.apache.syncope.common.lib.to.AttrTO)6 PasswordPatch (org.apache.syncope.common.lib.patch.PasswordPatch)5 List (java.util.List)4 Optional (java.util.Optional)4 ImplementationTO (org.apache.syncope.common.lib.to.ImplementationTO)4 PropagationStatus (org.apache.syncope.common.lib.to.PropagationStatus)4 IOException (java.io.IOException)3 Map (java.util.Map)3 Set (java.util.Set)3