Search in sources :

Example 46 with PropagationTaskTO

use of org.apache.syncope.common.lib.to.PropagationTaskTO in project syncope by apache.

the class RealmLogic method update.

@PreAuthorize("hasRole('" + StandardEntitlement.REALM_UPDATE + "')")
public ProvisioningResult<RealmTO> update(final RealmTO realmTO) {
    Realm realm = realmDAO.findByFullPath(realmTO.getFullPath());
    if (realm == null) {
        LOG.error("Could not find realm '" + realmTO.getFullPath() + "'");
        throw new NotFoundException(realmTO.getFullPath());
    }
    PropagationByResource propByRes = binder.update(realm, realmTO);
    realm = realmDAO.save(realm);
    List<PropagationTaskTO> tasks = propagationManager.createTasks(realm, propByRes, null);
    PropagationReporter propagationReporter = taskExecutor.execute(tasks, false);
    ProvisioningResult<RealmTO> result = new ProvisioningResult<>();
    result.setEntity(binder.getRealmTO(realm, true));
    result.getPropagationStatuses().addAll(propagationReporter.getStatuses());
    return result;
}
Also used : PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) RealmTO(org.apache.syncope.common.lib.to.RealmTO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) 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) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 47 with PropagationTaskTO

use of org.apache.syncope.common.lib.to.PropagationTaskTO in project syncope by apache.

the class RealmLogic method create.

@PreAuthorize("hasRole('" + StandardEntitlement.REALM_CREATE + "')")
public ProvisioningResult<RealmTO> create(final String parentPath, final RealmTO realmTO) {
    Realm parent;
    if (StringUtils.isBlank(realmTO.getParent())) {
        parent = realmDAO.findByFullPath(parentPath);
        if (parent == null) {
            LOG.error("Could not find parent realm " + parentPath);
            throw new NotFoundException(parentPath);
        }
        realmTO.setParent(parent.getFullPath());
    } else {
        parent = realmDAO.find(realmTO.getParent());
        if (parent == null) {
            LOG.error("Could not find parent realm " + realmTO.getParent());
            throw new NotFoundException(realmTO.getParent());
        }
        if (!parent.getFullPath().equals(parentPath)) {
            SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidPath);
            sce.getElements().add("Mismatching parent realm: " + parentPath + " Vs " + parent.getFullPath());
            throw sce;
        }
    }
    String fullPath = StringUtils.appendIfMissing(parent.getFullPath(), "/") + realmTO.getName();
    if (realmDAO.findByFullPath(fullPath) != null) {
        throw new DuplicateException(fullPath);
    }
    Realm realm = realmDAO.save(binder.create(parent, realmTO));
    PropagationByResource propByRes = new PropagationByResource();
    realm.getResourceKeys().forEach(resource -> {
        propByRes.add(ResourceOperation.CREATE, resource);
    });
    List<PropagationTaskTO> tasks = propagationManager.createTasks(realm, propByRes, null);
    PropagationReporter propagationReporter = taskExecutor.execute(tasks, false);
    ProvisioningResult<RealmTO> result = new ProvisioningResult<>();
    result.setEntity(binder.getRealmTO(realm, true));
    result.getPropagationStatuses().addAll(propagationReporter.getStatuses());
    return result;
}
Also used : PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) DuplicateException(org.apache.syncope.core.persistence.api.dao.DuplicateException) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) RealmTO(org.apache.syncope.common.lib.to.RealmTO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) 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) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 48 with PropagationTaskTO

use of org.apache.syncope.common.lib.to.PropagationTaskTO in project syncope by apache.

the class RealmLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.REALM_DELETE + "')")
public ProvisioningResult<RealmTO> delete(final String fullPath) {
    Realm realm = realmDAO.findByFullPath(fullPath);
    if (realm == null) {
        LOG.error("Could not find realm '" + fullPath + "'");
        throw new NotFoundException(fullPath);
    }
    if (!realmDAO.findChildren(realm).isEmpty()) {
        throw SyncopeClientException.build(ClientExceptionType.HasChildren);
    }
    Set<String> adminRealms = Collections.singleton(realm.getFullPath());
    AnyCond keyCond = new AnyCond(AttributeCond.Type.ISNOTNULL);
    keyCond.setSchema("key");
    SearchCond allMatchingCond = SearchCond.getLeafCond(keyCond);
    int users = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.USER);
    int groups = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.GROUP);
    int anyObjects = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.ANY_OBJECT);
    if (users + groups + anyObjects > 0) {
        SyncopeClientException containedAnys = SyncopeClientException.build(ClientExceptionType.AssociatedAnys);
        containedAnys.getElements().add(users + " user(s)");
        containedAnys.getElements().add(groups + " group(s)");
        containedAnys.getElements().add(anyObjects + " anyObject(s)");
        throw containedAnys;
    }
    PropagationByResource propByRes = new PropagationByResource();
    realm.getResourceKeys().forEach(resource -> {
        propByRes.add(ResourceOperation.DELETE, resource);
    });
    List<PropagationTaskTO> tasks = propagationManager.createTasks(realm, propByRes, null);
    PropagationReporter propagationReporter = taskExecutor.execute(tasks, false);
    ProvisioningResult<RealmTO> result = new ProvisioningResult<>();
    result.setEntity(binder.getRealmTO(realm, true));
    result.getPropagationStatuses().addAll(propagationReporter.getStatuses());
    realmDAO.delete(realm);
    return result;
}
Also used : PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) RealmTO(org.apache.syncope.common.lib.to.RealmTO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Realm(org.apache.syncope.core.persistence.api.entity.Realm) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

PropagationTaskTO (org.apache.syncope.common.lib.to.PropagationTaskTO)48 PropagationReporter (org.apache.syncope.core.provisioning.api.propagation.PropagationReporter)29 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)21 Transactional (org.springframework.transaction.annotation.Transactional)11 Pair (org.apache.commons.lang3.tuple.Pair)10 ArrayList (java.util.ArrayList)9 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)9 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)9 WorkflowResult (org.apache.syncope.core.provisioning.api.WorkflowResult)9 List (java.util.List)8 PropagationException (org.apache.syncope.core.provisioning.api.propagation.PropagationException)8 Map (java.util.Map)7 Test (org.junit.jupiter.api.Test)7 RealmTO (org.apache.syncope.common.lib.to.RealmTO)6 Realm (org.apache.syncope.core.persistence.api.entity.Realm)6 HashSet (java.util.HashSet)5 Collectors (java.util.stream.Collectors)5 UserTO (org.apache.syncope.common.lib.to.UserTO)5 TaskQuery (org.apache.syncope.common.rest.api.beans.TaskQuery)5 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)5