Search in sources :

Example 1 with PropagationReporter

use of org.apache.syncope.core.provisioning.api.propagation.PropagationReporter in project syncope by apache.

the class CreateProducer method process.

@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
    if ((exchange.getIn().getBody() instanceof WorkflowResult)) {
        Object actual = exchange.getProperty("actual");
        Set<String> excludedResources = exchange.getProperty("excludedResources", Set.class);
        Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
        if (actual instanceof UserTO) {
            WorkflowResult<Pair<String, Boolean>> created = (WorkflowResult<Pair<String, Boolean>>) exchange.getIn().getBody();
            List<PropagationTaskTO> tasks = getPropagationManager().getUserCreateTasks(created.getResult().getKey(), ((UserTO) actual).getPassword(), created.getResult().getValue(), created.getPropByRes(), ((UserTO) actual).getVirAttrs(), excludedResources);
            PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
            exchange.getOut().setBody(Pair.of(created.getResult().getKey(), propagationReporter.getStatuses()));
        } else if (actual instanceof AnyTO) {
            WorkflowResult<String> created = (WorkflowResult<String>) exchange.getIn().getBody();
            if (actual instanceof GroupTO && isPull()) {
                Map<String, String> groupOwnerMap = exchange.getProperty("groupOwnerMap", Map.class);
                Optional<AttrTO> groupOwner = ((GroupTO) actual).getPlainAttr(StringUtils.EMPTY);
                if (groupOwner.isPresent()) {
                    groupOwnerMap.put(created.getResult(), groupOwner.get().getValues().iterator().next());
                }
                List<PropagationTaskTO> tasks = getPropagationManager().getCreateTasks(AnyTypeKind.GROUP, created.getResult(), created.getPropByRes(), ((AnyTO) actual).getVirAttrs(), excludedResources);
                getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
                exchange.getOut().setBody(Pair.of(created.getResult(), null));
            } else {
                List<PropagationTaskTO> tasks = getPropagationManager().getCreateTasks(actual instanceof AnyObjectTO ? AnyTypeKind.ANY_OBJECT : AnyTypeKind.GROUP, created.getResult(), created.getPropByRes(), ((AnyTO) actual).getVirAttrs(), excludedResources);
                PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
                exchange.getOut().setBody(Pair.of(created.getResult(), propagationReporter.getStatuses()));
            }
        }
    }
}
Also used : AnyTO(org.apache.syncope.common.lib.to.AnyTO) WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) Optional(java.util.Optional) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) GroupTO(org.apache.syncope.common.lib.to.GroupTO) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) UserTO(org.apache.syncope.common.lib.to.UserTO) List(java.util.List) Map(java.util.Map) Pair(org.apache.commons.lang3.tuple.Pair)

Example 2 with PropagationReporter

use of org.apache.syncope.core.provisioning.api.propagation.PropagationReporter in project syncope by apache.

the class DeleteProducer method process.

@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
    String key = exchange.getIn().getBody(String.class);
    Set<String> excludedResources = exchange.getProperty("excludedResources", Set.class);
    Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
    if (null != getAnyTypeKind()) {
        List<PropagationTaskTO> tasks;
        PropagationReporter propagationReporter;
        switch(getAnyTypeKind()) {
            case USER:
                PropagationByResource propByRes = new PropagationByResource();
                propByRes.set(ResourceOperation.DELETE, userDAO.findAllResourceKeys(key));
                // Note here that we can only notify about "delete", not any other
                // task defined in workflow process definition: this because this
                // information could only be available after uwfAdapter.delete(), which
                // will also effectively remove user from db, thus making virtually
                // impossible by NotificationManager to fetch required user information
                tasks = getPropagationManager().getDeleteTasks(AnyTypeKind.USER, key, propByRes, excludedResources);
                propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
                exchange.setProperty("statuses", propagationReporter.getStatuses());
                break;
            case GROUP:
                tasks = new ArrayList<>();
                // resources only because of the reason being deleted (see SYNCOPE-357)
                for (Map.Entry<String, PropagationByResource> entry : groupDataBinder.findUsersWithTransitiveResources(key).entrySet()) {
                    tasks.addAll(getPropagationManager().getDeleteTasks(AnyTypeKind.USER, entry.getKey(), entry.getValue(), excludedResources));
                }
                for (Map.Entry<String, PropagationByResource> entry : groupDataBinder.findAnyObjectsWithTransitiveResources(key).entrySet()) {
                    tasks.addAll(getPropagationManager().getDeleteTasks(AnyTypeKind.ANY_OBJECT, entry.getKey(), entry.getValue(), excludedResources));
                }
                // Generate propagation tasks for deleting this group from resources
                tasks.addAll(getPropagationManager().getDeleteTasks(AnyTypeKind.GROUP, key, null, null));
                propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
                exchange.setProperty("statuses", propagationReporter.getStatuses());
                break;
            case ANY_OBJECT:
                tasks = getPropagationManager().getDeleteTasks(AnyTypeKind.ANY_OBJECT, key, null, excludedResources);
                propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
                exchange.setProperty("statuses", propagationReporter.getStatuses());
                break;
            default:
                break;
        }
    }
}
Also used : PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) Map(java.util.Map)

