Search in sources :

Example 6 with AnyPatch

use of org.apache.syncope.common.lib.patch.AnyPatch in project syncope by apache.

the class AbstractAnyDataBinder method fill.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected PropagationByResource fill(final Any any, final AnyPatch anyPatch, final AnyUtils anyUtils, final SyncopeClientCompositeException scce) {
    PropagationByResource propByRes = new PropagationByResource();
    // 1. anyTypeClasses
    for (StringPatchItem patch : anyPatch.getAuxClasses()) {
        AnyTypeClass auxClass = anyTypeClassDAO.find(patch.getValue());
        if (auxClass == null) {
            LOG.debug("Invalid " + AnyTypeClass.class.getSimpleName() + " {}, ignoring...", patch.getValue());
        } else {
            switch(patch.getOperation()) {
                case ADD_REPLACE:
                    any.add(auxClass);
                    break;
                case DELETE:
                default:
                    any.getAuxClasses().remove(auxClass);
            }
        }
    }
    // 2. resources
    for (StringPatchItem patch : anyPatch.getResources()) {
        ExternalResource resource = resourceDAO.find(patch.getValue());
        if (resource == null) {
            LOG.debug("Invalid " + ExternalResource.class.getSimpleName() + " {}, ignoring...", patch.getValue());
        } else {
            switch(patch.getOperation()) {
                case ADD_REPLACE:
                    propByRes.add(ResourceOperation.CREATE, resource.getKey());
                    any.add(resource);
                    break;
                case DELETE:
                default:
                    propByRes.add(ResourceOperation.DELETE, resource.getKey());
                    any.getResources().remove(resource);
            }
        }
    }
    Set<ExternalResource> resources = anyUtils.getAllResources(any);
    SyncopeClientException invalidValues = SyncopeClientException.build(ClientExceptionType.InvalidValues);
    // 3. plain attributes
    anyPatch.getPlainAttrs().stream().filter(patch -> patch.getAttrTO() != null).forEach(patch -> {
        PlainSchema schema = getPlainSchema(patch.getAttrTO().getSchema());
        if (schema == null) {
            LOG.debug("Invalid " + PlainSchema.class.getSimpleName() + " {}, ignoring...", patch.getAttrTO().getSchema());
        } else {
            PlainAttr<?> attr = (PlainAttr<?>) any.getPlainAttr(schema.getKey()).orElse(null);
            if (attr == null) {
                LOG.debug("No plain attribute found for schema {}", schema);
                if (patch.getOperation() == PatchOperation.ADD_REPLACE) {
                    attr = anyUtils.newPlainAttr();
                    ((PlainAttr) attr).setOwner(any);
                    attr.setSchema(schema);
                    any.add(attr);
                }
            }
            if (attr != null) {
                processAttrPatch(any, patch, schema, attr, anyUtils, resources, propByRes, invalidValues);
            }
        }
    });
    if (!invalidValues.isEmpty()) {
        scce.addException(invalidValues);
    }
    SyncopeClientException requiredValuesMissing = checkMandatory(any, anyUtils);
    if (!requiredValuesMissing.isEmpty()) {
        scce.addException(requiredValuesMissing);
    }
    requiredValuesMissing = checkMandatoryOnResources(any, resources);
    if (!requiredValuesMissing.isEmpty()) {
        scce.addException(requiredValuesMissing);
    }
    return propByRes;
}
Also used : StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Realm(org.apache.syncope.core.persistence.api.entity.Realm) PlainAttr(org.apache.syncope.core.persistence.api.entity.PlainAttr) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) InvalidPlainAttrValueException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException) ResourceOperation(org.apache.syncope.common.lib.types.ResourceOperation) StringUtils(org.apache.commons.lang3.StringUtils) AllowedSchemas(org.apache.syncope.core.persistence.api.dao.AllowedSchemas) JexlUtils(org.apache.syncope.core.provisioning.java.jexl.JexlUtils) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) AnyObjectDAO(org.apache.syncope.core.persistence.api.dao.AnyObjectDAO) Map(java.util.Map) SchemaDataBinder(org.apache.syncope.core.provisioning.api.data.SchemaDataBinder) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) ParseException(java.text.ParseException) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) AnyPatch(org.apache.syncope.common.lib.patch.AnyPatch) RelationshipTypeDAO(org.apache.syncope.core.persistence.api.dao.RelationshipTypeDAO) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) Collection(java.util.Collection) DerAttrHandler(org.apache.syncope.core.provisioning.api.DerAttrHandler) Set(java.util.Set) PlainAttrValue(org.apache.syncope.core.persistence.api.entity.PlainAttrValue) Collectors(java.util.stream.Collectors) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) EntityFactory(org.apache.syncope.core.persistence.api.entity.EntityFactory) List(java.util.List) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) Optional(java.util.Optional) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName) AttrTO(org.apache.syncope.common.lib.to.AttrTO) AnyUtilsFactory(org.apache.syncope.core.persistence.api.entity.AnyUtilsFactory) GroupableRelatable(org.apache.syncope.core.persistence.api.entity.GroupableRelatable) AnyTO(org.apache.syncope.common.lib.to.AnyTO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) MappingManager(org.apache.syncope.core.provisioning.api.MappingManager) SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) RealmDAO(org.apache.syncope.core.persistence.api.dao.RealmDAO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) Logger(org.slf4j.Logger) PlainSchemaDAO(org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO) VirAttrHandler(org.apache.syncope.core.provisioning.api.VirAttrHandler) Membership(org.apache.syncope.core.persistence.api.entity.Membership) PlainAttrValueDAO(org.apache.syncope.core.persistence.api.dao.PlainAttrValueDAO) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) MappingUtils(org.apache.syncope.core.provisioning.java.utils.MappingUtils) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) RelationshipTO(org.apache.syncope.common.lib.to.RelationshipTO) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) IntAttrNameParser(org.apache.syncope.core.provisioning.java.IntAttrNameParser) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) Collections(java.util.Collections) AnyTypeClassDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeClassDAO) Any(org.apache.syncope.core.persistence.api.entity.Any) PlainAttrDAO(org.apache.syncope.core.persistence.api.dao.PlainAttrDAO) GroupablePlainAttr(org.apache.syncope.core.persistence.api.entity.GroupablePlainAttr) PlainAttr(org.apache.syncope.core.persistence.api.entity.PlainAttr) GroupablePlainAttr(org.apache.syncope.core.persistence.api.entity.GroupablePlainAttr) StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)

