use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.
the class PageAccountActivation method propagatePassword.
private void propagatePassword(AjaxRequestTarget target, Form<?> form) {
List<ShadowType> shadowsToActivate = getShadowsToActivate();
PasswordTextField passwordPanel = (PasswordTextField) form.get(createComponentPath(ID_PASSWORD));
String value = passwordPanel.getModelObject();
ConnectionEnvironment connEnv = ConnectionEnvironment.create(SchemaConstants.CHANNEL_GUI_USER_URI);
UsernamePasswordAuthenticationToken token;
try {
token = authenticationEvaluator.authenticate(connEnv, new PasswordAuthenticationContext(userModel.getObject().getName().getOrig(), value));
} catch (Exception ex) {
LOGGER.error("Failed to authenticate user, reason ", ex.getMessage());
getSession().error(getString("PageAccountActivation.authentication.failed"));
throw new RestartResponseException(PageAccountActivation.class, getPageParameters());
}
if (token == null) {
LOGGER.error("Failed to authenticate user");
getSession().error(getString("PageAccountActivation.authentication.failed"));
throw new RestartResponseException(PageAccountActivation.class, getPageParameters());
}
ProtectedStringType passwordValue = new ProtectedStringType();
passwordValue.setClearValue(value);
Collection<ObjectDelta<ShadowType>> passwordDeltas = new ArrayList<>(shadowsToActivate.size());
for (ShadowType shadow : shadowsToActivate) {
ObjectDelta<ShadowType> shadowDelta = ObjectDelta.createModificationReplaceProperty(ShadowType.class, shadow.getOid(), SchemaConstants.PATH_PASSWORD_VALUE, getPrismContext(), passwordValue);
shadowDelta.addModificationReplaceProperty(ShadowType.F_LIFECYCLE_STATE, SchemaConstants.LIFECYCLE_PROPOSED);
passwordDeltas.add(shadowDelta);
}
OperationResult result = runPrivileged(new Producer<OperationResult>() {
@Override
public OperationResult run() {
OperationResult result = new OperationResult(OPERATION_ACTIVATE_SHADOWS);
Task task = createAnonymousTask(OPERATION_ACTIVATE_SHADOWS);
WebModelServiceUtils.save((Collection) passwordDeltas, null, result, task, PageAccountActivation.this);
return result;
}
});
result.recomputeStatus();
if (!result.isSuccess()) {
getSession().error(getString("PageAccountActivation.account.activation.failed"));
LOGGER.error("Failed to acitvate accounts, reason: {} ", result.getMessage());
target.add(getFeedbackPanel());
} else {
getSession().success(getString("PageAccountActivation.account.activation.successful"));
target.add(getFeedbackPanel());
activated = true;
}
target.add(PageAccountActivation.this);
}
use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.
the class TestSchemaDelta method testSubtractAssignmentFromModifyDelta.
@Test
public void testSubtractAssignmentFromModifyDelta() throws Exception {
final String TEST_NAME = "testSubtractAssignmentFromModifyDelta";
displayTestTile(TEST_NAME);
// GIVEN
PrismObject<UserType> user = PrismTestUtil.parseObject(USER_BILL_FILE);
user.asObjectable().getAssignment().get(0).setId(9999L);
AssignmentType assignment9999 = new AssignmentType();
assignment9999.setId(9999L);
ObjectDelta<UserType> delta = (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, getPrismContext()).item(UserType.F_ASSIGNMENT).delete(assignment9999).asObjectDelta(user.getOid());
// WHEN
PrismContainerDefinition<AssignmentType> assignmentDef = PrismTestUtil.getSchemaRegistry().findContainerDefinitionByCompileTimeClass(AssignmentType.class).clone();
((PrismContainerDefinitionImpl) assignmentDef).setMaxOccurs(1);
PrismContainer<AssignmentType> assignmentContainer = assignmentDef.instantiate();
PrismContainerValue<AssignmentType> assignmentValue = ObjectTypeUtil.createAssignmentTo("00000001-d34d-b33f-f00d-000000000002", ObjectTypes.ROLE, getPrismContext()).asPrismContainerValue();
assignmentValue.setId(9999L);
assignmentContainer.add(assignmentValue);
System.out.println("Delta before operation:\n" + delta.debugDump() + "\n");
System.out.println("Assignment to subtract:\n" + assignmentValue.debugDump() + "\n");
boolean removed = delta.subtract(SchemaConstants.PATH_ASSIGNMENT, assignmentValue, true, false);
// THEN
System.out.println("Delta after operation:\n" + delta.debugDump() + "\n");
System.out.println("Removed: " + removed + "\n");
assertTrue("Not removed", removed);
assertTrue("Remaining delta is not a MODIFY delta", delta.isModify());
assertEquals("Wrong # of remaining modifications", 0, delta.getModifications().size());
}
use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.
the class ModelInteractionServiceImpl method previewChanges.
@Override
public <F extends ObjectType> ModelContext<F> previewChanges(Collection<ObjectDelta<? extends ObjectType>> deltas, ModelExecuteOptions options, Task task, Collection<ProgressListener> listeners, OperationResult parentResult) throws SchemaException, PolicyViolationException, ExpressionEvaluationException, ObjectNotFoundException, ObjectAlreadyExistsException, CommunicationException, ConfigurationException, SecurityViolationException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Preview changes input:\n{}", DebugUtil.debugDump(deltas));
}
int size = 0;
if (deltas != null) {
size = deltas.size();
}
Collection<ObjectDelta<? extends ObjectType>> clonedDeltas = new ArrayList<>(size);
if (deltas != null) {
for (ObjectDelta delta : deltas) {
clonedDeltas.add(delta.clone());
}
}
OperationResult result = parentResult.createSubresult(PREVIEW_CHANGES);
LensContext<F> context;
try {
RepositoryCache.enter();
//used cloned deltas instead of origin deltas, because some of the values should be lost later..
context = contextFactory.createContext(clonedDeltas, options, task, result);
// context.setOptions(options);
if (LOGGER.isDebugEnabled()) {
LOGGER.trace("Preview changes context:\n{}", context.debugDump());
}
context.setProgressListeners(listeners);
projector.projectAllWaves(context, "preview", task, result);
context.distributeResource();
} catch (ConfigurationException | SecurityViolationException | ObjectNotFoundException | SchemaException | CommunicationException | PolicyViolationException | RuntimeException | ObjectAlreadyExistsException | ExpressionEvaluationException e) {
ModelUtils.recordFatalError(result, e);
throw e;
} finally {
RepositoryCache.exit();
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Preview changes output:\n{}", context.debugDump());
}
result.computeStatus();
result.cleanupResult();
return context;
}
use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.
the class ObjectImporter method addObject.
private <T extends ObjectType> String addObject(PrismObject<T> object, boolean overwrite, boolean noCrypt, boolean raw, Task task, OperationResult parentResult) throws ObjectAlreadyExistsException, SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
ObjectDelta<T> delta = ObjectDelta.createAddDelta(object);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(delta);
ModelExecuteOptions options = new ModelExecuteOptions();
options.setRaw(raw);
if (overwrite) {
options.setOverwrite(true);
}
if (noCrypt) {
options.setNoCrypt(true);
}
modelService.executeChanges(deltas, options, task, parentResult);
return deltas.iterator().next().getOid();
}
use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.
the class PageDebugView method savePerformed.
public void savePerformed(AjaxRequestTarget target) {
ObjectViewDto dto = model.getObject();
if (StringUtils.isEmpty(dto.getXml())) {
error(getString("pageDebugView.message.cantSaveEmpty"));
target.add(getFeedbackPanel());
return;
}
Task task = createSimpleTask(OPERATION_SAVE_OBJECT);
OperationResult result = task.getResult();
try {
PrismObject<ObjectType> oldObject = dto.getObject();
oldObject.revive(getPrismContext());
Holder<PrismObject<ObjectType>> objectHolder = new Holder<>(null);
validateObject(result, objectHolder);
if (result.isAcceptable()) {
PrismObject<ObjectType> newObject = objectHolder.getValue();
ObjectDelta<ObjectType> delta = oldObject.diff(newObject, true, true);
if (delta.getPrismContext() == null) {
LOGGER.warn("No prism context in delta {} after diff, adding it", delta);
delta.revive(getPrismContext());
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Delta to be applied:\n{}", delta.debugDump());
}
//quick fix for now (MID-1910), maybe it should be somewhere in model..
// if (isReport(oldObject)){
// ReportTypeUtil.applyConfigurationDefinition((PrismObject)newObject, delta, getPrismContext());
// }
Collection<ObjectDelta<? extends ObjectType>> deltas = (Collection) MiscUtil.createCollection(delta);
ModelExecuteOptions options = new ModelExecuteOptions();
if (saveAsRaw.getObject()) {
options.setRaw(true);
}
if (reevaluateSearchFilters.getObject()) {
options.setReevaluateSearchFilters(true);
}
if (!encrypt.getObject()) {
options.setNoCrypt(true);
}
getModelService().executeChanges(deltas, options, task, result);
result.computeStatus();
}
} catch (Exception ex) {
result.recordFatalError("Couldn't save object.", ex);
}
if (result.isError()) {
showResult(result);
target.add(getFeedbackPanel());
} else {
showResult(result);
redirectBack();
}
}
Aggregations