Search in sources :

Example 1 with PullTask

use of org.apache.syncope.core.persistence.api.entity.task.PullTask in project syncope by apache.

the class PullJobDelegate method doExecuteProvisioning.

@Override
protected String doExecuteProvisioning(final PullTask pullTask, final Connector connector, final boolean dryRun) throws JobExecutionException {
    LOG.debug("Executing pull on {}", pullTask.getResource());
    List<PullActions> actions = new ArrayList<>();
    pullTask.getActions().forEach(impl -> {
        try {
            actions.add(ImplementationManager.build(impl));
        } catch (Exception e) {
            LOG.warn("While building {}", impl, e);
        }
    });
    profile = new ProvisioningProfile<>(connector, pullTask);
    profile.getActions().addAll(actions);
    profile.setDryRun(dryRun);
    profile.setResAct(pullTask.getResource().getPullPolicy() == null ? ConflictResolutionAction.IGNORE : pullTask.getResource().getPullPolicy().getConflictResolutionAction());
    latestSyncTokens.clear();
    if (!profile.isDryRun()) {
        for (PullActions action : actions) {
            action.beforeAll(profile);
        }
    }
    status.set("Initialization completed");
    // First realms...
    if (pullTask.getResource().getOrgUnit() != null) {
        status.set("Pulling " + pullTask.getResource().getOrgUnit().getObjectClass().getObjectClassValue());
        OrgUnit orgUnit = pullTask.getResource().getOrgUnit();
        OperationOptions options = MappingUtils.buildOperationOptions(MappingUtils.getPullItems(orgUnit.getItems()).iterator());
        rhandler = buildRealmHandler();
        try {
            switch(pullTask.getPullMode()) {
                case INCREMENTAL:
                    if (!dryRun) {
                        latestSyncTokens.put(orgUnit.getObjectClass(), orgUnit.getSyncToken());
                    }
                    connector.sync(orgUnit.getObjectClass(), orgUnit.getSyncToken(), rhandler, options);
                    if (!dryRun) {
                        orgUnit.setSyncToken(latestSyncTokens.get(orgUnit.getObjectClass()));
                        resourceDAO.save(orgUnit.getResource());
                    }
                    break;
                case FILTERED_RECONCILIATION:
                    ReconFilterBuilder filterBuilder = ImplementationManager.build(pullTask.getReconFilterBuilder());
                    connector.filteredReconciliation(orgUnit.getObjectClass(), filterBuilder, rhandler, options);
                    break;
                case FULL_RECONCILIATION:
                default:
                    connector.fullReconciliation(orgUnit.getObjectClass(), rhandler, options);
                    break;
            }
        } catch (Throwable t) {
            throw new JobExecutionException("While pulling from connector", t);
        }
    }
    // ...then provisions for any types
    ahandler = buildAnyObjectHandler();
    uhandler = buildUserHandler();
    ghandler = buildGroupHandler();
    for (Provision provision : pullTask.getResource().getProvisions()) {
        if (provision.getMapping() != null) {
            status.set("Pulling " + provision.getObjectClass().getObjectClassValue());
            SyncopePullResultHandler handler;
            switch(provision.getAnyType().getKind()) {
                case USER:
                    handler = uhandler;
                    break;
                case GROUP:
                    handler = ghandler;
                    break;
                case ANY_OBJECT:
                default:
                    handler = ahandler;
            }
            try {
                Set<MappingItem> linkingMappingItems = virSchemaDAO.findByProvision(provision).stream().map(schema -> schema.asLinkingMappingItem()).collect(Collectors.toSet());
                Iterator<MappingItem> mapItems = new IteratorChain<>(provision.getMapping().getItems().iterator(), linkingMappingItems.iterator());
                OperationOptions options = MappingUtils.buildOperationOptions(mapItems);
                switch(pullTask.getPullMode()) {
                    case INCREMENTAL:
                        if (!dryRun) {
                            latestSyncTokens.put(provision.getObjectClass(), provision.getSyncToken());
                        }
                        connector.sync(provision.getObjectClass(), provision.getSyncToken(), handler, options);
                        if (!dryRun) {
                            provision.setSyncToken(latestSyncTokens.get(provision.getObjectClass()));
                            resourceDAO.save(provision.getResource());
                        }
                        break;
                    case FILTERED_RECONCILIATION:
                        ReconFilterBuilder filterBuilder = ImplementationManager.build(pullTask.getReconFilterBuilder());
                        connector.filteredReconciliation(provision.getObjectClass(), filterBuilder, handler, options);
                        break;
                    case FULL_RECONCILIATION:
                    default:
                        connector.fullReconciliation(provision.getObjectClass(), handler, options);
                        break;
                }
            } catch (Throwable t) {
                throw new JobExecutionException("While pulling from connector", t);
            }
        }
    }
    try {
        setGroupOwners(ghandler);
    } catch (Exception e) {
        LOG.error("While setting group owners", e);
    }
    if (!profile.isDryRun()) {
        for (PullActions action : actions) {
            action.afterAll(profile);
        }
    }
    status.set("Pull done");
    String result = createReport(profile.getResults(), pullTask.getResource(), dryRun);
    LOG.debug("Pull result: {}", result);
    return result;
}
Also used : OrgUnit(org.apache.syncope.core.persistence.api.entity.resource.OrgUnit) OperationOptions(org.identityconnectors.framework.common.objects.OperationOptions) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) ReconFilterBuilder(org.apache.syncope.core.provisioning.api.pushpull.ReconFilterBuilder) ProvisioningProfile(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningProfile) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) SyncopePullExecutor(org.apache.syncope.core.provisioning.api.pushpull.SyncopePullExecutor) UserPullResultHandler(org.apache.syncope.core.provisioning.api.pushpull.UserPullResultHandler) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) PullTask(org.apache.syncope.core.persistence.api.entity.task.PullTask) GroupPullResultHandler(org.apache.syncope.core.provisioning.api.pushpull.GroupPullResultHandler) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Map(java.util.Map) OperationOptions(org.identityconnectors.framework.common.objects.OperationOptions) OrgUnit(org.apache.syncope.core.persistence.api.entity.resource.OrgUnit) SyncopePullResultHandler(org.apache.syncope.core.provisioning.api.pushpull.SyncopePullResultHandler) SyncToken(org.identityconnectors.framework.common.objects.SyncToken) Iterator(java.util.Iterator) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) ConflictResolutionAction(org.apache.syncope.common.lib.types.ConflictResolutionAction) Set(java.util.Set) IteratorChain(org.apache.syncope.common.lib.collections.IteratorChain) Collectors(java.util.stream.Collectors) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) Name(org.identityconnectors.framework.common.objects.Name) ImplementationManager(org.apache.syncope.core.spring.ImplementationManager) JobExecutionException(org.quartz.JobExecutionException) MappingUtils(org.apache.syncope.core.provisioning.java.utils.MappingUtils) Connector(org.apache.syncope.core.provisioning.api.Connector) List(java.util.List) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) AnyObjectPullResultHandler(org.apache.syncope.core.provisioning.api.pushpull.AnyObjectPullResultHandler) PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) RealmPullResultHandler(org.apache.syncope.core.provisioning.api.pushpull.RealmPullResultHandler) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) VirSchemaDAO(org.apache.syncope.core.persistence.api.dao.VirSchemaDAO) Group(org.apache.syncope.core.persistence.api.entity.group.Group) Optional(java.util.Optional) ApplicationContextProvider(org.apache.syncope.core.spring.ApplicationContextProvider) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) SyncopePullResultHandler(org.apache.syncope.core.provisioning.api.pushpull.SyncopePullResultHandler) PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) ArrayList(java.util.ArrayList) IteratorChain(org.apache.syncope.common.lib.collections.IteratorChain) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) JobExecutionException(org.quartz.JobExecutionException) JobExecutionException(org.quartz.JobExecutionException) ReconFilterBuilder(org.apache.syncope.core.provisioning.api.pushpull.ReconFilterBuilder)

