Search in sources :

Example 51 with PropagationByResource

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

the class PasswordReset method doExecute.

@Override
protected void doExecute(final String executionId) {
    User user = engine.getRuntimeService().getVariable(executionId, FlowableUserWorkflowAdapter.USER, User.class);
    String token = engine.getRuntimeService().getVariable(executionId, FlowableUserWorkflowAdapter.TOKEN, String.class);
    String password = engine.getRuntimeService().getVariable(executionId, FlowableUserWorkflowAdapter.PASSWORD, String.class);
    if (!user.checkToken(token)) {
        throw new WorkflowException(new IllegalArgumentException("Wrong token: " + token + " for " + user));
    }
    user.removeToken();
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(user.getKey());
    userPatch.setPassword(new PasswordPatch.Builder().onSyncope(true).resources(userDAO.findAllResourceKeys(user.getKey())).value(password).build());
    PropagationByResource propByRes = dataBinder.update(user, userPatch);
    // report updated user and propagation by resource as result
    engine.getRuntimeService().setVariable(executionId, FlowableUserWorkflowAdapter.USER, user);
    engine.getRuntimeService().setVariable(executionId, FlowableUserWorkflowAdapter.USER_PATCH, userPatch);
    engine.getRuntimeService().setVariable(executionId, FlowableUserWorkflowAdapter.PROP_BY_RESOURCE, propByRes);
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) WorkflowException(org.apache.syncope.core.workflow.api.WorkflowException) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) UserPatch(org.apache.syncope.common.lib.patch.UserPatch)

Example 52 with PropagationByResource

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

the class DefaultAnyObjectWorkflowAdapter method doCreate.

@Override
protected WorkflowResult<String> doCreate(final AnyObjectTO anyObjectTO) {
    AnyObject anyObject = entityFactory.newEntity(AnyObject.class);
    dataBinder.create(anyObject, anyObjectTO);
    anyObject = anyObjectDAO.save(anyObject);
    PropagationByResource propByRes = new PropagationByResource();
    propByRes.set(ResourceOperation.CREATE, anyObjectDAO.findAllResourceKeys(anyObject.getKey()));
    return new WorkflowResult<>(anyObject.getKey(), propByRes, "create");
}
Also used : AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource)

Example 53 with PropagationByResource

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

the class DefaultUserWorkflowAdapter method doCreate.

@Override
protected WorkflowResult<Pair<String, Boolean>> doCreate(final UserTO userTO, final boolean disablePwdPolicyCheck, final Boolean enabled, final boolean storePassword) {
    User user = entityFactory.newEntity(User.class);
    dataBinder.create(user, userTO, storePassword);
    // this will make UserValidator not to consider password policies at all
    if (disablePwdPolicyCheck) {
        user.removeClearPassword();
    }
    String status;
    boolean propagateEnable;
    if (enabled == null) {
        status = "created";
        propagateEnable = true;
    } else {
        status = enabled ? "active" : "suspended";
        propagateEnable = enabled;
        user.setSuspended(!enabled);
    }
    user.setStatus(status);
    user = userDAO.save(user);
    PropagationByResource propByRes = new PropagationByResource();
    propByRes.set(ResourceOperation.CREATE, userDAO.findAllResourceKeys(user.getKey()));
    return new WorkflowResult<>(Pair.of(user.getKey(), propagateEnable), propByRes, "create");
}
Also used : WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) User(org.apache.syncope.core.persistence.api.entity.user.User) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource)

Example 54 with PropagationByResource

use of org.apache.syncope.core.provisioning.api.PropagationByResource 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 55 with PropagationByResource

use of org.apache.syncope.core.provisioning.api.PropagationByResource 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)

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