Package org.apache.syncope.core.sync

Examples of org.apache.syncope.core.sync.SyncResult


        if (!syncTask.isPerformCreate()) {
            LOG.debug("SyncTask not configured for create");
            return Collections.<SyncResult>emptyList();
        }

        final SyncResult result = new SyncResult();
        result.setOperation(ResourceOperation.CREATE);
        result.setSubjectType(attrUtil.getType());
        result.setStatus(SyncResult.Status.SUCCESS);

        AbstractAttributableTO subjectTO = connObjectUtil.getAttributableTO(delta.getObject(), syncTask, attrUtil);

        delta = actions.beforeCreate(this, delta, subjectTO);

        if (dryRun) {
            result.setId(0L);
            if (subjectTO instanceof UserTO) {
                result.setName(((UserTO) subjectTO).getUsername());
            }
            if (subjectTO instanceof RoleTO) {
                result.setName(((RoleTO) subjectTO).getName());
            }
        } else {
            try {
                if (AttributableType.USER == attrUtil.getType()) {
                    Boolean enabled = readEnabled(delta.getObject());
                    WorkflowResult<Map.Entry<Long, Boolean>> created =
                            uwfAdapter.create((UserTO) subjectTO, true, enabled);

                    List<PropagationTask> tasks = propagationManager.getUserCreateTaskIds(created,
                            ((UserTO) subjectTO).getPassword(), subjectTO.getVirtualAttributes(),
                            Collections.singleton(syncTask.getResource().getName()));

                    taskExecutor.execute(tasks);

                    notificationManager.createTasks(created.getResult().getKey(), created.getPerformedTasks());

                    subjectTO = userDataBinder.getUserTO(created.getResult().getKey());

                    result.setId(created.getResult().getKey());
                    result.setName(((UserTO) subjectTO).getUsername());
                }
                if (AttributableType.ROLE == attrUtil.getType()) {
                    WorkflowResult<Long> created = rwfAdapter.create((RoleTO) subjectTO);
                    AttributeTO roleOwner = subjectTO.getAttributeMap().get(StringUtils.EMPTY);
                    if (roleOwner != null) {
                        roleOwnerMap.put(created.getResult(), roleOwner.getValues().iterator().next());
                    }

                    EntitlementUtil.extendAuthContext(created.getResult());

                    List<PropagationTask> tasks = propagationManager.getRoleCreateTaskIds(created,
                            subjectTO.getVirtualAttributes(), Collections.singleton(syncTask.getResource().getName()));

                    taskExecutor.execute(tasks);

                    subjectTO = roleDataBinder.getRoleTO(created.getResult());

                    result.setId(created.getResult());
                    result.setName(((RoleTO) subjectTO).getName());
                }

            } catch (PropagationException e) {
                // A propagation failure doesn't imply a synchronization failure.
                // The propagation exception status will be reported into the propagation task execution.
                LOG.error("Could not propagate {} {}", attrUtil.getType(), delta.getUid().getUidValue(), e);
            } catch (Exception e) {
                result.setStatus(SyncResult.Status.FAILURE);
                result.setMessage(e.getMessage());
                LOG.error("Could not create {} {} ", attrUtil.getType(), delta.getUid().getUidValue(), e);
            }
        }

        actions.after(this, delta, subjectTO, result);
