Search in sources :

Example 6 with UserPatch

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

the class DefaultUserWorkflowAdapter method doUpdate.

@Override
protected WorkflowResult<Pair<UserPatch, Boolean>> doUpdate(final User user, final UserPatch userPatch) {
    UserTO original = dataBinder.getUserTO(user, true);
    PropagationByResource propByRes = dataBinder.update(user, userPatch);
    PasswordPatch password = userPatch.getPassword();
    Set<AttrTO> virAttrs = userPatch.getVirAttrs();
    UserTO updated = dataBinder.getUserTO(userDAO.save(user), true);
    UserPatch effectivePatch = AnyOperations.diff(updated, original, false);
    effectivePatch.setPassword(password);
    effectivePatch.getVirAttrs().clear();
    effectivePatch.getVirAttrs().addAll(virAttrs);
    return new WorkflowResult<>(Pair.of(effectivePatch, !user.isSuspended()), propByRes, "update");
}
Also used : WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) UserTO(org.apache.syncope.common.lib.to.UserTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) UserPatch(org.apache.syncope.common.lib.patch.UserPatch)

Example 7 with UserPatch

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

the class DefaultUserWorkflowAdapter method doConfirmPasswordReset.

@Override
protected WorkflowResult<Pair<UserPatch, Boolean>> doConfirmPasswordReset(final User user, final String token, final String password) {
    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());
    return doUpdate(user, userPatch);
}
Also used : PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) WorkflowException(org.apache.syncope.core.workflow.api.WorkflowException) UserPatch(org.apache.syncope.common.lib.patch.UserPatch)

Example 8 with UserPatch

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

the class UserITCase method updateMultivalueAttribute.

@Test
public void updateMultivalueAttribute() {
    UserTO userTO = getUniqueSampleTO("multivalue@syncope.apache.org");
    userTO.getResources().clear();
    userTO.getVirAttrs().clear();
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    AttrTO loginDate = userTO.getPlainAttr("loginDate").get();
    assertNotNull(loginDate);
    assertEquals(1, loginDate.getValues().size());
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    loginDate.getValues().add("2000-01-01");
    userPatch.getPlainAttrs().add(new AttrPatch.Builder().operation(PatchOperation.ADD_REPLACE).attrTO(loginDate).build());
    userTO = updateUser(userPatch).getEntity();
    assertNotNull(userTO);
    loginDate = userTO.getPlainAttr("loginDate").get();
    assertNotNull(loginDate);
    assertEquals(2, loginDate.getValues().size());
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 9 with UserPatch

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

the class UserITCase method updateSamePassword.

@Test
public void updateSamePassword() {
    assertThrows(SyncopeClientException.class, () -> {
        UserTO userTO = getUniqueSampleTO("updatesame@password.com");
        userTO.setRealm("/even/two");
        userTO = createUser(userTO).getEntity();
        assertNotNull(userTO);
        UserPatch userPatch = new UserPatch();
        userPatch.setKey(userTO.getKey());
        userPatch.setPassword(new PasswordPatch.Builder().value("password123").build());
        userService.update(userPatch);
    });
}
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) Test(org.junit.jupiter.api.Test)

Example 10 with UserPatch

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

the class UserITCase method verifyTaskRegistration.

@SuppressWarnings("unchecked")
@Test
public void verifyTaskRegistration() {
    // get task list
    PagedResult<PropagationTaskTO> tasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).page(1).size(1).build());
    assertNotNull(tasks);
    assertFalse(tasks.getResult().isEmpty());
    String maxKey = tasks.getResult().iterator().next().getKey();
    // --------------------------------------
    // Create operation
    // --------------------------------------
    UserTO userTO = getUniqueSampleTO("t@p.mode");
    // add a membership
    userTO.getMemberships().add(new MembershipTO.Builder().group("f779c0d4-633b-4be5-8f57-32eb478a3ca5").build());
    // 1. create user
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    // get the new task list
    tasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).page(1).size(1).build());
    assertNotNull(tasks);
    assertFalse(tasks.getResult().isEmpty());
    String newMaxKey = tasks.getResult().iterator().next().getKey();
    // default configuration for ws-target-resource2 during create:
    // only failed executions have to be registered
    // --> no more tasks/executions should be added
    assertEquals(newMaxKey, maxKey);
    // --------------------------------------
    // Update operation
    // --------------------------------------
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.getPlainAttrs().add(attrAddReplacePatch("surname", "surname2"));
    userTO = updateUser(userPatch).getEntity();
    assertNotNull(userTO);
    // get the new task list
    tasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).page(1).size(1).build());
    // default configuration for ws-target-resource2 during update:
    // all update executions have to be registered
    newMaxKey = tasks.getResult().iterator().next().getKey();
    PropagationTaskTO taskTO = taskService.read(TaskType.PROPAGATION, newMaxKey, true);
    assertNotNull(taskTO);
    assertEquals(1, taskTO.getExecutions().size());
    // --------------------------------------
    // Delete operation
    // --------------------------------------
    userService.delete(userTO.getKey());
    // get the new task list
    tasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).page(1).size(1).build());
    maxKey = newMaxKey;
    newMaxKey = tasks.getResult().iterator().next().getKey();
    // default configuration for ws-target-resource2: no delete executions have to be registered
    // --> no more tasks/executions should be added
    assertEquals(newMaxKey, maxKey);
}
Also used : PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) UserTO(org.apache.syncope.common.lib.to.UserTO) TaskQuery(org.apache.syncope.common.rest.api.beans.TaskQuery) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

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