Search in sources :

Example 16 with ExecTO

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

the class ReportLogic method deleteExecution.

@PreAuthorize("hasRole('" + StandardEntitlement.REPORT_DELETE + "')")
@Override
public ExecTO deleteExecution(final String executionKey) {
    ReportExec reportExec = reportExecDAO.find(executionKey);
    if (reportExec == null) {
        throw new NotFoundException("Report execution " + executionKey);
    }
    ExecTO reportExecToDelete = binder.getExecTO(reportExec);
    reportExecDAO.delete(reportExec);
    return reportExecToDelete;
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) ReportExec(org.apache.syncope.core.persistence.api.entity.ReportExec) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 17 with ExecTO

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

the class AbstractTaskITCase method execTask.

protected static ExecTO execTask(final TaskService taskService, final TaskType type, final String taskKey, final String initialStatus, final int maxWaitSeconds, final boolean dryRun) {
    TaskTO taskTO = taskService.read(type, taskKey, true);
    assertNotNull(taskTO);
    assertNotNull(taskTO.getExecutions());
    int preSyncSize = taskTO.getExecutions().size();
    ExecTO execution = taskService.execute(new ExecuteQuery.Builder().key(taskTO.getKey()).dryRun(dryRun).build());
    assertEquals(initialStatus, execution.getStatus());
    int i = 0;
    int maxit = maxWaitSeconds;
    // wait for completion (executions incremented)
    do {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
        taskTO = taskService.read(type, taskTO.getKey(), true);
        assertNotNull(taskTO);
        assertNotNull(taskTO.getExecutions());
        i++;
    } while (preSyncSize == taskTO.getExecutions().size() && i < maxit);
    if (i == maxit) {
        fail("Timeout when executing task " + taskKey);
    }
    return taskTO.getExecutions().get(taskTO.getExecutions().size() - 1);
}
Also used : TaskTO(org.apache.syncope.common.lib.to.TaskTO) NotificationTaskTO(org.apache.syncope.common.lib.to.NotificationTaskTO) ExecTO(org.apache.syncope.common.lib.to.ExecTO)

Example 18 with ExecTO

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

the class ReportDataBinderImpl method getExecTO.

@Override
public ExecTO getExecTO(final ReportExec execution) {
    ExecTO execTO = new ExecTO();
    execTO.setKey(execution.getKey());
    BeanUtils.copyProperties(execution, execTO, IGNORE_REPORT_EXECUTION_PROPERTIES);
    if (execution.getKey() != null) {
        execTO.setKey(execution.getKey());
    }
    execTO.setJobType(JobType.REPORT);
    execTO.setRefKey(execution.getReport().getKey());
    execTO.setRefDesc(buildRefDesc(execution.getReport()));
    return execTO;
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO)

Example 19 with ExecTO

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

the class MembershipITCase method pull.

