Search in sources :

Example 31 with ExecTO

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

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

the class ReportITCase method execReport.

protected static String execReport(final String reportKey) {
    ReportTO reportTO = reportService.read(reportKey);
    assertNotNull(reportTO);
    assertNotNull(reportTO.getExecutions());
    int preExecSize = reportTO.getExecutions().size();
    ExecTO exec = reportService.execute(new ExecuteQuery.Builder().key(reportKey).build());
    assertNotNull(exec);
    int i = 0;
    int maxit = 50;
    // wait for completion (executions incremented)
    do {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
        reportTO = reportService.read(reportKey);
        assertNotNull(reportTO);
        assertNotNull(reportTO.getExecutions());
        i++;
    } while (preExecSize == reportTO.getExecutions().size() && i < maxit);
    if (i == maxit) {
        fail("Timeout when executing report " + reportKey);
    }
    exec = reportTO.getExecutions().get(reportTO.getExecutions().size() - 1);
    assertEquals(ReportExecStatus.SUCCESS.name(), exec.getStatus());
    return exec.getKey();
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO) ExecuteQuery(org.apache.syncope.common.rest.api.beans.ExecuteQuery) ReportTO(org.apache.syncope.common.lib.to.ReportTO)

Example 33 with ExecTO

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

the class AbstractTaskITCase method execProvisioningTasks.

protected void execProvisioningTasks(final TaskService taskService, final TaskType type, final Set<String> taskKeys, final int maxWaitSeconds, final boolean dryRun) throws Exception {
    ExecutorService service = Executors.newFixedThreadPool(taskKeys.size());
    List<Future<ExecTO>> futures = new ArrayList<>();
    for (String key : taskKeys) {
        futures.add(service.submit(new ThreadExec(taskService, type, key, maxWaitSeconds, dryRun)));
        // avoid flooding the test server
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
        }
    }
    for (Future<ExecTO> future : futures) {
        future.get(100, TimeUnit.SECONDS);
    }
    service.shutdownNow();
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future)

Example 34 with ExecTO

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

the class GroupITCase method bulkMembersAction.

@Test
public void bulkMembersAction() throws InterruptedException {
    // 1. create group without resources
    GroupTO groupTO = getBasicSampleTO("forProvision");
    groupTO = createGroup(groupTO).getEntity();
    // 2. create user with such group assigned
    UserTO userTO = UserITCase.getUniqueSampleTO("forProvision@syncope.apache.org");
    userTO.getMemberships().add(new MembershipTO.Builder().group(groupTO.getKey()).build());
    userTO = createUser(userTO).getEntity();
    // 3. modify the group by assiging the LDAP resource
    GroupPatch groupPatch = new GroupPatch();
    groupPatch.setKey(groupTO.getKey());
    groupPatch.getResources().add(new StringPatchItem.Builder().value(RESOURCE_NAME_LDAP).build());
    ProvisioningResult<GroupTO> groupUpdateResult = updateGroup(groupPatch);
    groupTO = groupUpdateResult.getEntity();
    PropagationStatus propStatus = groupUpdateResult.getPropagationStatuses().get(0);
    assertEquals(RESOURCE_NAME_LDAP, propStatus.getResource());
    assertEquals(PropagationTaskExecStatus.SUCCESS, propStatus.getStatus());
    // 4. verify that the user above is not found on LDAP
    try {
        resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), userTO.getKey());
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.NotFound, e.getType());
    }
    try {
        // 5. bulk provision group members
        ExecTO exec = groupService.bulkMembersAction(groupTO.getKey(), BulkMembersActionType.PROVISION);
        assertNotNull(exec.getRefKey());
        int i = 0;
        int maxit = 50;
        // wait for task exec completion (executions incremented)
        SchedTaskTO taskTO;
        do {
            Thread.sleep(1000);
            taskTO = taskService.read(TaskType.SCHEDULED, exec.getRefKey(), true);
            assertNotNull(taskTO);
            assertNotNull(taskTO.getExecutions());
            i++;
        } while (taskTO.getExecutions().isEmpty() && i < maxit);
        assertFalse(taskTO.getExecutions().isEmpty());
        assertEquals(TaskJob.Status.SUCCESS.name(), taskTO.getExecutions().get(0).getStatus());
        // 6. verify that the user above is now fond on LDAP
        ConnObjectTO userOnLdap = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), userTO.getKey());
        assertNotNull(userOnLdap);
    } finally {
        groupService.delete(groupTO.getKey());
        userService.delete(userTO.getKey());
    }
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) Test(org.junit.jupiter.api.Test)

Example 35 with ExecTO

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

the class TaskLogic method deleteExecution.

@PreAuthorize("hasRole('" + StandardEntitlement.TASK_DELETE + "')")
@Override
public ExecTO deleteExecution(final String execKey) {
    TaskExec taskExec = taskExecDAO.find(execKey);
    if (taskExec == null) {
        throw new NotFoundException("Task execution " + execKey);
    }
    ExecTO taskExecutionToDelete = binder.getExecTO(taskExec);
    taskExecDAO.delete(taskExec);
    return taskExecutionToDelete;
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO) TaskExec(org.apache.syncope.core.persistence.api.entity.task.TaskExec) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

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