Example 2 with PullTask

use of org.apache.syncope.core.persistence.api.entity.task.PullTask in project syncope by apache.

the class TaskDataBinderImpl method getTaskTO.

@Override
public <T extends TaskTO> T getTaskTO(final Task task, final TaskUtils taskUtils, final boolean details) {
    T taskTO = taskUtils.newTaskTO();
    BeanUtils.copyProperties(task, taskTO, IGNORE_TASK_PROPERTIES);
    TaskExec latestExec = taskExecDAO.findLatestStarted(task);
    if (latestExec == null) {
        taskTO.setLatestExecStatus(StringUtils.EMPTY);
    } else {
        taskTO.setLatestExecStatus(latestExec.getStatus());
        taskTO.setStart(latestExec.getStart());
        taskTO.setEnd(latestExec.getEnd());
    }
    if (details) {
        task.getExecs().stream().filter(execution -> execution != null).forEachOrdered(execution -> taskTO.getExecutions().add(getExecTO(execution)));
    }
    switch(taskUtils.getType()) {
        case PROPAGATION:
            PropagationTask propagationTask = (PropagationTask) task;
            PropagationTaskTO propagationTaskTO = (PropagationTaskTO) taskTO;
            propagationTaskTO.setAnyTypeKind(propagationTask.getAnyTypeKind());
            propagationTaskTO.setEntityKey(propagationTask.getEntityKey());
            propagationTaskTO.setResource(propagationTask.getResource().getKey());
            propagationTaskTO.setAttributes(propagationTask.getSerializedAttributes());
            break;
        case SCHEDULED:
            SchedTask schedTask = (SchedTask) task;
            SchedTaskTO schedTaskTO = (SchedTaskTO) taskTO;
            setExecTime(schedTaskTO, task);
            if (schedTask.getJobDelegate() != null) {
                schedTaskTO.setJobDelegate(schedTask.getJobDelegate().getKey());
            }
            break;
        case PULL:
            PullTask pullTask = (PullTask) task;
            PullTaskTO pullTaskTO = (PullTaskTO) taskTO;
            setExecTime(pullTaskTO, task);
            pullTaskTO.setDestinationRealm(pullTask.getDestinatioRealm().getFullPath());
            pullTaskTO.setResource(pullTask.getResource().getKey());
            pullTaskTO.setMatchingRule(pullTask.getMatchingRule() == null ? MatchingRule.UPDATE : pullTask.getMatchingRule());
            pullTaskTO.setUnmatchingRule(pullTask.getUnmatchingRule() == null ? UnmatchingRule.PROVISION : pullTask.getUnmatchingRule());
            if (pullTask.getReconFilterBuilder() != null) {
                pullTaskTO.setReconFilterBuilder(pullTask.getReconFilterBuilder().getKey());
            }
            pullTaskTO.getActions().addAll(pullTask.getActions().stream().map(Entity::getKey).collect(Collectors.toList()));
            pullTask.getTemplates().forEach(template -> {
                pullTaskTO.getTemplates().put(template.getAnyType().getKey(), template.get());
            });
            pullTaskTO.setRemediation(pullTask.isRemediation());
            break;
        case PUSH:
            PushTask pushTask = (PushTask) task;
            PushTaskTO pushTaskTO = (PushTaskTO) taskTO;
            setExecTime(pushTaskTO, task);
            pushTaskTO.setSourceRealm(pushTask.getSourceRealm().getFullPath());
            pushTaskTO.setResource(pushTask.getResource().getKey());
            pushTaskTO.setMatchingRule(pushTask.getMatchingRule() == null ? MatchingRule.LINK : pushTask.getMatchingRule());
            pushTaskTO.setUnmatchingRule(pushTask.getUnmatchingRule() == null ? UnmatchingRule.ASSIGN : pushTask.getUnmatchingRule());
            pushTaskTO.getActions().addAll(pushTask.getActions().stream().map(Entity::getKey).collect(Collectors.toList()));
            pushTask.getFilters().forEach(filter -> {
                pushTaskTO.getFilters().put(filter.getAnyType().getKey(), filter.getFIQLCond());
            });
            break;
        case NOTIFICATION:
            NotificationTask notificationTask = (NotificationTask) task;
            NotificationTaskTO notificationTaskTO = (NotificationTaskTO) taskTO;
            notificationTaskTO.setNotification(notificationTask.getNotification().getKey());
            notificationTaskTO.setAnyTypeKind(notificationTask.getAnyTypeKind());
            notificationTaskTO.setEntityKey(notificationTask.getEntityKey());
            if (notificationTask.isExecuted() && StringUtils.isBlank(taskTO.getLatestExecStatus())) {
                taskTO.setLatestExecStatus("[EXECUTED]");
            }
            break;
        default:
    }
    return taskTO;
}
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) Entity(org.apache.syncope.core.persistence.api.entity.Entity) NotificationTask(org.apache.syncope.core.persistence.api.entity.task.NotificationTask) PropagationTask(org.apache.syncope.core.persistence.api.entity.task.PropagationTask) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) PushTask(org.apache.syncope.core.persistence.api.entity.task.PushTask) SchedTask(org.apache.syncope.core.persistence.api.entity.task.SchedTask) SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) AnyTemplatePullTask(org.apache.syncope.core.persistence.api.entity.task.AnyTemplatePullTask) PullTask(org.apache.syncope.core.persistence.api.entity.task.PullTask) TaskExec(org.apache.syncope.core.persistence.api.entity.task.TaskExec) PushTaskTO(org.apache.syncope.common.lib.to.PushTaskTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) NotificationTaskTO(org.apache.syncope.common.lib.to.NotificationTaskTO)

