Skip to content

Commit

Permalink
Fix AuditController#reconstructObject
Browse files Browse the repository at this point in the history
An unmodifiable list of audit events (search result)
was modified while reconstructing an object history.

This is now fixed. It makes TestAudit pass again.
  • Loading branch information
mederly committed Sep 10, 2021
1 parent 52a6171 commit f394bb0
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package com.evolveum.midpoint.model.impl.controller;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

Expand Down Expand Up @@ -111,7 +112,10 @@ public <O extends ObjectType> PrismObject<O> reconstructObject(
//noinspection unchecked
PrismObject<O> currentObject = (PrismObject<O>) currentObjectType.asPrismObject();

List<AuditEventRecordType> changeTrail = getChangeTrail(oid, eventIdentifier, result);
List<AuditEventRecordType> changeTrail =
new ArrayList<>( // we later modify this list, so we need to make it mutable here
getChangeTrail(oid, eventIdentifier, result));

LOGGER.trace("Found change trail for {} containing {} events", oid, changeTrail.size());

LOGGER.debug("TRAIL:\n{}", DebugUtil.debugDumpLazily(changeTrail, 1));
Expand Down Expand Up @@ -166,6 +170,13 @@ private AuditEventRecordType findEvent(String eventIdentifier, OperationResult r
return listRecords.get(0);
}

/**
* Side effect: removes the last event.
*
* The reason is that we don't want to use it when rolling back the time later in
* {@link #rollBackTime(PrismObject, List)}. It is the reference event that we want to
* know the object state on.
*/
private <O extends ObjectType> PrismObject<O> getObjectFromLastEvent(
PrismObject<O> object, List<AuditEventRecordType> changeTrail, String eventIdentifier) {
if (changeTrail.isEmpty()) {
Expand Down

0 comments on commit f394bb0

Please sign in to comment.