Search in sources :

Example 16 with PullTaskTO

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

the class PullTaskITCase method reconcileFromLDAP.

@Test
public void reconcileFromLDAP() {
    // First of all, clear any potential conflict with existing user / group
    ldapCleanup();
    // 0. pull
    ExecTO execution = execProvisioningTask(taskService, TaskType.PULL, "1e419ca4-ea81-4493-a14f-28b90113686d", 50, false);
    // 1. verify execution status
    assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
    // 2. verify that pulled group is found
    PagedResult<GroupTO> matchingGroups = groupService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getGroupSearchConditionBuilder().is("name").equalTo("testLDAPGroup").query()).build());
    assertNotNull(matchingGroups);
    assertEquals(1, matchingGroups.getResult().size());
    // SYNCOPE-898
    PullTaskTO task = taskService.read(TaskType.PULL, "1e419ca4-ea81-4493-a14f-28b90113686d", false);
    assertEquals("/", task.getDestinationRealm());
    assertEquals("/", matchingGroups.getResult().get(0).getRealm());
    // 3. verify that pulled user is found
    PagedResult<UserTO> matchingUsers = userService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getUserSearchConditionBuilder().is("username").equalTo("pullFromLDAP").query()).build());
    assertNotNull(matchingUsers);
    assertEquals(1, matchingUsers.getResult().size());
    // SYNCOPE-898
    assertEquals("/odd", matchingUsers.getResult().get(0).getRealm());
    // Check for SYNCOPE-436
    assertEquals("pullFromLDAP", matchingUsers.getResult().get(0).getVirAttr("virtualReadOnly").get().getValues().get(0));
    // Check for SYNCOPE-270
    assertNotNull(matchingUsers.getResult().get(0).getPlainAttr("obscure"));
    // Check for SYNCOPE-123
    assertNotNull(matchingUsers.getResult().get(0).getPlainAttr("photo"));
    GroupTO groupTO = matchingGroups.getResult().iterator().next();
    assertNotNull(groupTO);
    assertEquals("testLDAPGroup", groupTO.getName());
    assertEquals("true", groupTO.getPlainAttr("show").get().getValues().get(0));
    assertEquals(matchingUsers.getResult().iterator().next().getKey(), groupTO.getUserOwner());
    assertNull(groupTO.getGroupOwner());
    // SYNCOPE-317
    execProvisioningTask(taskService, TaskType.PULL, "1e419ca4-ea81-4493-a14f-28b90113686d", 50, false);
    // 4. verify that LDAP group membership is propagated as Syncope membership
    int i = 0;
    int maxit = 50;
    PagedResult<UserTO> members;
    do {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
        members = userService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getUserSearchConditionBuilder().inGroups(groupTO.getKey()).query()).build());
        assertNotNull(members);
        i++;
    } while (members.getResult().isEmpty() && i < maxit);
    if (i == maxit) {
        fail("Timeout while checking for memberships of " + groupTO.getName());
    }
    assertEquals(1, members.getResult().size());
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO) UserTO(org.apache.syncope.common.lib.to.UserTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) AnyQuery(org.apache.syncope.common.rest.api.beans.AnyQuery) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 17 with PullTaskTO

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

the class PullTaskITCase method issueSYNCOPE307.