Example 7 with AnyPatch

use of org.apache.syncope.common.lib.patch.AnyPatch in project syncope by apache.

the class AbstractPullResultHandler method link.

protected List<ProvisioningReport> link(final SyncDelta delta, final List<String> anyKeys, final Provision provision, final boolean unlink) throws JobExecutionException {
    if (!profile.getTask().isPerformUpdate()) {
        LOG.debug("PullTask not configured for update");
        finalize(unlink ? MatchingRule.toEventName(MatchingRule.UNLINK) : MatchingRule.toEventName(MatchingRule.LINK), Result.SUCCESS, null, null, delta);
        return Collections.<ProvisioningReport>emptyList();
    }
    LOG.debug("About to update {}", anyKeys);
    final List<ProvisioningReport> results = new ArrayList<>();
    for (String key : anyKeys) {
        LOG.debug("About to unassign resource {}", key);
        ProvisioningReport result = new ProvisioningReport();
        result.setOperation(ResourceOperation.NONE);
        result.setAnyType(provision.getAnyType().getKey());
        result.setStatus(ProvisioningReport.Status.SUCCESS);
        result.setKey(key);
        AnyTO before = getAnyTO(key);
        if (before == null) {
            result.setStatus(ProvisioningReport.Status.FAILURE);
            result.setMessage(String.format("Any '%s(%s)' not found", provision.getAnyType().getKey(), key));
        }
        if (!profile.isDryRun()) {
            Result resultStatus;
            Object output;
            AnyPatch effectivePatch = null;
            if (before == null) {
                resultStatus = Result.FAILURE;
                output = null;
            } else {
                result.setName(getName(before));
                try {
                    if (unlink) {
                        for (PullActions action : profile.getActions()) {
                            action.beforeUnlink(profile, delta, before);
                        }
                    } else {
                        for (PullActions action : profile.getActions()) {
                            action.beforeLink(profile, delta, before);
                        }
                    }
                    AnyPatch anyPatch = newPatch(before.getKey());
                    anyPatch.getResources().add(new StringPatchItem.Builder().operation(unlink ? PatchOperation.DELETE : PatchOperation.ADD_REPLACE).value(profile.getTask().getResource().getKey()).build());
                    effectivePatch = update(anyPatch).getResult();
                    output = AnyOperations.patch(before, effectivePatch);
                    for (PullActions action : profile.getActions()) {
                        action.after(profile, delta, AnyTO.class.cast(output), result);
                    }
                    resultStatus = Result.SUCCESS;
                    LOG.debug("{} {} successfully updated", provision.getAnyType().getKey(), key);
                } catch (PropagationException e) {
                    // A propagation failure doesn't imply a pull failure.
                    // The propagation exception status will be reported into the propagation task execution.
                    LOG.error("Could not propagate {} {}", provision.getAnyType().getKey(), delta.getUid().getUidValue(), e);
                    output = e;
                    resultStatus = Result.FAILURE;
                } catch (Exception e) {
                    throwIgnoreProvisionException(delta, e);
                    result.setStatus(ProvisioningReport.Status.FAILURE);
                    result.setMessage(ExceptionUtils.getRootCauseMessage(e));
                    LOG.error("Could not update {} {}", provision.getAnyType().getKey(), delta.getUid().getUidValue(), e);
                    output = e;
                    resultStatus = Result.FAILURE;
                }
            }
            finalize(unlink ? MatchingRule.toEventName(MatchingRule.UNLINK) : MatchingRule.toEventName(MatchingRule.LINK), resultStatus, before, output, delta, effectivePatch);
        }
        results.add(result);
    }
    return results;
}
Also used : AnyTO(org.apache.syncope.common.lib.to.AnyTO) PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) AnyPatch(org.apache.syncope.common.lib.patch.AnyPatch) PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) ArrayList(java.util.ArrayList) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) IgnoreProvisionException(org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException) PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) JobExecutionException(org.quartz.JobExecutionException) Result(org.apache.syncope.common.lib.types.AuditElements.Result)

