Search in sources :

Example 36 with PropertyDelta

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);
}
Also used : QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) AsynchronousOperationReturnValue(com.evolveum.midpoint.schema.result.AsynchronousOperationReturnValue) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta)

Example 37 with PropertyDelta

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..
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) QName(javax.xml.namespace.QName) Collection(java.util.Collection) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) File(java.io.File) Test(org.testng.annotations.Test)

Example 38 with PropertyDelta

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;
}
Also used : QName(javax.xml.namespace.QName) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 39 with PropertyDelta

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;
}
Also used : QName(javax.xml.namespace.QName) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 40 with PropertyDelta

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);
}
Also used : QName(javax.xml.namespace.QName) XNode(com.evolveum.midpoint.prism.xnode.XNode) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Entry(org.opends.server.types.Entry) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) HashSet(java.util.HashSet)

Aggregations

PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)90 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)39 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)33 QName (javax.xml.namespace.QName)28 ArrayList (java.util.ArrayList)23 Test (org.testng.annotations.Test)20 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)19 Task (com.evolveum.midpoint.task.api.Task)19 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)18 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)15 Collection (java.util.Collection)15 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)14 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)11 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)9 SystemException (com.evolveum.midpoint.util.exception.SystemException)9 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)7 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)7 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)7 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)6