Example 3 with PropagationReporter

use of org.apache.syncope.core.provisioning.api.propagation.PropagationReporter in project syncope by apache.

the class DeprovisionProducer method process.

@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
    String key = exchange.getIn().getBody(String.class);
    List<String> resources = exchange.getProperty("resources", List.class);
    Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
    if (null != getAnyTypeKind()) {
        PropagationByResource propByRes = new PropagationByResource();
        List<PropagationTaskTO> tasks;
        PropagationReporter propagationReporter;
        switch(getAnyTypeKind()) {
            case USER:
                propByRes.set(ResourceOperation.DELETE, resources);
                tasks = getPropagationManager().getDeleteTasks(AnyTypeKind.USER, key, propByRes, userDAO.findAllResourceKeys(key).stream().filter(resource -> !resources.contains(resource)).collect(Collectors.toList()));
                propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
                exchange.getOut().setBody(propagationReporter.getStatuses());
                break;
            case GROUP:
                propByRes.addAll(ResourceOperation.DELETE, resources);
                tasks = getPropagationManager().getDeleteTasks(AnyTypeKind.GROUP, key, propByRes, groupDAO.findAllResourceKeys(key).stream().filter(resource -> !resources.contains(resource)).collect(Collectors.toList()));
                propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
                exchange.getOut().setBody(propagationReporter.getStatuses());
                break;
            case ANY_OBJECT:
                propByRes.addAll(ResourceOperation.DELETE, resources);
                tasks = getPropagationManager().getDeleteTasks(AnyTypeKind.ANY_OBJECT, key, propByRes, anyObjectDAO.findAllResourceKeys(key).stream().filter(resource -> !resources.contains(resource)).collect(Collectors.toList()));
                propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
                exchange.getOut().setBody(propagationReporter.getStatuses());
                break;
            default:
                break;
        }
    }
}
Also used : AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) List(java.util.List) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) AnyObjectDAO(org.apache.syncope.core.persistence.api.dao.AnyObjectDAO) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) ResourceOperation(org.apache.syncope.common.lib.types.ResourceOperation) Collectors(java.util.stream.Collectors) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter)

Example 4 with PropagationReporter

use of org.apache.syncope.core.provisioning.api.propagation.PropagationReporter in project syncope by apache.

the class StatusProducer method process.

