Search in sources :

Example 6 with Realm

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

the class AbstractAnyLogic method beforeUpdate.

protected Pair<P, List<LogicActions>> beforeUpdate(final P input, final String realmPath) {
    Realm realm = realmDAO.findByFullPath(realmPath);
    if (realm == null) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRealm);
        sce.getElements().add(realmPath);
        throw sce;
    }
    P mod = input;
    List<LogicActions> actions = getActions(realm);
    for (LogicActions action : actions) {
        mod = action.beforeUpdate(mod);
    }
    LOG.debug("Input: {}\nOutput: {}\n", input, mod);
    return ImmutablePair.of(mod, actions);
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Realm(org.apache.syncope.core.persistence.api.entity.Realm) LogicActions(org.apache.syncope.core.provisioning.api.LogicActions)

Example 7 with Realm

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

the class AbstractAnyLogic method beforeCreate.

protected Pair<TO, List<LogicActions>> beforeCreate(final TO input) {
    Realm realm = realmDAO.findByFullPath(input.getRealm());
    if (realm == null) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRealm);
        sce.getElements().add(input.getRealm());
        throw sce;
    }
    AnyType anyType = input instanceof UserTO ? anyTypeDAO.findUser() : input instanceof GroupTO ? anyTypeDAO.findGroup() : anyTypeDAO.find(input.getType());
    if (anyType == null) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidAnyType);
        sce.getElements().add(input.getType());
        throw sce;
    }
    TO any = input;
    templateUtils.apply(any, realm.getTemplate(anyType));
    List<LogicActions> actions = getActions(realm);
    for (LogicActions action : actions) {
        any = action.beforeCreate(any);
    }
    LOG.debug("Input: {}\nOutput: {}\n", input, any);
    return ImmutablePair.of(any, actions);
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AnyTO(org.apache.syncope.common.lib.to.AnyTO) GroupTO(org.apache.syncope.common.lib.to.GroupTO) UserTO(org.apache.syncope.common.lib.to.UserTO) Realm(org.apache.syncope.core.persistence.api.entity.Realm) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) LogicActions(org.apache.syncope.core.provisioning.api.LogicActions) GroupTO(org.apache.syncope.common.lib.to.GroupTO)

Example 8 with Realm

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

the class DefaultRealmPullResultHandler method link.

private List<ProvisioningReport> link(final SyncDelta delta, final List<String> keys, 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 link {}", keys);
    final List<ProvisioningReport> results = new ArrayList<>();
    for (String key : keys) {
        LOG.debug("About to unassign resource {}", key);
        ProvisioningReport result = new ProvisioningReport();
        result.setOperation(ResourceOperation.NONE);
        result.setAnyType(REALM_TYPE);
        result.setStatus(ProvisioningReport.Status.SUCCESS);
        result.setKey(key);
        Realm realm = realmDAO.find(key);
        RealmTO before = binder.getRealmTO(realm, true);
        if (before == null) {
            result.setStatus(ProvisioningReport.Status.FAILURE);
            result.setMessage(String.format("Realm '%s' not found", key));
        } else {
            result.setName(before.getFullPath());
        }
        Object output;
        Result resultStatus;
        if (!profile.isDryRun()) {
            if (before == null) {
                resultStatus = Result.FAILURE;
                output = null;
            } else {
                try {
                    if (unlink) {
                        for (PullActions action : profile.getActions()) {
                            action.beforeUnlink(profile, delta, before);
                        }
                    } else {
                        for (PullActions action : profile.getActions()) {
                            action.beforeLink(profile, delta, before);
                        }
                    }
                    if (unlink) {
                        realm.getResources().remove(profile.getTask().getResource());
                    } else {
                        realm.add(profile.getTask().getResource());
                    }
                    output = update(delta, Collections.singletonList(key));
                    for (PullActions action : profile.getActions()) {
                        action.after(profile, delta, RealmTO.class.cast(output), result);
                    }
                    resultStatus = Result.SUCCESS;
                    LOG.debug("{} successfully updated", realm);
                } 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 Realm {}", 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 Realm {}", delta.getUid().getUidValue(), e);
                    output = e;
                    resultStatus = Result.FAILURE;
                }
            }
            finalize(unlink ? MatchingRule.toEventName(MatchingRule.UNLINK) : MatchingRule.toEventName(MatchingRule.LINK), resultStatus, before, output, delta);
        }
        results.add(result);
    }
    return results;
}
Also used : PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) ArrayList(java.util.ArrayList) RealmTO(org.apache.syncope.common.lib.to.RealmTO) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport) Realm(org.apache.syncope.core.persistence.api.entity.Realm) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) 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) JobExecutionException(org.quartz.JobExecutionException) Result(org.apache.syncope.common.lib.types.AuditElements.Result)