Example 8 with AnyPatch

use of org.apache.syncope.common.lib.patch.AnyPatch in project syncope by apache.

the class AbstractPullResultHandler method update.

protected List<ProvisioningReport> update(final SyncDelta delta, final List<String> anyKeys, final Provision provision) throws JobExecutionException {
    if (!profile.getTask().isPerformUpdate()) {
        LOG.debug("PullTask not configured for update");
        finalize(MatchingRule.toEventName(MatchingRule.UPDATE), Result.SUCCESS, null, null, delta);
        return Collections.<ProvisioningReport>emptyList();
    }
    LOG.debug("About to update {}", anyKeys);
    List<ProvisioningReport> results = new ArrayList<>();
    for (String key : anyKeys) {
        LOG.debug("About to update {}", key);
        ProvisioningReport result = new ProvisioningReport();
        result.setOperation(ResourceOperation.UPDATE);
        result.setAnyType(provision.getAnyType().getKey());
        result.setStatus(ProvisioningReport.Status.SUCCESS);
        result.setKey(key);
        AnyTO before = getAnyTO(key);
        if (before == null) {
            result.setStatus(ProvisioningReport.Status.FAILURE);
            result.setMessage(String.format("Any '%s(%s)' not found", provision.getAnyType().getKey(), key));
        } else {
            result.setName(getName(before));
        }
        if (!profile.isDryRun()) {
            Result resultStatus;
            Object output;
            AnyPatch effectivePatch = null;
            if (before == null) {
                resultStatus = Result.FAILURE;
                output = null;
            } else {
                AnyPatch anyPatch = null;
                try {
                    anyPatch = connObjectUtils.getAnyPatch(before.getKey(), delta.getObject(), before, profile.getTask(), provision, getAnyUtils());
                    for (PullActions action : profile.getActions()) {
                        action.beforeUpdate(profile, delta, before, anyPatch);
                    }
                    effectivePatch = doUpdate(before, anyPatch, delta, result);
                    AnyTO updated = AnyOperations.patch(before, effectivePatch);
                    for (PullActions action : profile.getActions()) {
                        action.after(profile, delta, updated, result);
                    }
                    output = updated;
                    resultStatus = Result.SUCCESS;
                    result.setName(getName(updated));
                    LOG.debug("{} {} successfully updated", provision.getAnyType().getKey(), key);
                } catch (PropagationException e) {
                    // A propagation failure doesn't imply a pull failure.
                    // The propagation exception status will be reported into the propagation task execution.
                    LOG.error("Could not propagate {} {}", provision.getAnyType().getKey(), delta.getUid().getUidValue(), e);
                    output = e;
                    resultStatus = Result.FAILURE;
                } catch (Exception e) {
                    throwIgnoreProvisionException(delta, e);
                    result.setStatus(ProvisioningReport.Status.FAILURE);
                    result.setMessage(ExceptionUtils.getRootCauseMessage(e));
                    LOG.error("Could not update {} {}", provision.getAnyType().getKey(), delta.getUid().getUidValue(), e);
                    output = e;
                    resultStatus = Result.FAILURE;
                    if (profile.getTask().isRemediation()) {
                        Remediation entity = entityFactory.newEntity(Remediation.class);
                        entity.setAnyType(provision.getAnyType());
                        entity.setOperation(ResourceOperation.UPDATE);
                        entity.setPayload(anyPatch);
                        entity.setError(result.getMessage());
                        entity.setInstant(new Date());
                        entity.setRemoteName(delta.getObject().getName().getNameValue());
                        entity.setPullTask(profile.getTask());
                        remediationDAO.save(entity);
                    }
                }
            }
            finalize(MatchingRule.toEventName(MatchingRule.UPDATE), resultStatus, before, output, delta, effectivePatch);
        }
        results.add(result);
    }
    return results;
}
Also used : AnyTO(org.apache.syncope.common.lib.to.AnyTO) PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) ArrayList(java.util.ArrayList) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) IgnoreProvisionException(org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException) PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) JobExecutionException(org.quartz.JobExecutionException) Date(java.util.Date) Result(org.apache.syncope.common.lib.types.AuditElements.Result) PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) AnyPatch(org.apache.syncope.common.lib.patch.AnyPatch) Remediation(org.apache.syncope.core.persistence.api.entity.Remediation)

Aggregations

AnyPatch (org.apache.syncope.common.lib.patch.AnyPatch)8 ArrayList (java.util.ArrayList)4 AnyTO (org.apache.syncope.common.lib.to.AnyTO)4 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)4 Result (org.apache.syncope.common.lib.types.AuditElements.Result)3 AttributeBuilder (org.identityconnectors.framework.common.objects.AttributeBuilder)3 List (java.util.List)2 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)2 PropagationException (org.apache.syncope.core.provisioning.api.propagation.PropagationException)2 IgnoreProvisionException (org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException)2 ProvisioningReport (org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport)2 PullActions (org.apache.syncope.core.provisioning.api.pushpull.PullActions)2 DelegatedAdministrationException (org.apache.syncope.core.spring.security.DelegatedAdministrationException)2 JobExecutionException (org.quartz.JobExecutionException)2 ParseException (java.text.ParseException)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1