Search in sources :

Example 91 with UserPatch

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

the class VirAttrITCase method virAttrCache.

@Test
public void virAttrCache() {
    UserTO userTO = UserITCase.getUniqueSampleTO("virattrcache@apache.org");
    userTO.getVirAttrs().clear();
    AttrTO virAttrTO = new AttrTO();
    virAttrTO.setSchema("virtualdata");
    virAttrTO.getValues().add("virattrcache");
    userTO.getVirAttrs().add(virAttrTO);
    userTO.getMemberships().clear();
    userTO.getResources().clear();
    userTO.getResources().add(RESOURCE_NAME_DBVIRATTR);
    // 1. create user
    UserTO actual = createUser(userTO).getEntity();
    assertNotNull(actual);
    // 2. check for virtual attribute value
    actual = userService.read(actual.getKey());
    assertEquals("virattrcache", actual.getVirAttr("virtualdata").get().getValues().get(0));
    // 3. update virtual attribute directly
    JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
    String value = queryForObject(jdbcTemplate, 50, "SELECT USERNAME FROM testpull WHERE ID=?", String.class, actual.getKey());
    assertEquals("virattrcache", value);
    jdbcTemplate.update("UPDATE testpull set USERNAME='virattrcache2' WHERE ID=?", actual.getKey());
    value = queryForObject(jdbcTemplate, 50, "SELECT USERNAME FROM testpull WHERE ID=?", String.class, actual.getKey());
    assertEquals("virattrcache2", value);
    // 4. check for cached attribute value
    actual = userService.read(actual.getKey());
    assertEquals("virattrcache", actual.getVirAttr("virtualdata").get().getValues().get(0));
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(actual.getKey());
    userPatch.getVirAttrs().add(attrTO("virtualdata", "virtualupdated"));
    // 5. update virtual attribute
    actual = updateUser(userPatch).getEntity();
    assertNotNull(actual);
    // 6. check for virtual attribute value
    actual = userService.read(actual.getKey());
    assertNotNull(actual);
    assertEquals("virtualupdated", actual.getVirAttr("virtualdata").get().getValues().get(0));
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 92 with UserPatch

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

the class VirAttrITCase method issueSYNCOPE260.

@Test
public void issueSYNCOPE260() {
    // create new virtual schema for the resource below
    ResourceTO ws2 = resourceService.read(RESOURCE_NAME_WS2);
    ProvisionTO provision = ws2.getProvision(AnyTypeKind.USER.name()).get();
    assertNotNull(provision);
    VirSchemaTO virSchema = new VirSchemaTO();
    virSchema.setKey("syncope260" + getUUIDString());
    virSchema.setExtAttrName("companyName");
    virSchema.setResource(RESOURCE_NAME_WS2);
    virSchema.setAnyType(provision.getAnyType());
    virSchema = createSchema(SchemaType.VIRTUAL, virSchema);
    assertNotNull(virSchema);
    AnyTypeClassTO newClass = new AnyTypeClassTO();
    newClass.setKey("syncope260" + getUUIDString());
    newClass.getVirSchemas().add(virSchema.getKey());
    Response response = anyTypeClassService.create(newClass);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
    newClass = getObject(response.getLocation(), AnyTypeClassService.class, AnyTypeClassTO.class);
    // ----------------------------------
    // create user and check virtual attribute value propagation
    // ----------------------------------
    UserTO userTO = UserITCase.getUniqueSampleTO("260@a.com");
    userTO.getAuxClasses().add(newClass.getKey());
    userTO.getVirAttrs().add(attrTO(virSchema.getKey(), "virtualvalue"));
    userTO.getResources().add(RESOURCE_NAME_WS2);
    ProvisioningResult<UserTO> result = createUser(userTO);
    assertNotNull(result);
    assertFalse(result.getPropagationStatuses().isEmpty());
    assertEquals(RESOURCE_NAME_WS2, result.getPropagationStatuses().get(0).getResource());
    assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
    userTO = result.getEntity();
    ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
    assertEquals("virtualvalue", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
    // ----------------------------------
    // ----------------------------------
    // update user virtual attribute and check virtual attribute value update propagation
    // ----------------------------------
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.getVirAttrs().add(attrTO(virSchema.getKey(), "virtualvalue2"));
    result = updateUser(userPatch);
    assertNotNull(result);
    assertFalse(result.getPropagationStatuses().isEmpty());
    assertEquals(RESOURCE_NAME_WS2, result.getPropagationStatuses().get(0).getResource());
    assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
    userTO = result.getEntity();
    connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
    assertEquals("virtualvalue2", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
    // ----------------------------------
    // ----------------------------------
    // suspend/reactivate user and check virtual attribute value (unchanged)
    // ----------------------------------
    StatusPatch statusPatch = new StatusPatch.Builder().key(userTO.getKey()).type(StatusPatchType.SUSPEND).build();
    userTO = userService.status(statusPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    }).getEntity();
    assertEquals("suspended", userTO.getStatus());
    connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
    assertEquals("virtualvalue2", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
    statusPatch = new StatusPatch.Builder().key(userTO.getKey()).type(StatusPatchType.REACTIVATE).build();
    userTO = userService.status(statusPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    }).getEntity();
    assertEquals("active", userTO.getStatus());
    connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
    assertEquals("virtualvalue2", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
    // ----------------------------------
    // ----------------------------------
    // update user attribute and check virtual attribute value (unchanged)
    // ----------------------------------
    userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.getPlainAttrs().add(attrAddReplacePatch("surname", "Surname2"));
    result = updateUser(userPatch);
    assertNotNull(result);
    assertFalse(result.getPropagationStatuses().isEmpty());
    assertEquals(RESOURCE_NAME_WS2, result.getPropagationStatuses().get(0).getResource());
    assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
    userTO = result.getEntity();
    connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
    assertEquals("Surname2", connObjectTO.getAttr("SURNAME").get().getValues().get(0));
    // virtual attribute value did not change
    assertFalse(connObjectTO.getAttr("COMPANYNAME").get().getValues().isEmpty());
    assertEquals("virtualvalue2", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
// ----------------------------------
}
Also used : ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Response(javax.ws.rs.core.Response) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) AnyTypeClassService(org.apache.syncope.common.rest.api.service.AnyTypeClassService) UserTO(org.apache.syncope.common.lib.to.UserTO) StatusPatch(org.apache.syncope.common.lib.patch.StatusPatch) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) Test(org.junit.jupiter.api.Test)

Example 93 with UserPatch

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

the class VirAttrITCase method issueSYNCOPE501.

@Test
public void issueSYNCOPE501() {
    // 1. create user and propagate him on resource-db-virattr
    UserTO userTO = UserITCase.getUniqueSampleTO("syncope501@apache.org");
    userTO.getResources().clear();
    userTO.getMemberships().clear();
    userTO.getVirAttrs().clear();
    userTO.getResources().add(RESOURCE_NAME_DBVIRATTR);
    // virtualdata is mapped with username
    userTO.getVirAttrs().add(attrTO("virtualdata", "syncope501@apache.org"));
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO.getVirAttr("virtualdata"));
    assertEquals("syncope501@apache.org", userTO.getVirAttr("virtualdata").get().getValues().get(0));
    // 2. update virtual attribute
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    // change virtual attribute value
    userPatch.getVirAttrs().add(attrTO("virtualdata", "syncope501_updated@apache.org"));
    userTO = updateUser(userPatch).getEntity();
    assertNotNull(userTO);
    // 3. check that user virtual attribute has really been updated
    assertFalse(userTO.getVirAttr("virtualdata").get().getValues().isEmpty());
    assertEquals("syncope501_updated@apache.org", userTO.getVirAttr("virtualdata").get().getValues().get(0));
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 94 with UserPatch

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

the class FlowableUserWorkflowAdapter method submitForm.

@Override
public WorkflowResult<UserPatch> submitForm(final WorkflowFormTO form) {
    String authUser = AuthContextUtils.getUsername();
    Pair<Task, TaskFormData> checked = checkTask(form.getTaskId(), authUser);
    if (!checked.getKey().getOwner().equals(authUser)) {
        throw new WorkflowException(new IllegalArgumentException("Task " + form.getTaskId() + " assigned to " + checked.getKey().getOwner() + " but submitted by " + authUser));
    }
    User user = userDAO.findByWorkflowId(checked.getKey().getProcessInstanceId());
    if (user == null) {
        throw new NotFoundException("User with workflow id " + checked.getKey().getProcessInstanceId());
    }
    Set<String> preTasks = getPerformedTasks(user);
    try {
        engine.getFormService().submitTaskFormData(form.getTaskId(), getPropertiesForSubmit(form));
        engine.getRuntimeService().setVariable(user.getWorkflowId(), FORM_SUBMITTER, authUser);
    } catch (FlowableException e) {
        throwException(e, "While submitting form for task " + form.getTaskId());
    }
    Set<String> postTasks = getPerformedTasks(user);
    postTasks.removeAll(preTasks);
    postTasks.add(form.getTaskId());
    updateStatus(user);
    User updated = userDAO.save(user);
    // see if there is any propagation to be done
    PropagationByResource propByRes = engine.getRuntimeService().getVariable(user.getWorkflowId(), PROP_BY_RESOURCE, PropagationByResource.class);
    // fetch - if available - the encrypted password
    String clearPassword = null;
    String encryptedPwd = engine.getRuntimeService().getVariable(user.getWorkflowId(), ENCRYPTED_PWD, String.class);
    if (StringUtils.isNotBlank(encryptedPwd)) {
        clearPassword = decrypt(encryptedPwd);
    }
    // supports approval chains
    saveForFormSubmit(user, clearPassword, propByRes);
    UserPatch userPatch = engine.getRuntimeService().getVariable(user.getWorkflowId(), USER_PATCH, UserPatch.class);
    if (userPatch == null) {
        userPatch = new UserPatch();
        userPatch.setKey(updated.getKey());
        userPatch.setPassword(new PasswordPatch.Builder().onSyncope(true).value(clearPassword).build());
        if (propByRes != null) {
            userPatch.getPassword().getResources().addAll(propByRes.get(ResourceOperation.CREATE));
        }
    }
    return new WorkflowResult<>(userPatch, propByRes, postTasks);
}
Also used : Task(org.flowable.task.api.Task) WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) User(org.apache.syncope.core.persistence.api.entity.user.User) WorkflowException(org.apache.syncope.core.workflow.api.WorkflowException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) TaskFormData(org.flowable.engine.form.TaskFormData) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) FlowableException(org.flowable.engine.common.api.FlowableException)

Example 95 with UserPatch

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

the class FlowableUserWorkflowAdapter method doUpdate.

@Override
protected WorkflowResult<Pair<UserPatch, Boolean>> doUpdate(final User user, final UserPatch userPatch) {
    Set<String> tasks = doExecuteTask(user, "update", Collections.singletonMap(USER_PATCH, (Object) userPatch));
    updateStatus(user);
    User updated = userDAO.save(user);
    PropagationByResource propByRes = engine.getRuntimeService().getVariable(user.getWorkflowId(), PROP_BY_RESOURCE, PropagationByResource.class);
    UserPatch updatedPatch = engine.getRuntimeService().getVariable(user.getWorkflowId(), USER_PATCH, UserPatch.class);
    saveForFormSubmit(updated, updatedPatch.getPassword() == null ? null : updatedPatch.getPassword().getValue(), propByRes);
    Boolean propagateEnable = engine.getRuntimeService().getVariable(user.getWorkflowId(), PROPAGATE_ENABLE, Boolean.class);
    return new WorkflowResult<>(Pair.of(updatedPatch, propagateEnable), propByRes, tasks);
}
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) UserPatch(org.apache.syncope.common.lib.patch.UserPatch)

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