Search in sources :

Example 96 with UserPatch

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

the class AutoActivate method doExecute.

@Override
protected void doExecute(final String executionId) {
    User user = engine.getRuntimeService().getVariable(executionId, FlowableUserWorkflowAdapter.USER, User.class);
    UserTO userTO = engine.getRuntimeService().getVariable(executionId, FlowableUserWorkflowAdapter.USER_TO, UserTO.class);
    if (userTO != null && userTO.getKey() != null && user.getKey() != null) {
        user = userDAO.save(user);
        UserPatch userPatch = AnyOperations.diff(userTO, dataBinder.getUserTO(user, true), false);
        // don't mess with password, as the cleartext values was already properly saved
        userPatch.setPassword(null);
        dataBinder.update(user, userPatch);
        engine.getRuntimeService().setVariable(executionId, FlowableUserWorkflowAdapter.USER, user);
    }
    engine.getRuntimeService().setVariable(executionId, FlowableUserWorkflowAdapter.PROPAGATE_ENABLE, Boolean.TRUE);
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) UserTO(org.apache.syncope.common.lib.to.UserTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch)

Example 97 with UserPatch

use of org.apache.syncope.common.lib.patch.UserPatch 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 98 with UserPatch

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

the class UserRestClient method mustChangePassword.

public ProvisioningResult<UserTO> mustChangePassword(final String etag, final boolean value, final String key) {
    final UserPatch userPatch = new UserPatch();
    userPatch.setKey(key);
    userPatch.setMustChangePassword(new BooleanReplacePatchItem.Builder().value(value).build());
    return update(etag, userPatch);
}
Also used : BooleanReplacePatchItem(org.apache.syncope.common.lib.patch.BooleanReplacePatchItem) UserPatch(org.apache.syncope.common.lib.patch.UserPatch)

Example 99 with UserPatch

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

the class UserWizardBuilder method onApplyInternal.

@Override
protected Serializable onApplyInternal(final AnyWrapper<UserTO> modelObject) {
    UserTO inner = modelObject.getInnerObject();
    ProvisioningResult<UserTO> actual;
    if (inner.getKey() == null) {
        actual = userRestClient.create(inner, modelObject instanceof UserWrapper ? UserWrapper.class.cast(modelObject).isStorePasswordInSyncope() : StringUtils.isNotBlank(inner.getPassword()));
    } else {
        UserPatch patch = AnyOperations.diff(inner, getOriginalItem().getInnerObject(), false);
        if (StringUtils.isNotBlank(inner.getPassword())) {
            PasswordPatch passwordPatch = new PasswordPatch.Builder().value(inner.getPassword()).onSyncope(true).resources(inner.getResources()).build();
            patch.setPassword(passwordPatch);
        }
        // update just if it is changed
        if (patch.isEmpty()) {
            actual = new ProvisioningResult<>();
            actual.setEntity(inner);
        } else {
            actual = userRestClient.update(getOriginalItem().getInnerObject().getETagValue(), patch);
        }
    }
    return actual;
}
Also used : PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) UserTO(org.apache.syncope.common.lib.to.UserTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch)

Example 100 with UserPatch

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

the class UserLogic method doUpdate.

protected ProvisioningResult<UserTO> doUpdate(final UserPatch userPatch, final boolean self, final boolean nullPriorityAsync) {
    UserTO userTO = binder.getUserTO(userPatch.getKey());
    Set<String> dynRealmsBefore = new HashSet<>(userTO.getDynRealms());
    Pair<UserPatch, List<LogicActions>> before = beforeUpdate(userPatch, userTO.getRealm());
    boolean authDynRealms = false;
    if (!self && before.getLeft().getRealm() != null && StringUtils.isNotBlank(before.getLeft().getRealm().getValue())) {
        Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(StandardEntitlement.USER_UPDATE), before.getLeft().getRealm().getValue());
        authDynRealms = securityChecks(effectiveRealms, before.getLeft().getRealm().getValue(), before.getLeft().getKey());
    }
    Pair<UserPatch, List<PropagationStatus>> updated = provisioningManager.update(before.getLeft(), nullPriorityAsync);
    return afterUpdate(binder.returnUserTO(binder.getUserTO(updated.getLeft().getKey())), updated.getRight(), before.getRight(), authDynRealms, dynRealmsBefore);
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) List(java.util.List) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) HashSet(java.util.HashSet)

Aggregations

UserPatch (org.apache.syncope.common.lib.patch.UserPatch)102 UserTO (org.apache.syncope.common.lib.to.UserTO)73 Test (org.junit.jupiter.api.Test)59 PasswordPatch (org.apache.syncope.common.lib.patch.PasswordPatch)37 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)18 AttrTO (org.apache.syncope.common.lib.to.AttrTO)17 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)17 Response (javax.ws.rs.core.Response)16 Map (java.util.Map)12 StringReplacePatchItem (org.apache.syncope.common.lib.patch.StringReplacePatchItem)12 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)11 GroupTO (org.apache.syncope.common.lib.to.GroupTO)11 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)11 WorkflowResult (org.apache.syncope.core.provisioning.api.WorkflowResult)11 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)11 GenericType (javax.ws.rs.core.GenericType)10 Pair (org.apache.commons.lang3.tuple.Pair)10 PatchOperation (org.apache.syncope.common.lib.types.PatchOperation)10 List (java.util.List)9 AttrPatch (org.apache.syncope.common.lib.patch.AttrPatch)9