Search in sources :

Example 36 with PropagationByResource

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

the class ProvisionProducer 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 (getAnyTypeKind() == AnyTypeKind.USER) {
        Boolean changePwd = exchange.getProperty("changePwd", Boolean.class);
        String password = exchange.getProperty("password", String.class);
        UserPatch userPatch = new UserPatch();
        userPatch.setKey(key);
        userPatch.getResources().addAll(resources.stream().map(resource -> new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(resource).build()).collect(Collectors.toList()));
        if (changePwd) {
            userPatch.setPassword(new PasswordPatch.Builder().onSyncope(true).value(password).resources(resources).build());
        }
        PropagationByResource propByRes = new PropagationByResource();
        propByRes.addAll(ResourceOperation.UPDATE, resources);
        WorkflowResult<Pair<UserPatch, Boolean>> wfResult = new WorkflowResult<>(ImmutablePair.of(userPatch, (Boolean) null), propByRes, "update");
        List<PropagationTaskTO> tasks = getPropagationManager().getUserUpdateTasks(wfResult, changePwd, null);
        PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
        exchange.getOut().setBody(propagationReporter.getStatuses());
    } else {
        PropagationByResource propByRes = new PropagationByResource();
        propByRes.addAll(ResourceOperation.UPDATE, resources);
        AnyTypeKind anyTypeKind = AnyTypeKind.GROUP;
        if (getAnyTypeKind() != null) {
            anyTypeKind = getAnyTypeKind();
        }
        List<PropagationTaskTO> tasks = getPropagationManager().getUpdateTasks(anyTypeKind, key, false, null, propByRes, null, null);
        PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
        exchange.getOut().setBody(propagationReporter.getStatuses());
    }
}
Also used : WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) 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) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Pair(org.apache.commons.lang3.tuple.Pair)

Example 37 with PropagationByResource

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

the class PropagationManagerImpl method getUserUpdateTasks.

@Override
public List<PropagationTaskTO> getUserUpdateTasks(final WorkflowResult<Pair<UserPatch, Boolean>> wfResult) {
    UserPatch userPatch = wfResult.getResult().getKey();
    // Propagate password update only to requested resources
    List<PropagationTaskTO> tasks = new ArrayList<>();
    if (userPatch.getPassword() == null) {
        // a. no specific password propagation request: generate propagation tasks for any resource associated
        tasks = getUserUpdateTasks(wfResult, false, null);
    } else {
        // b. generate the propagation task list in two phases: first the ones containing password,
        // the the rest (with no password)
        WorkflowResult<Pair<UserPatch, Boolean>> pwdWFResult = new WorkflowResult<>(wfResult.getResult(), new PropagationByResource(), wfResult.getPerformedTasks());
        Set<String> pwdResourceNames = new HashSet<>(userPatch.getPassword().getResources());
        Collection<String> allResourceNames = userDAO.findAllResourceKeys(userPatch.getKey());
        pwdResourceNames.retainAll(allResourceNames);
        pwdWFResult.getPropByRes().addAll(ResourceOperation.UPDATE, pwdResourceNames);
        if (!pwdWFResult.getPropByRes().isEmpty()) {
            Set<String> toBeExcluded = new HashSet<>(allResourceNames);
            toBeExcluded.addAll(userPatch.getResources().stream().map(patchItem -> patchItem.getValue()).collect(Collectors.toList()));
            toBeExcluded.removeAll(pwdResourceNames);
            tasks.addAll(getUserUpdateTasks(pwdWFResult, true, toBeExcluded));
        }
        WorkflowResult<Pair<UserPatch, Boolean>> noPwdWFResult = new WorkflowResult<>(wfResult.getResult(), new PropagationByResource(), wfResult.getPerformedTasks());
        noPwdWFResult.getPropByRes().merge(wfResult.getPropByRes());
        noPwdWFResult.getPropByRes().removeAll(pwdResourceNames);
        noPwdWFResult.getPropByRes().purge();
        if (!noPwdWFResult.getPropByRes().isEmpty()) {
            tasks.addAll(getUserUpdateTasks(noPwdWFResult, false, pwdResourceNames));
        }
    }
    return tasks;
}
Also used : WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) ArrayList(java.util.ArrayList) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Pair(org.apache.commons.lang3.tuple.Pair) HashSet(java.util.HashSet)

Example 38 with PropagationByResource

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

the class PropagationManagerImpl method getDeleteTasks.