Example 3 with PullTask

use of org.apache.syncope.core.persistence.api.entity.task.PullTask in project syncope by apache.

the class TaskTest method issueSYNCOPE144.

@Test
public void issueSYNCOPE144() {
    ExternalResource resource = resourceDAO.find("ws-target-resource-1");
    assertNotNull(resource);
    Implementation pullActions = entityFactory.newEntity(Implementation.class);
    pullActions.setKey("syncope144");
    pullActions.setEngine(ImplementationEngine.JAVA);
    pullActions.setType(ImplementationType.PULL_ACTIONS);
    pullActions.setBody(PullActions.class.getName());
    pullActions = implementationDAO.save(pullActions);
    PullTask task = entityFactory.newEntity(PullTask.class);
    task.setResource(resource);
    task.setName("issueSYNCOPE144");
    task.setDescription("issueSYNCOPE144 Description");
    task.setActive(true);
    task.setPullMode(PullMode.FULL_RECONCILIATION);
    task.add(pullActions);
    task.setMatchingRule(MatchingRule.UPDATE);
    task.setUnmatchingRule(UnmatchingRule.PROVISION);
    task = taskDAO.save(task);
    assertNotNull(task);
    PullTask actual = taskDAO.find(task.getKey());
    assertEquals(task, actual);
    assertEquals("issueSYNCOPE144", actual.getName());
    assertEquals("issueSYNCOPE144 Description", actual.getDescription());
    actual.setName("issueSYNCOPE144_2");
    actual.setDescription("issueSYNCOPE144 Description_2");
    actual = taskDAO.save(actual);
    assertNotNull(actual);
    assertEquals("issueSYNCOPE144_2", actual.getName());
    assertEquals("issueSYNCOPE144 Description_2", actual.getDescription());
}
Also used : PullTask(org.apache.syncope.core.persistence.api.entity.task.PullTask) AnyTemplatePullTask(org.apache.syncope.core.persistence.api.entity.task.AnyTemplatePullTask) PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 4 with PullTask

