use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class ModifyHelper method modifyShadow.
String modifyShadow(PrismObject<ShadowType> repoShadow, Collection<? extends ItemDelta<?, ?>> modifications, OperationProvisioningScriptsType scripts, ProvisioningOperationOptions options, Task task, OperationResult parentResult) throws CommunicationException, GenericFrameworkException, ObjectNotFoundException, SchemaException, ConfigurationException, SecurityViolationException, PolicyViolationException, ExpressionEvaluationException, EncryptionException, ObjectAlreadyExistsException {
Validate.notNull(repoShadow, "Object to modify must not be null.");
Validate.notNull(modifications, "Object modification must not be null.");
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Start modifying {}{}:\n{}", repoShadow, getAdditionalOperationDesc(scripts, options), DebugUtil.debugDump(modifications, 1));
}
InternalMonitor.recordCount(InternalCounters.SHADOW_CHANGE_OPERATION_COUNT);
Collection<QName> additionalAuxiliaryObjectClassQNames = new ArrayList<>();
for (ItemDelta modification : modifications) {
if (ShadowType.F_AUXILIARY_OBJECT_CLASS.equivalent(modification.getPath())) {
PropertyDelta<QName> auxDelta = (PropertyDelta<QName>) modification;
for (PrismPropertyValue<QName> pval : auxDelta.getValues(QName.class)) {
additionalAuxiliaryObjectClassQNames.add(pval.getValue());
}
}
}
ProvisioningContext ctx = ctxFactory.createForShadow(repoShadow, additionalAuxiliaryObjectClassQNames, task, parentResult);
ctx.assertDefinition();
ProvisioningOperationState<AsynchronousOperationReturnValue<Collection<PropertyDelta<PrismPropertyValue>>>> opState = new ProvisioningOperationState<>();
opState.setRepoShadow(repoShadow);
// it is quite cheap and probably more safe then not do it
if (options == null) {
options = ProvisioningOperationOptions.createForceRetry(Boolean.TRUE);
} else if (options.getForceRetry() == null) {
options.setForceRetry(Boolean.TRUE);
}
return modifyShadowAttempt(ctx, modifications, scripts, options, opState, false, task, parentResult);
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class TestOpenDj method test704ConfiguredCapabilityNoUpdate.
@Test
public void test704ConfiguredCapabilityNoUpdate() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
addResourceFromFile(new File(TEST_DIR, "/resource-opendj-no-update.xml"), IntegrationTestTools.CONNECTOR_LDAP_TYPE, true, result);
try {
PropertyDelta delta = prismContext.deltaFactory().property().createModificationReplaceProperty(ItemPath.create(ShadowType.F_ATTRIBUTES, new QName(MidPointConstants.NS_RI, "sn")), prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ShadowType.class), "doesnotmatter");
Collection modifications = MiscUtil.createCollection(delta);
provisioningService.modifyObject(ShadowType.class, ACCOUNT_WILL_OID, modifications, null, null, task, result);
AssertJUnit.fail("Expected unsupported operation exception, but haven't got one.");
} catch (UnsupportedOperationException ex) {
// this is expected..
}
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class TestUcfOpenDj method createReplaceAttributeChange.
private PropertyModificationOperation createReplaceAttributeChange(String propertyName, String propertyValue) throws SchemaException {
PrismProperty<?> property = createProperty(propertyName, propertyValue);
ItemPath propertyPath = ItemPath.create(ShadowType.F_ATTRIBUTES, new QName(MidPointConstants.NS_RI, propertyName));
PropertyDelta delta = prismContext.deltaFactory().property().create(propertyPath, property.getDefinition());
delta.setRealValuesToReplace(propertyValue);
PropertyModificationOperation attributeModification = new PropertyModificationOperation(delta);
return attributeModification;
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class TestUcfOpenDj method createAddAttributeChange.
private PropertyModificationOperation createAddAttributeChange(String propertyName, String propertyValue) throws SchemaException {
PrismProperty<?> property = createProperty(propertyName, propertyValue);
ItemPath propertyPath = ItemPath.create(ShadowType.F_ATTRIBUTES, new QName(MidPointConstants.NS_RI, propertyName));
PropertyDelta delta = prismContext.deltaFactory().property().create(propertyPath, property.getDefinition());
delta.addRealValuesToAdd(propertyValue);
PropertyModificationOperation attributeModification = new PropertyModificationOperation(delta);
return attributeModification;
}
use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.
the class TestUcfOpenDj method test610ChangePassword.
@Test
public void test610ChangePassword() throws Exception {
// GIVEN
ResourceAttributeContainer resourceObject = createResourceObject("uid=drake,ou=People,dc=example,dc=com", "Sir Francis Drake", "Drake");
PrismObject<ShadowType> shadow = wrapInShadow(ShadowType.class, resourceObject);
OperationResult addResult = createOperationResult();
// Add a testing object
cc.addObject(shadow, null, addResult);
String entryUuid = (String) resourceObject.getPrimaryIdentifier().getValue().getValue();
Entry entry = openDJController.searchAndAssertByEntryUuid(entryUuid);
displayValue("Entry before change", entry);
String passwordBefore = OpenDJController.getAttributeValue(entry, "userPassword");
// We have set no password during create, therefore the password should
// be empty
assertNull(passwordBefore);
ResourceObjectDefinition accountDefinition = resourceObject.getDefinition().getComplexTypeDefinition();
Collection<ResourceAttribute<?>> identifiers = resourceObject.getPrimaryIdentifiers();
// Determine object class from the schema
OperationResult result = new OperationResult(this.getClass().getName() + ".testFetchObject");
// WHEN
Set<Operation> changes = new HashSet<>();
ProtectedStringType passPs = protector.encryptString("salalala");
ItemDeltaType propMod = new ItemDeltaType();
// create modification path
ItemPathType path = prismContext.itemPathParser().asItemPathType("credentials/password/value");
propMod.setPath(path);
// set the replace value
XNode passPsXnode = prismContext.xnodeSerializer().root(new QName("dummy")).serializeRealValue(passPs).getSubnode();
RawType value = new RawType(passPsXnode.frozen(), prismContext);
propMod.getValue().add(value);
// set the modification type
propMod.setModificationType(ModificationTypeType.REPLACE);
PropertyDelta<ProtectedStringType> passDelta = (PropertyDelta) DeltaConvertor.createItemDelta(propMod, shadow.getDefinition());
PropertyModificationOperation<ProtectedStringType> passwordModification = new PropertyModificationOperation(passDelta);
changes.add(passwordModification);
ResourceObjectIdentification identification = ResourceObjectIdentification.createFromAttributes(accountDefinition, identifiers);
cc.modifyObject(identification, null, changes, null, null, result);
// THEN
entry = openDJController.searchAndAssertByEntryUuid(entryUuid);
displayValue("Entry after change", entry);
String passwordAfter = OpenDJController.getAttributeValue(entry, "userPassword");
assertNotNull(passwordAfter);
System.out.println("Account password: " + passwordAfter);
}
Aggregations