View Full Code Here


        List<SyncResult> updResults = new ArrayList<SyncResult>();

        for (Long id : subjects) {
            LOG.debug("About to update {}", id);

            final SyncResult result = new SyncResult();
            result.setOperation(ResourceOperation.UPDATE);
            result.setSubjectType(attrUtil.getType());
            result.setStatus(SyncResult.Status.SUCCESS);
            result.setId(id);

            try {
                if (AttributableType.USER == attrUtil.getType()) {
                    UserTO updated = updateUser(id, delta, dryRun, result);
                    result.setName(updated.getUsername());
                }

                if (AttributableType.ROLE == attrUtil.getType()) {
                    RoleTO updated = updateRole(id, delta, dryRun, result);
                    result.setName(updated.getName());
                }
            } catch (PropagationException e) {
                // A propagation failure doesn't imply a synchronization failure.
                // The propagation exception status will be reported into the propagation task execution.
                LOG.error("Could not propagate {} {}", attrUtil.getType(), delta.getUid().getUidValue(), e);
            } catch (Exception e) {
                result.setStatus(SyncResult.Status.FAILURE);
                result.setMessage(e.getMessage());

                LOG.error("Could not update {} {}", attrUtil.getType(), delta.getUid().getUidValue(), e);
            }
            results.add(result);
View Full Code Here

                AbstractAttributableTO subjectTO = AttributableType.USER == attrUtil.getType()
                        ? userDataBinder.getUserTO(id)
                        : roleDataBinder.getRoleTO(id);
                delta = actions.beforeDelete(this, delta, subjectTO);

                final SyncResult result = new SyncResult();
                result.setId(id);
                if (subjectTO instanceof UserTO) {
                    result.setName(((UserTO) subjectTO).getUsername());
                }
                if (subjectTO instanceof RoleTO) {
                    result.setName(((RoleTO) subjectTO).getName());
                }
                result.setOperation(ResourceOperation.DELETE);
                result.setSubjectType(attrUtil.getType());
                result.setStatus(SyncResult.Status.SUCCESS);

                if (!dryRun) {
                    try {
                        List<PropagationTask> tasks = Collections.<PropagationTask>emptyList();
                        if (AttributableType.USER == attrUtil.getType()) {
                            tasks = propagationManager.getUserDeleteTaskIds(id, syncTask.getResource().getName());
                            notificationManager.createTasks(id, Collections.<String>singleton("delete"));
                        }
                        if (AttributableType.ROLE == attrUtil.getType()) {
                            tasks = propagationManager.getRoleDeleteTaskIds(id, syncTask.getResource().getName());
                        }
                        taskExecutor.execute(tasks);
                    } catch (Exception e) {
                        // A propagation failure doesn't imply a synchronization failure.
                        // The propagation exception status will be reported into the propagation task execution.
                        LOG.error("Could not propagate user " + id, e);
                    }

                    try {
                        if (AttributableType.USER == attrUtil.getType()) {
                            uwfAdapter.delete(id);
                        }
                        if (AttributableType.ROLE == attrUtil.getType()) {
                            rwfAdapter.delete(id);
                        }
                    } catch (Exception e) {
                        result.setStatus(SyncResult.Status.FAILURE);
                        result.setMessage(e.getMessage());
                        LOG.error("Could not delete {} {}", attrUtil.getType(), id, e);
                    }
                }

                actions.after(this, delta, subjectTO, result);
View Full Code Here

        if (!syncTask.isPerformCreate()) {
            LOG.debug("SyncTask not configured for create");
            return Collections.<SyncResult>emptyList();
        }

        final SyncResult result = new SyncResult();
        result.setOperation(ResourceOperation.CREATE);
        result.setSubjectType(attrUtil.getType());

        AbstractAttributableTO subjectTO = connObjectUtil.getAttributableTO(delta.getObject(), syncTask, attrUtil);

        delta = actions.beforeCreate(this, delta, subjectTO);

        if (dryRun) {
            result.setId(0L);
            if (subjectTO instanceof UserTO) {
                result.setName(((UserTO) subjectTO).getUsername());
            }
            if (subjectTO instanceof RoleTO) {
                result.setName(((RoleTO) subjectTO).getName());
            }
            result.setStatus(SyncResult.Status.SUCCESS);
        } else {
            try {
                if (AttributableType.USER == attrUtil.getType()) {
                    Boolean enabled = readEnabled(delta.getObject());
                    WorkflowResult<Map.Entry<Long, Boolean>> created =
                            uwfAdapter.create((UserTO) subjectTO, true, enabled);

                    List<PropagationTask> tasks = propagationManager.getUserCreateTaskIds(created,
                            ((UserTO) subjectTO).getPassword(), subjectTO.getVirtualAttributes(),
                            Collections.singleton(syncTask.getResource().getName()));

                    taskExecutor.execute(tasks);

                    notificationManager.createTasks(created.getResult().getKey(), created.getPerformedTasks());

                    subjectTO = userDataBinder.getUserTO(created.getResult().getKey());

                    result.setId(created.getResult().getKey());
                }
                if (AttributableType.ROLE == attrUtil.getType()) {
                    WorkflowResult<Long> created = rwfAdapter.create((RoleTO) subjectTO);
                    AttributeTO roleOwner = subjectTO.getAttributeMap().get(StringUtils.EMPTY);
                    if (roleOwner != null) {
                        roleOwnerMap.put(created.getResult(), roleOwner.getValues().iterator().next());
                    }

                    EntitlementUtil.extendAuthContext(created.getResult());

                    List<PropagationTask> tasks = propagationManager.getRoleCreateTaskIds(created,
                            subjectTO.getVirtualAttributes(), Collections.singleton(syncTask.getResource().getName()));

                    taskExecutor.execute(tasks);

                    subjectTO = roleDataBinder.getRoleTO(created.getResult());

                    result.setId(created.getResult());
                }

                if (subjectTO instanceof UserTO) {
                    result.setName(((UserTO) subjectTO).getUsername());
                }
                if (subjectTO instanceof RoleTO) {
                    result.setName(((RoleTO) subjectTO).getName());
                }
                result.setStatus(SyncResult.Status.SUCCESS);
            } catch (PropagationException e) {
                LOG.error("Could not propagate {} {}", attrUtil.getType(), delta.getUid().getUidValue(), e);
            } catch (Exception e) {
                result.setStatus(SyncResult.Status.FAILURE);
                result.setMessage(e.getMessage());
                LOG.error("Could not create {} {} ", attrUtil.getType(), delta.getUid().getUidValue(), e);
            }
        }

        actions.after(this, delta, subjectTO, result);
View Full Code Here

        List<SyncResult> updResults = new ArrayList<SyncResult>();

        for (Long id : subjects) {
            LOG.debug("About to update {}", id);

            final SyncResult result = new SyncResult();
            result.setOperation(ResourceOperation.UPDATE);
            result.setSubjectType(attrUtil.getType());
            result.setStatus(SyncResult.Status.SUCCESS);
            result.setId(id);

            try {
                if (AttributableType.USER == attrUtil.getType()) {
                    updateUser(id, delta, dryRun, result);
                }

                if (AttributableType.ROLE == attrUtil.getType()) {
                    updateRole(id, delta, dryRun, result);
                }
            } catch (PropagationException e) {
                result.setStatus(SyncResult.Status.FAILURE);
                result.setMessage(delta.getUid().getUidValue() + "updated but not propagated\n" + e.getMessage());

                LOG.error("Could not propagate {} {}", attrUtil.getType(), delta.getUid().getUidValue(), e);
            } catch (Exception e) {
                result.setStatus(SyncResult.Status.FAILURE);
                result.setMessage(e.getMessage());

                LOG.error("Could not update {} {}", attrUtil.getType(), delta.getUid().getUidValue(), e);
            }
            results.add(result);
View Full Code Here

                AbstractAttributableTO subjectTO = AttributableType.USER == attrUtil.getType()
                        ? userDataBinder.getUserTO(id)
                        : roleDataBinder.getRoleTO(id);
                delta = actions.beforeDelete(this, delta, subjectTO);

                final SyncResult result = new SyncResult();
                result.setId(id);
                if (subjectTO instanceof UserTO) {
                    result.setName(((UserTO) subjectTO).getUsername());
                }
                if (subjectTO instanceof RoleTO) {
                    result.setName(((RoleTO) subjectTO).getName());
                }
                result.setOperation(ResourceOperation.DELETE);
                result.setSubjectType(attrUtil.getType());
                result.setStatus(SyncResult.Status.SUCCESS);

                if (!dryRun) {
                    try {
                        List<PropagationTask> tasks = Collections.<PropagationTask>emptyList();
                        if (AttributableType.USER == attrUtil.getType()) {
                            tasks = propagationManager.getUserDeleteTaskIds(id, syncTask.getResource().getName());
                            notificationManager.createTasks(id, Collections.<String>singleton("delete"));
                        }
                        if (AttributableType.ROLE == attrUtil.getType()) {
                            tasks = propagationManager.getRoleDeleteTaskIds(id, syncTask.getResource().getName());
                        }
                        taskExecutor.execute(tasks);
                    } catch (Exception e) {
                        LOG.error("Could not propagate user " + id, e);
                    }

                    try {
                        if (AttributableType.USER == attrUtil.getType()) {
                            uwfAdapter.delete(id);
                        }
                        if (AttributableType.ROLE == attrUtil.getType()) {
                            rwfAdapter.delete(id);
                        }
                    } catch (Exception e) {
                        result.setStatus(SyncResult.Status.SUCCESS);
                        result.setMessage(e.getMessage());
                        LOG.error("Could not delete {} {}", attrUtil.getType(), id, e);
                    }
                }

                actions.after(this, delta, subjectTO, result);
View Full Code Here

        if (!syncTask.isPerformCreate()) {
            LOG.debug("SyncTask not configured for create");
            return Collections.<SyncResult>emptyList();
        }

        final SyncResult result = new SyncResult();
        result.setOperation(ResourceOperation.CREATE);
        result.setSubjectType(attrUtil.getType());
        result.setStatus(SyncResult.Status.SUCCESS);

        AbstractAttributableTO subjectTO = connObjectUtil.getAttributableTO(delta.getObject(), syncTask, attrUtil);

        // Attributable transformation (if configured)
        AbstractAttributableTO actual = attrTransformer.transform(subjectTO);
        LOG.debug("Transformed: {}", actual);

        if (dryRun) {
            result.setId(0L);
            if (actual instanceof UserTO) {
                result.setName(((UserTO) actual).getUsername());
            }
            if (actual instanceof RoleTO) {
                result.setName(((RoleTO) actual).getName());
            }
        } else {
            delta = actions.beforeCreate(this, delta, actual);

            Object output;
            Result resultStatus;

            try {
                if (AttributableType.USER == attrUtil.getType()) {
                    Boolean enabled = readEnabled(delta.getObject());
                    WorkflowResult<Map.Entry<Long, Boolean>> created =
                            uwfAdapter.create((UserTO) actual, true, enabled);

                    List<PropagationTask> tasks = propagationManager.getUserCreateTaskIds(created,
                            ((UserTO) actual).getPassword(), actual.getVirtualAttributes(),
                            Collections.singleton(syncTask.getResource().getName()));

                    taskExecutor.execute(tasks);

                    actual = userDataBinder.getUserTO(created.getResult().getKey());

                    result.setId(created.getResult().getKey());
                    result.setName(((UserTO) actual).getUsername());
                } else if (AttributableType.ROLE == attrUtil.getType()) {
                    WorkflowResult<Long> created = rwfAdapter.create((RoleTO) actual);
                    AttributeTO roleOwner = actual.getAttributeMap().get(StringUtils.EMPTY);
                    if (roleOwner != null) {
                        roleOwnerMap.put(created.getResult(), roleOwner.getValues().iterator().next());
                    }

                    EntitlementUtil.extendAuthContext(created.getResult());

                    List<PropagationTask> tasks = propagationManager.getRoleCreateTaskIds(created,
                            actual.getVirtualAttributes(), Collections.singleton(syncTask.getResource().getName()));

                    taskExecutor.execute(tasks);

                    actual = roleDataBinder.getRoleTO(created.getResult());

                    result.setId(created.getResult());
                    result.setName(((RoleTO) actual).getName());
                }

                output = actual;
                resultStatus = Result.SUCCESS;

            } catch (PropagationException e) {
                // A propagation failure doesn't imply a synchronization failure.
                // The propagation exception status will be reported into the propagation task execution.
                LOG.error("Could not propagate {} {}", attrUtil.getType(), delta.getUid().getUidValue(), e);
                output = e;
                resultStatus = Result.FAILURE;
            } catch (Exception e) {
                result.setStatus(SyncResult.Status.FAILURE);
                result.setMessage(ExceptionUtils.getRootCauseMessage(e));
                LOG.error("Could not create {} {} ", attrUtil.getType(), delta.getUid().getUidValue(), e);
                output = e;
                resultStatus = Result.FAILURE;
            }
View Full Code Here

            Object output;
            AbstractAttributableTO before = null;
            Result resultStatus;

            final SyncResult result = new SyncResult();
            result.setOperation(ResourceOperation.UPDATE);
            result.setSubjectType(attrUtil.getType());
            result.setStatus(SyncResult.Status.SUCCESS);
            result.setId(id);

            try {
                final AbstractAttributableTO updated;
                if (AttributableType.USER == attrUtil.getType()) {
                    final Map.Entry<UserTO, UserTO> res = updateUser(id, delta, dryRun, result);
                    before = res.getKey();
                    updated = res.getValue();
                    result.setName(((UserTO) updated).getUsername());
                } else if (AttributableType.ROLE == attrUtil.getType()) {
                    final Map.Entry<RoleTO, RoleTO> res = updateRole(id, delta, dryRun, result);
                    before = res.getKey();
                    updated = res.getValue();
                    result.setName(((RoleTO) updated).getName());
                } else {
                    updated = null;
                }
                output = updated;
                resultStatus = Result.SUCCESS;
            } catch (PropagationException e) {
                // A propagation failure doesn't imply a synchronization failure.
                // The propagation exception status will be reported into the propagation task execution.
                LOG.error("Could not propagate {} {}", attrUtil.getType(), delta.getUid().getUidValue(), e);
                output = e;
                resultStatus = Result.FAILURE;
            } catch (Exception e) {
                result.setStatus(SyncResult.Status.FAILURE);
                result.setMessage(ExceptionUtils.getRootCauseMessage(e));
                LOG.error("Could not update {} {}", attrUtil.getType(), delta.getUid().getUidValue(), e);
                output = e;
                resultStatus = Result.FAILURE;
            }
            updResults.add(result);
View Full Code Here

        for (Long id : subjects) {
            Object output;
            Result resultStatus = Result.FAILURE;

            final SyncResult result = new SyncResult();

            try {
                AbstractAttributableTO subjectTO = AttributableType.USER == attrUtil.getType()
                        ? userDataBinder.getUserTO(id)
                        : roleDataBinder.getRoleTO(id);

                result.setId(id);
                if (subjectTO instanceof UserTO) {
                    result.setName(((UserTO) subjectTO).getUsername());
                }
                if (subjectTO instanceof RoleTO) {
                    result.setName(((RoleTO) subjectTO).getName());
                }
                result.setOperation(ResourceOperation.DELETE);
                result.setSubjectType(attrUtil.getType());
                result.setStatus(SyncResult.Status.SUCCESS);

                if (!dryRun) {
                    delta = actions.beforeDelete(this, delta, subjectTO);

                    try {
                        List<PropagationTask> tasks = Collections.<PropagationTask>emptyList();
                        if (AttributableType.USER == attrUtil.getType()) {
                            tasks = propagationManager.getUserDeleteTaskIds(id, syncTask.getResource().getName());
                        } else if (AttributableType.ROLE == attrUtil.getType()) {
                            tasks = propagationManager.getRoleDeleteTaskIds(id, syncTask.getResource().getName());
                        }
                        taskExecutor.execute(tasks);
                    } catch (Exception e) {
                        // A propagation failure doesn't imply a synchronization failure.
                        // The propagation exception status will be reported into the propagation task execution.
                        LOG.error("Could not propagate user " + id, e);
                    }

                    try {
                        if (AttributableType.USER == attrUtil.getType()) {
                            uwfAdapter.delete(id);
                        } else if (AttributableType.ROLE == attrUtil.getType()) {
                            rwfAdapter.delete(id);
                        }
                        output = null;
                        resultStatus = Result.SUCCESS;
                    } catch (Exception e) {
                        result.setStatus(SyncResult.Status.FAILURE);
                        result.setMessage(ExceptionUtils.getRootCauseMessage(e));
                        LOG.error("Could not delete {} {}", attrUtil.getType(), id, e);
                        output = e;
                    }

                    actions.after(this, delta, subjectTO, result);
View Full Code Here

        if (!syncTask.isPerformCreate()) {
            LOG.debug("SyncTask not configured for create");
            return Collections.<SyncResult>emptyList();
        }

        final SyncResult result = new SyncResult();
        result.setOperation(ResourceOperation.CREATE);
        result.setSubjectType(attrUtil.getType());
        result.setStatus(SyncResult.Status.SUCCESS);

        AbstractAttributableTO subjectTO = connObjectUtil.getAttributableTO(delta.getObject(), syncTask, attrUtil);

        delta = actions.beforeCreate(this, delta, subjectTO);

        if (dryRun) {
            result.setId(0L);
            if (subjectTO instanceof UserTO) {
                result.setName(((UserTO) subjectTO).getUsername());
            }
            if (subjectTO instanceof RoleTO) {
                result.setName(((RoleTO) subjectTO).getName());
            }
        } else {
            try {
                if (AttributableType.USER == attrUtil.getType()) {
                    Boolean enabled = readEnabled(delta.getObject());
                    WorkflowResult<Map.Entry<Long, Boolean>> created =
                            uwfAdapter.create((UserTO) subjectTO, true, enabled);

                    List<PropagationTask> tasks = propagationManager.getUserCreateTaskIds(created,
                            ((UserTO) subjectTO).getPassword(), subjectTO.getVirtualAttributes(),
                            Collections.singleton(syncTask.getResource().getName()));

                    taskExecutor.execute(tasks);

                    notificationManager.createTasks(created.getResult().getKey(), created.getPerformedTasks());

                    subjectTO = userDataBinder.getUserTO(created.getResult().getKey());

                    result.setId(created.getResult().getKey());
                    result.setName(((UserTO) subjectTO).getUsername());
                }
                if (AttributableType.ROLE == attrUtil.getType()) {
                    WorkflowResult<Long> created = rwfAdapter.create((RoleTO) subjectTO);
                    AttributeTO roleOwner = subjectTO.getAttributeMap().get(StringUtils.EMPTY);
                    if (roleOwner != null) {
                        roleOwnerMap.put(created.getResult(), roleOwner.getValues().iterator().next());
                    }

                    EntitlementUtil.extendAuthContext(created.getResult());

                    List<PropagationTask> tasks = propagationManager.getRoleCreateTaskIds(created,
                            subjectTO.getVirtualAttributes(), Collections.singleton(syncTask.getResource().getName()));

                    taskExecutor.execute(tasks);

                    subjectTO = roleDataBinder.getRoleTO(created.getResult());

                    result.setId(created.getResult());
                    result.setName(((RoleTO) subjectTO).getName());
                }

            } catch (PropagationException e) {
                // A propagation failure doesn't imply a synchronization failure.
                // The propagation exception status will be reported into the propagation task execution.
                LOG.error("Could not propagate {} {}", attrUtil.getType(), delta.getUid().getUidValue(), e);
            } catch (Exception e) {
                result.setStatus(SyncResult.Status.FAILURE);
                result.setMessage(e.getMessage());
                LOG.error("Could not create {} {} ", attrUtil.getType(), delta.getUid().getUidValue(), e);
            }
        }

        actions.after(this, delta, subjectTO, result);
View Full Code Here

TOP

Related Classes of org.apache.syncope.core.sync.SyncResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.