@Override
public List<PropagationTaskTO> getDeleteTasks(final AnyTypeKind kind, final String key, final PropagationByResource propByRes, final Collection<String> noPropResourceKeys) {
    Any<?> any = dao(kind).authFind(key);
    PropagationByResource localPropByRes = new PropagationByResource();
    if (propByRes == null || propByRes.isEmpty()) {
        localPropByRes.addAll(ResourceOperation.DELETE, dao(kind).findAllResourceKeys(key));
    } else {
        localPropByRes.merge(propByRes);
    }
    if (noPropResourceKeys != null) {
        localPropByRes.removeAll(noPropResourceKeys);
    }
    return getDeleteTasks(any, localPropByRes, noPropResourceKeys);
}
Also used : PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource)

Example 39 with PropagationByResource

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

the class GroupDataBinderImpl method update.

@Override
public PropagationByResource update(final Group toBeUpdated, final GroupPatch groupPatch) {
    // Re-merge any pending change from workflow tasks
    Group group = groupDAO.save(toBeUpdated);
    PropagationByResource propByRes = new PropagationByResource();
    SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
    AnyUtils anyUtils = anyUtilsFactory.getInstance(AnyTypeKind.GROUP);
    // fetch connObjectKeys before update
    Map<String, String> oldConnObjectKeys = getConnObjectKeys(group, anyUtils);
    // realm
    setRealm(group, groupPatch);
    // name
    if (groupPatch.getName() != null && StringUtils.isNotBlank(groupPatch.getName().getValue())) {
        propByRes.addAll(ResourceOperation.UPDATE, groupDAO.findAllResourceKeys(group.getKey()));
        group.setName(groupPatch.getName().getValue());
    }
    // owner
    if (groupPatch.getUserOwner() != null) {
        group.setUserOwner(groupPatch.getUserOwner().getValue() == null ? null : userDAO.find(groupPatch.getUserOwner().getValue()));
    }
    if (groupPatch.getGroupOwner() != null) {
        group.setGroupOwner(groupPatch.getGroupOwner().getValue() == null ? null : groupDAO.find(groupPatch.getGroupOwner().getValue()));
    }
    // attributes and resources
    propByRes.merge(fill(group, groupPatch, anyUtils, scce));
    // check if some connObjectKey was changed by the update above
    Map<String, String> newConnObjectKeys = getConnObjectKeys(group, anyUtils);
    oldConnObjectKeys.entrySet().stream().filter(entry -> newConnObjectKeys.containsKey(entry.getKey()) && !entry.getValue().equals(newConnObjectKeys.get(entry.getKey()))).forEach(entry -> {
        propByRes.addOldConnObjectKey(entry.getKey(), entry.getValue());
        propByRes.add(ResourceOperation.UPDATE, entry.getKey());
    });
    group = groupDAO.save(group);
    // dynamic membership
    if (groupPatch.getUDynMembershipCond() == null) {
        if (group.getUDynMembership() != null) {
            group.getUDynMembership().setGroup(null);
            group.setUDynMembership(null);
            groupDAO.clearUDynMembers(group);
        }
    } else {
        setDynMembership(group, anyTypeDAO.findUser(), groupPatch.getUDynMembershipCond());
    }
    for (Iterator<? extends ADynGroupMembership> itor = group.getADynMemberships().iterator(); itor.hasNext(); ) {
        ADynGroupMembership memb = itor.next();
        memb.setGroup(null);
        itor.remove();
    }
    groupDAO.clearADynMembers(group);
    for (Map.Entry<String, String> entry : groupPatch.getADynMembershipConds().entrySet()) {
        AnyType anyType = anyTypeDAO.find(entry.getKey());
        if (anyType == null) {
            LOG.warn("Ignoring invalid {}: {}", AnyType.class.getSimpleName(), entry.getKey());
        } else {
            setDynMembership(group, anyType, entry.getValue());
        }
    }
    // type extensions
    for (TypeExtensionTO typeExtTO : groupPatch.getTypeExtensions()) {
        AnyType anyType = anyTypeDAO.find(typeExtTO.getAnyType());
        if (anyType == null) {
            LOG.warn("Ignoring invalid {}: {}", AnyType.class.getSimpleName(), typeExtTO.getAnyType());
        } else {
            TypeExtension typeExt = group.getTypeExtension(anyType).orElse(null);
            if (typeExt == null) {
                typeExt = entityFactory.newEntity(TypeExtension.class);
                typeExt.setAnyType(anyType);
                typeExt.setGroup(group);
                group.add(typeExt);
            }
            // add all classes contained in the TO
            for (String name : typeExtTO.getAuxClasses()) {
                AnyTypeClass anyTypeClass = anyTypeClassDAO.find(name);
                if (anyTypeClass == null) {
                    LOG.warn("Ignoring invalid {}: {}", AnyTypeClass.class.getSimpleName(), name);
                } else {
                    typeExt.add(anyTypeClass);
                }
            }
            // remove all classes not contained in the TO
            typeExt.getAuxClasses().removeIf(anyTypeClass -> !typeExtTO.getAuxClasses().contains(anyTypeClass.getKey()));
            // only consider non-empty type extensions
            if (typeExt.getAuxClasses().isEmpty()) {
                group.getTypeExtensions().remove(typeExt);
                typeExt.setGroup(null);
            }
        }
    }
    // remove all type extensions not contained in the TO
    group.getTypeExtensions().removeIf(typeExt -> !groupPatch.getTypeExtension(typeExt.getAnyType().getKey()).isPresent());
    // Throw composite exception if there is at least one element set in the composing exceptions
    if (scce.hasExceptions()) {
        throw scce;
    }
    return propByRes;
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Realm(org.apache.syncope.core.persistence.api.entity.Realm) UDynGroupMembership(org.apache.syncope.core.persistence.api.entity.user.UDynGroupMembership) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) Entity(org.apache.syncope.core.persistence.api.entity.Entity) ResourceOperation(org.apache.syncope.common.lib.types.ResourceOperation) StringUtils(org.apache.commons.lang3.StringUtils) GroupDataBinder(org.apache.syncope.core.provisioning.api.data.GroupDataBinder) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) Map(java.util.Map) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) SearchCondConverter(org.apache.syncope.core.persistence.api.search.SearchCondConverter) SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) TypeExtension(org.apache.syncope.core.persistence.api.entity.group.TypeExtension) Iterator(java.util.Iterator) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) User(org.apache.syncope.core.persistence.api.entity.user.User) ADynGroupMembership(org.apache.syncope.core.persistence.api.entity.anyobject.ADynGroupMembership) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Collectors(java.util.stream.Collectors) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) DynGroupMembership(org.apache.syncope.core.persistence.api.entity.DynGroupMembership) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) List(java.util.List) Component(org.springframework.stereotype.Component) TypeExtensionTO(org.apache.syncope.common.lib.to.TypeExtensionTO) Group(org.apache.syncope.core.persistence.api.entity.group.Group) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) Collections(java.util.Collections) Any(org.apache.syncope.core.persistence.api.entity.Any) Transactional(org.springframework.transaction.annotation.Transactional) Group(org.apache.syncope.core.persistence.api.entity.group.Group) SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) TypeExtension(org.apache.syncope.core.persistence.api.entity.group.TypeExtension) ADynGroupMembership(org.apache.syncope.core.persistence.api.entity.anyobject.ADynGroupMembership) TypeExtensionTO(org.apache.syncope.common.lib.to.TypeExtensionTO) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) HashMap(java.util.HashMap) Map(java.util.Map) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass)