@Test
public void pull() {
    // 0. create ad-hoc resource, with adequate mapping
    ResourceTO newResource = resourceService.read(RESOURCE_NAME_DBPULL);
    newResource.setKey(getUUIDString());
    ItemTO item = newResource.getProvision("USER").get().getMapping().getItems().stream().filter(object -> "firstname".equals(object.getIntAttrName())).findFirst().get();
    assertNotNull(item);
    assertEquals("ID", item.getExtAttrName());
    item.setIntAttrName("memberships[additional].aLong");
    item.setPurpose(MappingPurpose.BOTH);
    item = newResource.getProvision("USER").get().getMapping().getItems().stream().filter(object -> "fullname".equals(object.getIntAttrName())).findFirst().get();
    item.setPurpose(MappingPurpose.PULL);
    PullTaskTO newTask = null;
    try {
        newResource = createResource(newResource);
        assertNotNull(newResource);
        // 1. create user with new resource assigned
        UserTO user = UserITCase.getUniqueSampleTO("memb@apache.org");
        user.setRealm("/even/two");
        user.getPlainAttrs().remove(user.getPlainAttr("ctype").get());
        user.getResources().clear();
        user.getResources().add(newResource.getKey());
        MembershipTO membership = new MembershipTO.Builder().group("034740a9-fa10-453b-af37-dc7897e98fb1").build();
        membership.getPlainAttrs().add(new AttrTO.Builder().schema("aLong").value("5432").build());
        user.getMemberships().add(membership);
        user = createUser(user).getEntity();
        assertNotNull(user);
        // 2. verify that user was found on resource
        JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
        String idOnResource = queryForObject(jdbcTemplate, 50, "SELECT id FROM testpull WHERE id=?", String.class, "5432");
        assertEquals("5432", idOnResource);
        // 3. unlink user from resource, then remove it
        DeassociationPatch patch = new DeassociationPatch();
        patch.setKey(user.getKey());
        patch.setAction(ResourceDeassociationAction.UNLINK);
        patch.getResources().add(newResource.getKey());
        assertNotNull(userService.deassociate(patch).readEntity(BulkActionResult.class));
        userService.delete(user.getKey());
        // 4. create pull task and execute
        newTask = taskService.read(TaskType.PULL, "7c2242f4-14af-4ab5-af31-cdae23783655", true);
        newTask.setResource(newResource.getKey());
        newTask.setDestinationRealm("/even/two");
        Response response = taskService.create(TaskType.PULL, newTask);
        newTask = getObject(response.getLocation(), TaskService.class, PullTaskTO.class);
        assertNotNull(newTask);
        ExecTO execution = AbstractTaskITCase.execProvisioningTask(taskService, TaskType.PULL, newTask.getKey(), 50, false);
        assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
        // 5. verify that pulled user has
        PagedResult<UserTO> users = userService.search(new AnyQuery.Builder().realm("/").fiql(SyncopeClient.getUserSearchConditionBuilder().is("username").equalTo(user.getUsername()).query()).build());
        assertEquals(1, users.getTotalCount());
        assertEquals(1, users.getResult().get(0).getMemberships().size());
        assertEquals("5432", users.getResult().get(0).getMemberships().get(0).getPlainAttr("aLong").get().getValues().get(0));
    } catch (Exception e) {
        LOG.error("Unexpected error", e);
        fail(e.getMessage());
    } finally {
        if (newTask != null && !"83f7e85d-9774-43fe-adba-ccd856312994".equals(newTask.getKey())) {
            taskService.delete(TaskType.PULL, newTask.getKey());
        }
        resourceService.delete(newResource.getKey());
    }
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) TaskService(org.apache.syncope.common.rest.api.service.TaskService) PropagationTaskExecStatus(org.apache.syncope.common.lib.types.PropagationTaskExecStatus) AttrTO(org.apache.syncope.common.lib.to.AttrTO) Autowired(org.springframework.beans.factory.annotation.Autowired) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) ResourceDeassociationAction(org.apache.syncope.common.lib.types.ResourceDeassociationAction) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) SpringJUnitConfig(org.springframework.test.context.junit.jupiter.SpringJUnitConfig) MembershipPatch(org.apache.syncope.common.lib.patch.MembershipPatch) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) DataSource(javax.sql.DataSource) ItemTO(org.apache.syncope.common.lib.to.ItemTO) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AbstractITCase(org.apache.syncope.fit.AbstractITCase) AnyQuery(org.apache.syncope.common.rest.api.beans.AnyQuery) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) PagedResult(org.apache.syncope.common.lib.to.PagedResult) ExecTO(org.apache.syncope.common.lib.to.ExecTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) TypeExtensionTO(org.apache.syncope.common.lib.to.TypeExtensionTO) Response(javax.ws.rs.core.Response) MappingPurpose(org.apache.syncope.common.lib.types.MappingPurpose) DeassociationPatch(org.apache.syncope.common.lib.patch.DeassociationPatch) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) UserTO(org.apache.syncope.common.lib.to.UserTO) TaskType(org.apache.syncope.common.lib.types.TaskType) ExecTO(org.apache.syncope.common.lib.to.ExecTO) TaskService(org.apache.syncope.common.rest.api.service.TaskService) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) ItemTO(org.apache.syncope.common.lib.to.ItemTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Response(javax.ws.rs.core.Response) DeassociationPatch(org.apache.syncope.common.lib.patch.DeassociationPatch) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult) Test(org.junit.jupiter.api.Test)

Example 20 with ExecTO

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

the class MultitenancyITCase method createResourceAndPull.