use of org.apache.syncope.core.persistence.api.entity.task.PullTask in project syncope by apache.

the class ConnObjectUtils method getAnyTO.

/**
 * Build a UserTO / GroupTO / AnyObjectTO out of connector object attributes and schema mapping.
 *
 * @param obj connector object
 * @param pullTask pull task
 * @param provision provision information
 * @param anyUtils utils
 * @param <T> any object
 * @return UserTO for the user to be created
 */
@Transactional(readOnly = true)
public <T extends AnyTO> T getAnyTO(final ConnectorObject obj, final PullTask pullTask, final Provision provision, final AnyUtils anyUtils) {
    T anyTO = getAnyTOFromConnObject(obj, pullTask, provision, anyUtils);
    // (for users) if password was not set above, generate if resource is configured for that
    if (anyTO instanceof UserTO && StringUtils.isBlank(((UserTO) anyTO).getPassword()) && provision.getResource().isRandomPwdIfNotProvided()) {
        UserTO userTO = (UserTO) anyTO;
        List<PasswordPolicy> passwordPolicies = new ArrayList<>();
        Realm realm = realmDAO.findByFullPath(userTO.getRealm());
        if (realm != null) {
            realmDAO.findAncestors(realm).stream().filter(ancestor -> ancestor.getPasswordPolicy() != null).forEach(ancestor -> {
                passwordPolicies.add(ancestor.getPasswordPolicy());
            });
        }
        userTO.getResources().stream().map(resource -> resourceDAO.find(resource)).filter(resource -> resource != null && resource.getPasswordPolicy() != null).forEach(resource -> {
            passwordPolicies.add(resource.getPasswordPolicy());
        });
        String password;
        try {
            password = passwordGenerator.generate(passwordPolicies);
        } catch (InvalidPasswordRuleConf e) {
            LOG.error("Could not generate policy-compliant random password for {}", userTO, e);
            password = SecureRandomUtils.generateRandomPassword(16);
        }
        userTO.setPassword(password);
    }
    return anyTO;
}
Also used : AttrTO(org.apache.syncope.common.lib.to.AttrTO) Realm(org.apache.syncope.core.persistence.api.entity.Realm) RealmTO(org.apache.syncope.common.lib.to.RealmTO) LoggerFactory(org.slf4j.LoggerFactory) AnyTO(org.apache.syncope.common.lib.to.AnyTO) Autowired(org.springframework.beans.factory.annotation.Autowired) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) PasswordGenerator(org.apache.syncope.core.spring.security.PasswordGenerator) InvalidPasswordRuleConf(org.apache.syncope.core.provisioning.api.utils.policy.InvalidPasswordRuleConf) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) GuardedString(org.identityconnectors.common.security.GuardedString) Attribute(org.identityconnectors.framework.common.objects.Attribute) PullTask(org.apache.syncope.core.persistence.api.entity.task.PullTask) Base64(org.identityconnectors.common.Base64) MappingManager(org.apache.syncope.core.provisioning.api.MappingManager) SecurityUtil(org.identityconnectors.common.security.SecurityUtil) RealmDAO(org.apache.syncope.core.persistence.api.dao.RealmDAO) OrgUnit(org.apache.syncope.core.persistence.api.entity.resource.OrgUnit) AnyPatch(org.apache.syncope.common.lib.patch.AnyPatch) Encryptor(org.apache.syncope.core.spring.security.Encryptor) Logger(org.slf4j.Logger) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) GuardedByteArray(org.identityconnectors.common.security.GuardedByteArray) Set(java.util.Set) User(org.apache.syncope.core.persistence.api.entity.user.User) GroupTO(org.apache.syncope.common.lib.to.GroupTO) SecureRandomUtils(org.apache.syncope.core.spring.security.SecureRandomUtils) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) List(java.util.List) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) Component(org.springframework.stereotype.Component) UserTO(org.apache.syncope.common.lib.to.UserTO) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) AnyOperations(org.apache.syncope.common.lib.AnyOperations) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) Transactional(org.springframework.transaction.annotation.Transactional) InvalidPasswordRuleConf(org.apache.syncope.core.provisioning.api.utils.policy.InvalidPasswordRuleConf) UserTO(org.apache.syncope.common.lib.to.UserTO) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) ArrayList(java.util.ArrayList) GuardedString(org.identityconnectors.common.security.GuardedString) Realm(org.apache.syncope.core.persistence.api.entity.Realm) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with PullTask