@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
    if (getAnyTypeKind() == AnyTypeKind.USER && isPull()) {
        WorkflowResult<Map.Entry<UserPatch, Boolean>> updated = (WorkflowResult<Entry<UserPatch, Boolean>>) exchange.getIn().getBody();
        Boolean enabled = exchange.getProperty("enabled", Boolean.class);
        String key = exchange.getProperty("key", String.class);
        if (enabled != null) {
            User user = userDAO.find(key);
            WorkflowResult<String> enableUpdate = null;
            if (user.isSuspended() == null) {
                enableUpdate = uwfAdapter.activate(key, null);
            } else if (enabled && user.isSuspended()) {
                enableUpdate = uwfAdapter.reactivate(key);
            } else if (!enabled && !user.isSuspended()) {
                enableUpdate = uwfAdapter.suspend(key);
            }
            if (enableUpdate != null) {
                if (enableUpdate.getPropByRes() != null) {
                    updated.getPropByRes().merge(enableUpdate.getPropByRes());
                    updated.getPropByRes().purge();
                }
                updated.getPerformedTasks().addAll(enableUpdate.getPerformedTasks());
            }
        }
    } else if (getAnyTypeKind() == AnyTypeKind.USER) {
        WorkflowResult<Long> updated = (WorkflowResult<Long>) exchange.getIn().getBody();
        StatusPatch statusPatch = exchange.getProperty("statusPatch", StatusPatch.class);
        Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
        PropagationByResource propByRes = new PropagationByResource();
        propByRes.addAll(ResourceOperation.UPDATE, statusPatch.getResources());
        List<PropagationTaskTO> tasks = getPropagationManager().getUpdateTasks(AnyTypeKind.USER, statusPatch.getKey(), false, statusPatch.getType() != StatusPatchType.SUSPEND, propByRes, null, null);
        PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
        exchange.getOut().setBody(Pair.of(updated.getResult(), propagationReporter.getStatuses()));
    }
}
Also used : WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) User(org.apache.syncope.core.persistence.api.entity.user.User) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Entry(java.util.Map.Entry) StatusPatch(org.apache.syncope.common.lib.patch.StatusPatch) List(java.util.List)

Example 5 with PropagationReporter

use of org.apache.syncope.core.provisioning.api.propagation.PropagationReporter in project syncope by apache.

the class UpdateProducer method process.

@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
    if ((exchange.getIn().getBody() instanceof WorkflowResult)) {
        Object actual = exchange.getProperty("actual");
        Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
        Set<String> excludedResources = exchange.getProperty("excludedResources", Set.class);
        if (actual instanceof UserPatch || isPull()) {
            WorkflowResult<Pair<UserPatch, Boolean>> updated = (WorkflowResult<Pair<UserPatch, Boolean>>) exchange.getIn().getBody();
            List<PropagationTaskTO> tasks;
            if (isPull()) {
                boolean passwordNotNull = updated.getResult().getKey().getPassword() != null;
                tasks = getPropagationManager().getUserUpdateTasks(updated, passwordNotNull, excludedResources);
            } else {
                tasks = getPropagationManager().getUserUpdateTasks(updated);
            }
            PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
            exchange.getOut().setBody(Pair.of(updated.getResult().getLeft(), propagationReporter.getStatuses()));
        } else if (actual instanceof AnyPatch) {
            WorkflowResult<? extends AnyPatch> updated = (WorkflowResult<? extends AnyPatch>) exchange.getIn().getBody();
            List<PropagationTaskTO> tasks = getPropagationManager().getUpdateTasks(actual instanceof AnyObjectPatch ? AnyTypeKind.ANY_OBJECT : AnyTypeKind.GROUP, updated.getResult().getKey(), false, null, updated.getPropByRes(), ((AnyPatch) actual).getVirAttrs(), excludedResources);
            PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
            exchange.getOut().setBody(Pair.of(updated.getResult(), propagationReporter.getStatuses()));
        }
    }
}
Also used : WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) AnyPatch(org.apache.syncope.common.lib.patch.AnyPatch) List(java.util.List) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

PropagationReporter (org.apache.syncope.core.provisioning.api.propagation.PropagationReporter)36 PropagationTaskTO (org.apache.syncope.common.lib.to.PropagationTaskTO)28 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)23 Transactional (org.springframework.transaction.annotation.Transactional)10 ArrayList (java.util.ArrayList)8 Pair (org.apache.commons.lang3.tuple.Pair)7 List (java.util.List)6 WorkflowResult (org.apache.syncope.core.provisioning.api.WorkflowResult)6 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)5 PropagationException (org.apache.syncope.core.provisioning.api.propagation.PropagationException)5 Map (java.util.Map)4 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)4 AnyTO (org.apache.syncope.common.lib.to.AnyTO)4 Realm (org.apache.syncope.core.persistence.api.entity.Realm)4 Collectors (java.util.stream.Collectors)3 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)3 RealmTO (org.apache.syncope.common.lib.to.RealmTO)3 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)3 User (org.apache.syncope.core.persistence.api.entity.user.User)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3