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));
}
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));
// ----------------------------------
}
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));
}
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);
}
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);
}
Aggregations