@Test
public void createResourceAndPull() {
    // read connector
    ConnInstanceTO conn = adminClient.getService(ConnectorService.class).read("b7ea96c3-c633-488b-98a0-b52ac35850f7", Locale.ENGLISH.getLanguage());
    assertNotNull(conn);
    assertEquals("LDAP", conn.getDisplayName());
    // prepare resource
    ResourceTO resource = new ResourceTO();
    resource.setKey("new-ldap-resource");
    resource.setConnector(conn.getKey());
    try {
        ProvisionTO provisionTO = new ProvisionTO();
        provisionTO.setAnyType(AnyTypeKind.USER.name());
        provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME);
        resource.getProvisions().add(provisionTO);
        MappingTO mapping = new MappingTO();
        mapping.setConnObjectLink("'uid=' + username + ',ou=people,o=isp'");
        provisionTO.setMapping(mapping);
        ItemTO item = new ItemTO();
        item.setIntAttrName("username");
        item.setExtAttrName("cn");
        item.setPurpose(MappingPurpose.BOTH);
        mapping.setConnObjectKeyItem(item);
        item = new ItemTO();
        item.setPassword(true);
        item.setIntAttrName("password");
        item.setExtAttrName("userPassword");
        item.setPurpose(MappingPurpose.BOTH);
        item.setMandatoryCondition("true");
        mapping.add(item);
        item = new ItemTO();
        item.setIntAttrName("key");
        item.setPurpose(MappingPurpose.BOTH);
        item.setExtAttrName("sn");
        item.setMandatoryCondition("true");
        mapping.add(item);
        item = new ItemTO();
        item.setIntAttrName("email");
        item.setPurpose(MappingPurpose.BOTH);
        item.setExtAttrName("mail");
        mapping.add(item);
        // create resource
        Response response = adminClient.getService(ResourceService.class).create(resource);
        assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
        resource = adminClient.getService(ResourceService.class).read(resource.getKey());
        assertNotNull(resource);
        // create pull task
        PullTaskTO task = new PullTaskTO();
        task.setName("LDAP Pull Task");
        task.setActive(true);
        task.setDestinationRealm(SyncopeConstants.ROOT_REALM);
        task.setResource(resource.getKey());
        task.setPullMode(PullMode.FULL_RECONCILIATION);
        task.setPerformCreate(true);
        response = adminClient.getService(TaskService.class).create(TaskType.PULL, task);
        assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
        task = adminClient.getService(TaskService.class).read(TaskType.PULL, StringUtils.substringAfterLast(response.getLocation().toASCIIString(), "/"), true);
        assertNotNull(resource);
        // pull
        ExecTO execution = AbstractTaskITCase.execProvisioningTask(adminClient.getService(TaskService.class), TaskType.PULL, task.getKey(), 50, false);
        // verify execution status
        String status = execution.getStatus();
        assertNotNull(status);
        assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(status));
        // verify that pulled user is found
        PagedResult<UserTO> matchingUsers = adminClient.getService(UserService.class).search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getUserSearchConditionBuilder().is("username").equalTo("pullFromLDAP").query()).build());
        assertNotNull(matchingUsers);
        assertEquals(1, matchingUsers.getResult().size());
    } finally {
        adminClient.getService(ResourceService.class).delete(resource.getKey());
    }
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO) UserService(org.apache.syncope.common.rest.api.service.UserService) TaskService(org.apache.syncope.common.rest.api.service.TaskService) ResourceService(org.apache.syncope.common.rest.api.service.ResourceService) ItemTO(org.apache.syncope.common.lib.to.ItemTO) ConnectorService(org.apache.syncope.common.rest.api.service.ConnectorService) Response(javax.ws.rs.core.Response) MappingTO(org.apache.syncope.common.lib.to.MappingTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) UserTO(org.apache.syncope.common.lib.to.UserTO) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) Test(org.junit.jupiter.api.Test)

Aggregations

ExecTO (org.apache.syncope.common.lib.to.ExecTO)37 Test (org.junit.jupiter.api.Test)22 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)13 UserTO (org.apache.syncope.common.lib.to.UserTO)13 Response (javax.ws.rs.core.Response)11 PullTaskTO (org.apache.syncope.common.lib.to.PullTaskTO)10 Date (java.util.Date)9 TaskService (org.apache.syncope.common.rest.api.service.TaskService)8 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 Map (java.util.Map)6 GroupTO (org.apache.syncope.common.lib.to.GroupTO)6 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)6 IOException (java.io.IOException)5 TaskTO (org.apache.syncope.common.lib.to.TaskTO)5 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)5 AttrTO (org.apache.syncope.common.lib.to.AttrTO)4 ConnInstanceTO (org.apache.syncope.common.lib.to.ConnInstanceTO)4 ImplementationTO (org.apache.syncope.common.lib.to.ImplementationTO)4 ItemTO (org.apache.syncope.common.lib.to.ItemTO)4