@Test
public void issueSYNCOPE307() {
    UserTO userTO = UserITCase.getUniqueSampleTO("s307@apache.org");
    userTO.setUsername("test0");
    userTO.getPlainAttr("firstname").get().getValues().clear();
    userTO.getPlainAttr("firstname").get().getValues().add("nome0");
    userTO.getAuxClasses().add("csv");
    userTO.getResources().clear();
    userTO.getResources().add(RESOURCE_NAME_WS2);
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    userTO = userService.read(userTO.getKey());
    assertTrue(userTO.getVirAttrs().isEmpty());
    // Update pull task
    PullTaskTO task = taskService.read(TaskType.PULL, "38abbf9e-a1a3-40a1-a15f-7d0ac02f47f1", true);
    assertNotNull(task);
    UserTO template = new UserTO();
    template.setPassword("'password123'");
    template.getResources().add(RESOURCE_NAME_DBVIRATTR);
    template.getVirAttrs().add(attrTO("virtualdata", "'virtualvalue'"));
    task.getTemplates().put(AnyTypeKind.USER.name(), template);
    taskService.update(TaskType.PULL, task);
    // exec task: one user from CSV will match the user created above and template will be applied
    execProvisioningTask(taskService, TaskType.PULL, task.getKey(), 50, false);
    // check that template was successfully applied...
    userTO = userService.read(userTO.getKey());
    assertEquals("virtualvalue", userTO.getVirAttr("virtualdata").get().getValues().get(0));
    // ...and that propagation to db succeeded
    JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
    String value = queryForObject(jdbcTemplate, 50, "SELECT USERNAME FROM testpull WHERE ID=?", String.class, userTO.getKey());
    assertEquals("virtualvalue", value);
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Test(org.junit.jupiter.api.Test)

Example 18 with PullTaskTO

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

the class ImplementationITCase method delete.

@Test
public void delete() {
    ImplementationTO implementationTO = new ImplementationTO();
    implementationTO.setKey(UUID.randomUUID().toString());
    implementationTO.setEngine(ImplementationEngine.JAVA);
    implementationTO.setType(ImplementationType.PULL_ACTIONS);
    implementationTO.setBody(TestPullActions.class.getName());
    implementationService.create(implementationTO);
    PullTaskTO pullTask = taskService.read(TaskType.PULL, AbstractTaskITCase.PULL_TASK_KEY, false);
    assertNotNull(pullTask);
    int before = pullTask.getActions().size();
    pullTask.getActions().add(implementationTO.getKey());
    taskService.update(TaskType.PULL, pullTask);
    pullTask = taskService.read(TaskType.PULL, AbstractTaskITCase.PULL_TASK_KEY, false);
    assertNotNull(pullTask);
    int after = pullTask.getActions().size();
    assertEquals(before + 1, after);
    // fails because the implementation is used
    try {
        implementationService.delete(implementationTO.getType(), implementationTO.getKey());
        fail("Unexpected");
    } catch (SyncopeClientException e) {
        assertEquals(e.getType(), ClientExceptionType.InUse);
    }
    pullTask.getActions().remove(implementationTO.getKey());
    taskService.update(TaskType.PULL, pullTask);
    implementationService.delete(implementationTO.getType(), implementationTO.getKey());
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) TestPullActions(org.apache.syncope.fit.core.reference.TestPullActions) Test(org.junit.jupiter.api.Test)

Example 19 with PullTaskTO

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

the class TaskDataBinderImpl method fill.

private void fill(final ProvisioningTask task, final ProvisioningTaskTO taskTO) {
    if (task instanceof PushTask && taskTO instanceof PushTaskTO) {
        PushTask pushTask = (PushTask) task;
        PushTaskTO pushTaskTO = (PushTaskTO) taskTO;
        Implementation jobDelegate = pushTaskTO.getJobDelegate() == null ? implementationDAO.find(ImplementationType.TASKJOB_DELEGATE).stream().filter(impl -> PushJobDelegate.class.getName().equals(impl.getBody())).findFirst().orElse(null) : implementationDAO.find(pushTaskTO.getJobDelegate());
        if (jobDelegate == null) {
            jobDelegate = entityFactory.newEntity(Implementation.class);
            jobDelegate.setKey(PushJobDelegate.class.getSimpleName());
            jobDelegate.setEngine(ImplementationEngine.JAVA);
            jobDelegate.setType(ImplementationType.TASKJOB_DELEGATE);
            jobDelegate.setBody(PushJobDelegate.class.getName());
            jobDelegate = implementationDAO.save(jobDelegate);
        }
        pushTask.setJobDelegate(jobDelegate);
        pushTask.setSourceRealm(realmDAO.findByFullPath(pushTaskTO.getSourceRealm()));
        pushTask.setMatchingRule(pushTaskTO.getMatchingRule() == null ? MatchingRule.LINK : pushTaskTO.getMatchingRule());
        pushTask.setUnmatchingRule(pushTaskTO.getUnmatchingRule() == null ? UnmatchingRule.ASSIGN : pushTaskTO.getUnmatchingRule());
        pushTaskTO.getFilters().forEach((type, fiql) -> {
            AnyType anyType = anyTypeDAO.find(type);
            if (anyType == null) {
                LOG.debug("Invalid AnyType {} specified, ignoring...", type);
            } else {
                PushTaskAnyFilter filter = pushTask.getFilter(anyType).orElse(null);
                if (filter == null) {
                    filter = entityFactory.newEntity(PushTaskAnyFilter.class);
                    filter.setAnyType(anyType);
                    filter.setPushTask(pushTask);
                    pushTask.add(filter);
                }
                filter.setFIQLCond(fiql);
            }
        });
        // remove all filters not contained in the TO
        pushTask.getFilters().removeIf(anyFilter -> !pushTaskTO.getFilters().containsKey(anyFilter.getAnyType().getKey()));
    } else if (task instanceof PullTask && taskTO instanceof PullTaskTO) {
        PullTask pullTask = (PullTask) task;
        PullTaskTO pullTaskTO = (PullTaskTO) taskTO;
        Implementation jobDelegate = pullTaskTO.getJobDelegate() == null ? implementationDAO.find(ImplementationType.TASKJOB_DELEGATE).stream().filter(impl -> PullJobDelegate.class.getName().equals(impl.getBody())).findFirst().orElse(null) : implementationDAO.find(pullTaskTO.getJobDelegate());
        if (jobDelegate == null) {
            jobDelegate = entityFactory.newEntity(Implementation.class);
            jobDelegate.setKey(PullJobDelegate.class.getSimpleName());
            jobDelegate.setEngine(ImplementationEngine.JAVA);
            jobDelegate.setType(ImplementationType.TASKJOB_DELEGATE);
            jobDelegate.setBody(PullJobDelegate.class.getName());
            jobDelegate = implementationDAO.save(jobDelegate);
        }
        pullTask.setJobDelegate(jobDelegate);
        pullTask.setPullMode(pullTaskTO.getPullMode());
        if (pullTaskTO.getReconFilterBuilder() == null) {
            pullTask.setReconFilterBuilder(null);
        } else {
            Implementation reconFilterBuilder = implementationDAO.find(pullTaskTO.getReconFilterBuilder());
            if (reconFilterBuilder == null) {
                LOG.debug("Invalid " + Implementation.class.getSimpleName() + " {}, ignoring...", pullTaskTO.getReconFilterBuilder());
            } else {
                pullTask.setReconFilterBuilder(reconFilterBuilder);
            }
        }
        pullTask.setDestinationRealm(realmDAO.findByFullPath(pullTaskTO.getDestinationRealm()));
        pullTask.setMatchingRule(pullTaskTO.getMatchingRule() == null ? MatchingRule.UPDATE : pullTaskTO.getMatchingRule());
        pullTask.setUnmatchingRule(pullTaskTO.getUnmatchingRule() == null ? UnmatchingRule.PROVISION : pullTaskTO.getUnmatchingRule());
        // validate JEXL expressions from templates and proceed if fine
        templateUtils.check(pullTaskTO.getTemplates(), ClientExceptionType.InvalidPullTask);
        pullTaskTO.getTemplates().forEach((type, template) -> {
            AnyType anyType = anyTypeDAO.find(type);
            if (anyType == null) {
                LOG.debug("Invalid AnyType {} specified, ignoring...", type);
            } else {
                AnyTemplatePullTask anyTemplate = pullTask.getTemplate(anyType).orElse(null);
                if (anyTemplate == null) {
                    anyTemplate = entityFactory.newEntity(AnyTemplatePullTask.class);
                    anyTemplate.setAnyType(anyType);
                    anyTemplate.setPullTask(pullTask);
                    pullTask.add(anyTemplate);
                }
                anyTemplate.set(template);
            }
        });
        // remove all templates not contained in the TO
        pullTask.getTemplates().removeIf(anyTemplate -> !pullTaskTO.getTemplates().containsKey(anyTemplate.getAnyType().getKey()));
        pullTask.setRemediation(pullTaskTO.isRemediation());
    }
    // 3. fill the remaining fields
    task.setPerformCreate(taskTO.isPerformCreate());
    task.setPerformUpdate(taskTO.isPerformUpdate());
    task.setPerformDelete(taskTO.isPerformDelete());
    task.setSyncStatus(taskTO.isSyncStatus());
    taskTO.getActions().forEach(action -> {
        Implementation implementation = implementationDAO.find(action);
        if (implementation == null) {
            LOG.debug("Invalid " + Implementation.class.getSimpleName() + " {}, ignoring...", action);
        } else {
            task.add(implementation);
        }
    });
    // remove all implementations not contained in the TO
    task.getActions().removeIf(implementation -> !taskTO.getActions().contains(implementation.getKey()));
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) TaskTO(org.apache.syncope.common.lib.to.TaskTO) LoggerFactory(org.slf4j.LoggerFactory) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Autowired(org.springframework.beans.factory.annotation.Autowired) NotificationTask(org.apache.syncope.core.persistence.api.entity.task.NotificationTask) Entity(org.apache.syncope.core.persistence.api.entity.Entity) StringUtils(org.apache.commons.lang3.StringUtils) PropagationTask(org.apache.syncope.core.persistence.api.entity.task.PropagationTask) Scheduler(org.quartz.Scheduler) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) ProvisioningTaskTO(org.apache.syncope.common.lib.to.ProvisioningTaskTO) TaskExecDAO(org.apache.syncope.core.persistence.api.dao.TaskExecDAO) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) ImplementationDAO(org.apache.syncope.core.persistence.api.dao.ImplementationDAO) NotificationTaskTO(org.apache.syncope.common.lib.to.NotificationTaskTO) PullJobDelegate(org.apache.syncope.core.provisioning.java.pushpull.PullJobDelegate) ExecTO(org.apache.syncope.common.lib.to.ExecTO) Task(org.apache.syncope.core.persistence.api.entity.task.Task) JobNamer(org.apache.syncope.core.provisioning.api.job.JobNamer) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) Collectors(java.util.stream.Collectors) UnmatchingRule(org.apache.syncope.common.lib.types.UnmatchingRule) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) ImplementationEngine(org.apache.syncope.common.lib.types.ImplementationEngine) EntityFactory(org.apache.syncope.core.persistence.api.entity.EntityFactory) AnyTemplatePullTask(org.apache.syncope.core.persistence.api.entity.task.AnyTemplatePullTask) TaskUtilsFactory(org.apache.syncope.core.persistence.api.entity.task.TaskUtilsFactory) ProvisioningTask(org.apache.syncope.core.persistence.api.entity.task.ProvisioningTask) TriggerKey(org.quartz.TriggerKey) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) TaskDataBinder(org.apache.syncope.core.provisioning.api.data.TaskDataBinder) BeanUtils(org.apache.syncope.core.spring.BeanUtils) PullTask(org.apache.syncope.core.persistence.api.entity.task.PullTask) SchedulerException(org.quartz.SchedulerException) Trigger(org.quartz.Trigger) ImplementationType(org.apache.syncope.common.lib.types.ImplementationType) TaskExec(org.apache.syncope.core.persistence.api.entity.task.TaskExec) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) SchedTask(org.apache.syncope.core.persistence.api.entity.task.SchedTask) RealmDAO(org.apache.syncope.core.persistence.api.dao.RealmDAO) TemplateUtils(org.apache.syncope.core.provisioning.java.utils.TemplateUtils) PushJobDelegate(org.apache.syncope.core.provisioning.java.pushpull.PushJobDelegate) PushTaskTO(org.apache.syncope.common.lib.to.PushTaskTO) Logger(org.slf4j.Logger) PushTaskAnyFilter(org.apache.syncope.core.persistence.api.entity.task.PushTaskAnyFilter) TaskUtils(org.apache.syncope.core.persistence.api.entity.task.TaskUtils) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) PushTask(org.apache.syncope.core.persistence.api.entity.task.PushTask) Component(org.springframework.stereotype.Component) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) JobType(org.apache.syncope.common.lib.types.JobType) MatchingRule(org.apache.syncope.common.lib.types.MatchingRule) TaskType(org.apache.syncope.common.lib.types.TaskType) PushTaskAnyFilter(org.apache.syncope.core.persistence.api.entity.task.PushTaskAnyFilter) PushJobDelegate(org.apache.syncope.core.provisioning.java.pushpull.PushJobDelegate) AnyTemplatePullTask(org.apache.syncope.core.persistence.api.entity.task.AnyTemplatePullTask) PullTask(org.apache.syncope.core.persistence.api.entity.task.PullTask) PushTaskTO(org.apache.syncope.common.lib.to.PushTaskTO) AnyTemplatePullTask(org.apache.syncope.core.persistence.api.entity.task.AnyTemplatePullTask) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) PushTask(org.apache.syncope.core.persistence.api.entity.task.PushTask) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation)

Aggregations

PullTaskTO (org.apache.syncope.common.lib.to.PullTaskTO)19 Test (org.junit.jupiter.api.Test)15 Response (javax.ws.rs.core.Response)12 ExecTO (org.apache.syncope.common.lib.to.ExecTO)12 UserTO (org.apache.syncope.common.lib.to.UserTO)12 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)11 ImplementationTO (org.apache.syncope.common.lib.to.ImplementationTO)8 TaskService (org.apache.syncope.common.rest.api.service.TaskService)8 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)6 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)6 GroupTO (org.apache.syncope.common.lib.to.GroupTO)5 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)5 TaskTO (org.apache.syncope.common.lib.to.TaskTO)5 TaskType (org.apache.syncope.common.lib.types.TaskType)5 Map (java.util.Map)4 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)4 ConnInstanceTO (org.apache.syncope.common.lib.to.ConnInstanceTO)4 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)4 ItemTO (org.apache.syncope.common.lib.to.ItemTO)4 ClientExceptionType (org.apache.syncope.common.lib.types.ClientExceptionType)4