[midPoint] fire-and-forget action to update attribute in resource
Pavol Mederly
mederly at evolveum.com
Mon Mar 2 09:01:03 CET 2026
Hello Markus,
the technical reasons are quite minor - as you said, resource usage (cpu
and memory) - but nothing serious. Especially if it's only for a limited
number of users.
It's more a matter of solution elegance; I wanted to show you the
preferred approach that we use in the production code. :-)
Best regards,
--
Pavol Mederly
Interim Chief Product Officer
evolveum.com
On 02/03/2026 08:55, Markus Calmius via midPoint wrote:
> Hi Pavol,
>
> thank you for getting back to me again.
>
> Can I ask though, are there any specific reasons to not do the clone&diff?
> I assume it might have to do with resource-usage (memory etc) but
> would that be a major drawback?
> In this particular case, I do not see it as a problem as it's a
> limited number of users we'd need to do this for, but maybe that might
> change.
>
> Thanks,
>
> Markus Calmius
> Proton AG
>
> On Monday, 16 February 2026 at 16:42, Pavol Mederly via midPoint
> <midpoint at lists.evolveum.com> wrote:
>>
>> Hello Markus,
>>
>> I'd prefer direct creation of the delta, avoiding cloning and
>> diffing, like
>>
>> 1. If you know the resource (ResourceType), object class name, and
>> shadow OID
>>
>> Resource.of(...)
>> .deltaFor(objectClassName)
>> .item(ShadowType.F_ATTRIBUTES.append(attrName))
>> .replace(value)
>> .asObjectDelta(shadowOid);
>>
>> Resource is in com.evolveum.midpoint.schema.util package.
>>
>> (Or) 2. If you have the original shadow - which is probably your
>> situation - I am sorry but we don't have nicer API for this in
>> already released versions:
>>
>> var objectDefinition = ShadowUtil.getResourceObjectDefinition(shadow)
>> var delta = PrismContext.get().deltaFor(ShadowType.class, new
>> Resource.ResourceItemDefinitionResolver(objectDefinition))
>> .item(ShadowType.F_ATTRIBUTES.append(attrName))
>> .replace(value)
>> .asObjectDelta(shadowOid);
>>
>> This second variant is not tested, but it should work.
>>
>> Note that after
>> https://github.com/Evolveum/midpoint/commit/177c011fdbc74b45615d103c1bd0451c29524ffc
>> it could be written like this
>>
>> var objectDefinition = ShadowUtil.getResourceObjectDefinition(shadow)
>> var delta = objectDefinition.deltaFor()
>> .item(ShadowType.F_ATTRIBUTES.append(attrName))
>> .replace(value)
>> .asObjectDelta(shadowOid);
>>
>> Best regards,
>>
>> --
>> Pavol Mederly
>> Interim Chief Product Officer
>> evolveum.com
>> On 09/02/2026 14:53, Markus Calmius via midPoint wrote:
>>> Hi Pavol,
>>>
>>> thank you for the pointer.
>>>
>>> It looks like it's working.
>>> Ended up doing it like this... not sure whether or not there are
>>> better ways though
>>>
>>> shadowBefore = shadow.clone()
>>> shadowPrism = shadow.asPrismObject() ipath =
>>> ItemPath.create(ShadowType.F_ATTRIBUTES, attrQname)
>>> shadowPrism.findOrCreateProperty(ipath).addRealValue(setAttrValue)
>>> delta = shadowBefore.asPrismObject().diff(shadowPrism)
>>> midpoint.executeChanges(delta)
>>> Kind regards,
>>> Markus
>>> On Saturday, 7 February 2026 at 18:40, Pavol Mederly via midPoint
>>> <midpoint at lists.evolveum.com> wrote:
>>>>
>>>> Hi Markus,
>>>>
>>>> certainly. All you need to do is to execute a change against a
>>>> shadow object, modifying specified attribute directly. The property
>>>> path to be used is composed from "attributes" and the attribute
>>>> name, e.g. "attributes/dn".
>>>>
>>>> Best regards,
>>>>
>>>> --
>>>> Pavol Mederly
>>>> Interim Chief Product Officer
>>>> evolveum.com
>>>> On 23/01/2026 13:12, Markus Calmius via midPoint wrote:
>>>>> Hi,
>>>>> Is it possible to create a task or groovy script to modify a
>>>>> particular attribute directly on a resource, in the same way as
>>>>> when editing a user’s projection?
>>>>> Even without an outbound mapping, the attribute is updated on the
>>>>> resource. I would like to do this via a task/script without
>>>>> defining an outbound mapping, so that changes made by the resource
>>>>> are not overwritten by midpoint during reconciliations.
>>>>>
>>>>> Kind regards,
>>>>>
>>>>> Markus
>>>>>
>>>>> _______________________________________________
>>>>> midPoint mailing list
>>>>> midPoint at lists.evolveum.com
>>>>> https://lists.evolveum.com/mailman/listinfo/midpoint
>>>
>>>
>>> _______________________________________________
>>> midPoint mailing list
>>> midPoint at lists.evolveum.com
>>> https://lists.evolveum.com/mailman/listinfo/midpoint
>
>
> _______________________________________________
> midPoint mailing list
> midPoint at lists.evolveum.com
> https://lists.evolveum.com/mailman/listinfo/midpoint
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.evolveum.com/pipermail/midpoint/attachments/20260302/30c34278/attachment-0001.htm>
More information about the midPoint
mailing list