use of org.apache.syncope.core.persistence.api.entity.task.PullTask in project syncope by apache.

the class JobManagerImpl method register.

@Override
public Map<String, Object> register(final SchedTask task, final Date startAt, final long interruptMaxRetries) throws SchedulerException {
    TaskJob job = createSpringBean(TaskJob.class);
    job.setTaskKey(task.getKey());
    Implementation jobDelegate = task.getJobDelegate() == null ? task instanceof PullTask ? implementationDAO.find(ImplementationType.TASKJOB_DELEGATE).stream().filter(impl -> PullJobDelegate.class.getName().equals(impl.getBody())).findFirst().orElse(null) : task instanceof PushTask ? implementationDAO.find(ImplementationType.TASKJOB_DELEGATE).stream().filter(impl -> PushJobDelegate.class.getName().equals(impl.getBody())).findFirst().orElse(null) : null : task.getJobDelegate();
    if (jobDelegate == null) {
        throw new IllegalArgumentException("Task " + task + " does not provide any " + SchedTaskJobDelegate.class.getSimpleName());
    }
    Map<String, Object> jobMap = new HashMap<>();
    jobMap.put(JobManager.DOMAIN_KEY, AuthContextUtils.getDomain());
    jobMap.put(TaskJob.DELEGATE_IMPLEMENTATION, jobDelegate.getKey());
    registerJob(JobNamer.getJobKey(task).getName(), job, task.getCronExpression(), startAt, jobMap);
    return jobMap;
}
Also used : Connection(java.sql.Connection) SyncopeLoader(org.apache.syncope.core.persistence.api.SyncopeLoader) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) StringUtils(org.apache.commons.lang3.StringUtils) CPlainAttr(org.apache.syncope.core.persistence.api.entity.conf.CPlainAttr) JobBuilder(org.quartz.JobBuilder) Scheduler(org.quartz.Scheduler) Pair(org.apache.commons.lang3.tuple.Pair) ResultSet(java.sql.ResultSet) Map(java.util.Map) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) ImplementationDAO(org.apache.syncope.core.persistence.api.dao.ImplementationDAO) PullJobDelegate(org.apache.syncope.core.provisioning.java.pushpull.PullJobDelegate) Constants(org.quartz.impl.jdbcjobstore.Constants) Task(org.apache.syncope.core.persistence.api.entity.task.Task) SchedTaskJobDelegate(org.apache.syncope.core.provisioning.api.job.SchedTaskJobDelegate) JobNamer(org.apache.syncope.core.provisioning.api.job.JobNamer) Set(java.util.Set) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) PreparedStatement(java.sql.PreparedStatement) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) JobDataMap(org.quartz.JobDataMap) Optional(java.util.Optional) TriggerKey(org.quartz.TriggerKey) ConfDAO(org.apache.syncope.core.persistence.api.dao.ConfDAO) DataSourceUtils(org.springframework.jdbc.datasource.DataSourceUtils) IOUtil(org.identityconnectors.common.IOUtil) HashMap(java.util.HashMap) Job(org.quartz.Job) JobKey(org.quartz.JobKey) TaskDAO(org.apache.syncope.core.persistence.api.dao.TaskDAO) HashSet(java.util.HashSet) SQLException(java.sql.SQLException) PullTask(org.apache.syncope.core.persistence.api.entity.task.PullTask) SchedulerException(org.quartz.SchedulerException) TriggerBuilder(org.quartz.TriggerBuilder) BeanCreationException(org.springframework.beans.factory.BeanCreationException) DataSource(javax.sql.DataSource) ImplementationType(org.apache.syncope.common.lib.types.ImplementationType) SchedTask(org.apache.syncope.core.persistence.api.entity.task.SchedTask) ReportJob(org.apache.syncope.core.provisioning.java.job.report.ReportJob) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) PushJobDelegate(org.apache.syncope.core.provisioning.java.pushpull.PushJobDelegate) Report(org.apache.syncope.core.persistence.api.entity.Report) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) NotificationJob(org.apache.syncope.core.provisioning.java.job.notification.NotificationJob) ReportDAO(org.apache.syncope.core.persistence.api.dao.ReportDAO) JobManager(org.apache.syncope.core.provisioning.api.job.JobManager) PushTask(org.apache.syncope.core.persistence.api.entity.task.PushTask) DomainsHolder(org.apache.syncope.core.persistence.api.DomainsHolder) ApplicationContextProvider(org.apache.syncope.core.spring.ApplicationContextProvider) TaskType(org.apache.syncope.common.lib.types.TaskType) CronScheduleBuilder(org.quartz.CronScheduleBuilder) Transactional(org.springframework.transaction.annotation.Transactional) PushJobDelegate(org.apache.syncope.core.provisioning.java.pushpull.PushJobDelegate) HashMap(java.util.HashMap) PullTask(org.apache.syncope.core.persistence.api.entity.task.PullTask) PushTask(org.apache.syncope.core.persistence.api.entity.task.PushTask) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation)

Aggregations

PullTask (org.apache.syncope.core.persistence.api.entity.task.PullTask)8 StringUtils (org.apache.commons.lang3.StringUtils)5 Implementation (org.apache.syncope.core.persistence.api.entity.Implementation)5 AnyTemplatePullTask (org.apache.syncope.core.persistence.api.entity.task.AnyTemplatePullTask)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)4 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)4 Set (java.util.Set)3 ImplementationType (org.apache.syncope.common.lib.types.ImplementationType)3 TaskType (org.apache.syncope.common.lib.types.TaskType)3 ExternalResourceDAO (org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO)3 ImplementationDAO (org.apache.syncope.core.persistence.api.dao.ImplementationDAO)3 RealmDAO (org.apache.syncope.core.persistence.api.dao.RealmDAO)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Collectors (java.util.stream.Collectors)2