Example 40 with PropagationByResource

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

the class DefaultRealmPushResultHandler method update.

private Realm update(final RealmTO realmTO, final ProvisioningReport result) {
    Realm realm = realmDAO.findByFullPath(realmTO.getFullPath());
    PropagationByResource propByRes = binder.update(realm, realmTO);
    realm = realmDAO.save(realm);
    PropagationReporter reporter = taskExecutor.execute(propagationManager.createTasks(realm, propByRes, null), false);
    reportPropagation(result, reporter);
    return realm;
}
Also used : PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) Realm(org.apache.syncope.core.persistence.api.entity.Realm)

Aggregations

PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)56 PropagationReporter (org.apache.syncope.core.provisioning.api.propagation.PropagationReporter)23 PropagationTaskTO (org.apache.syncope.common.lib.to.PropagationTaskTO)21 WorkflowResult (org.apache.syncope.core.provisioning.api.WorkflowResult)19 Realm (org.apache.syncope.core.persistence.api.entity.Realm)13 ArrayList (java.util.ArrayList)12 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)12 User (org.apache.syncope.core.persistence.api.entity.user.User)12 HashMap (java.util.HashMap)11 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)11 Transactional (org.springframework.transaction.annotation.Transactional)10 PropagationException (org.apache.syncope.core.provisioning.api.propagation.PropagationException)9 Pair (org.apache.commons.lang3.tuple.Pair)8 List (java.util.List)7 RealmTO (org.apache.syncope.common.lib.to.RealmTO)7 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)7 Map (java.util.Map)6 Collectors (java.util.stream.Collectors)6 PasswordPatch (org.apache.syncope.common.lib.patch.PasswordPatch)6 AttrTO (org.apache.syncope.common.lib.to.AttrTO)6