Example 9 with Realm

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

the class PullUtils method match.

/**
 * Finds internal realms based on external attributes and mapping.
 *
 * @param connObj external attributes
 * @param orgUnit mapping
 * @return list of matching realms' keys.
 */
public List<String> match(final ConnectorObject connObj, final OrgUnit orgUnit) {
    String connObjectKey = null;
    Optional<? extends OrgUnitItem> connObjectKeyItem = orgUnit.getConnObjectKeyItem();
    if (connObjectKeyItem != null) {
        Attribute connObjectKeyAttr = connObj.getAttributeByName(connObjectKeyItem.get().getExtAttrName());
        if (connObjectKeyAttr != null) {
            connObjectKey = AttributeUtil.getStringValue(connObjectKeyAttr);
        }
    }
    if (connObjectKey == null) {
        return Collections.emptyList();
    }
    for (ItemTransformer transformer : MappingUtils.getItemTransformers(connObjectKeyItem.get())) {
        List<Object> output = transformer.beforePull(connObjectKeyItem.get(), null, Collections.<Object>singletonList(connObjectKey));
        if (output != null && !output.isEmpty()) {
            connObjectKey = output.get(0).toString();
        }
    }
    List<String> result = new ArrayList<>();
    Realm realm;
    switch(connObjectKeyItem.get().getIntAttrName()) {
        case "key":
            realm = realmDAO.find(connObjectKey);
            if (realm != null) {
                result.add(realm.getKey());
            }
            break;
        case "name":
            result.addAll(realmDAO.findByName(connObjectKey).stream().map(Entity::getKey).collect(Collectors.toList()));
            break;
        case "fullpath":
            realm = realmDAO.findByFullPath(connObjectKey);
            if (realm != null) {
                result.add(realm.getKey());
            }
            break;
        default:
    }
    return result;
}
Also used : Entity(org.apache.syncope.core.persistence.api.entity.Entity) Attribute(org.identityconnectors.framework.common.objects.Attribute) ItemTransformer(org.apache.syncope.core.provisioning.api.data.ItemTransformer) ArrayList(java.util.ArrayList) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) Realm(org.apache.syncope.core.persistence.api.entity.Realm)

Example 10 with Realm

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

the class DefaultRealmPushResultHandler method handle.

@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
public boolean handle(final String realmKey) {
    Realm realm = null;
    try {
        realm = realmDAO.find(realmKey);
        doHandle(realm);
        return true;
    } catch (IgnoreProvisionException e) {
        ProvisioningReport result = new ProvisioningReport();
        result.setOperation(ResourceOperation.NONE);
        result.setAnyType(realm == null ? null : REALM_TYPE);
        result.setStatus(ProvisioningReport.Status.IGNORE);
        result.setKey(realmKey);
        profile.getResults().add(result);
        LOG.warn("Ignoring during push", e);
        return true;
    } catch (JobExecutionException e) {
        LOG.error("Push failed", e);
        return false;
    }
}
Also used : JobExecutionException(org.quartz.JobExecutionException) Realm(org.apache.syncope.core.persistence.api.entity.Realm) IgnoreProvisionException(org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Realm (org.apache.syncope.core.persistence.api.entity.Realm)51 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)21 ArrayList (java.util.ArrayList)14 RealmTO (org.apache.syncope.common.lib.to.RealmTO)12 Group (org.apache.syncope.core.persistence.api.entity.group.Group)11 Transactional (org.springframework.transaction.annotation.Transactional)11 List (java.util.List)10 AnyUtils (org.apache.syncope.core.persistence.api.entity.AnyUtils)10 Collections (java.util.Collections)9 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 HashSet (java.util.HashSet)8 Set (java.util.Set)8 Collectors (java.util.stream.Collectors)7 StringUtils (org.apache.commons.lang3.StringUtils)7 Entity (org.apache.syncope.core.persistence.api.entity.Entity)7 AnyObject (org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject)7 PasswordPolicy (org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy)7 User (org.apache.syncope.core.persistence.api.entity.user.User)7 Date (java.util.Date)6