Search in sources :

Example 1 with ObjectDeltaOperation

use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.

the class Clockwork method auditEvent.

private <F extends ObjectType> void auditEvent(LensContext<F> context, AuditEventStage stage, XMLGregorianCalendar timestamp, boolean alwaysAudit, Task task, OperationResult result) throws SchemaException {
    PrismObject<? extends ObjectType> primaryObject;
    ObjectDelta<? extends ObjectType> primaryDelta;
    if (context.getFocusContext() != null) {
        primaryObject = context.getFocusContext().getObjectOld();
        if (primaryObject == null) {
            primaryObject = context.getFocusContext().getObjectNew();
        }
        primaryDelta = context.getFocusContext().getDelta();
    } else {
        Collection<LensProjectionContext> projectionContexts = context.getProjectionContexts();
        if (projectionContexts == null || projectionContexts.isEmpty()) {
            throw new IllegalStateException("No focus and no projections in " + context);
        }
        if (projectionContexts.size() > 1) {
            throw new IllegalStateException("No focus and more than one projection in " + context);
        }
        LensProjectionContext projection = projectionContexts.iterator().next();
        primaryObject = projection.getObjectOld();
        if (primaryObject == null) {
            primaryObject = projection.getObjectNew();
        }
        primaryDelta = projection.getDelta();
    }
    AuditEventType eventType;
    if (primaryDelta == null) {
        eventType = AuditEventType.SYNCHRONIZATION;
    } else if (primaryDelta.isAdd()) {
        eventType = AuditEventType.ADD_OBJECT;
    } else if (primaryDelta.isModify()) {
        eventType = AuditEventType.MODIFY_OBJECT;
    } else if (primaryDelta.isDelete()) {
        eventType = AuditEventType.DELETE_OBJECT;
    } else {
        throw new IllegalStateException("Unknown state of delta " + primaryDelta);
    }
    AuditEventRecord auditRecord = new AuditEventRecord(eventType, stage);
    if (primaryObject != null) {
        auditRecord.setTarget(primaryObject.clone());
    //		} else {
    //			throw new IllegalStateException("No primary object in:\n"+context.dump());
    }
    auditRecord.setChannel(context.getChannel());
    if (stage == AuditEventStage.REQUEST) {
        Collection<ObjectDeltaOperation<? extends ObjectType>> clonedDeltas = ObjectDeltaOperation.cloneDeltaCollection(context.getPrimaryChanges());
        checkNamesArePresent(clonedDeltas, primaryObject);
        auditRecord.addDeltas(clonedDeltas);
        if (auditRecord.getTarget() == null) {
            auditRecord.setTarget(Utils.determineAuditTargetDeltaOps(clonedDeltas));
        }
    } else if (stage == AuditEventStage.EXECUTION) {
        auditRecord.setOutcome(result.getComputeStatus());
        Collection<ObjectDeltaOperation<? extends ObjectType>> unauditedExecutedDeltas = context.getUnauditedExecutedDeltas();
        if (!alwaysAudit && (unauditedExecutedDeltas == null || unauditedExecutedDeltas.isEmpty())) {
            // No deltas, nothing to audit in this wave
            return;
        }
        Collection<ObjectDeltaOperation<? extends ObjectType>> clonedDeltas = ObjectDeltaOperation.cloneCollection(unauditedExecutedDeltas);
        checkNamesArePresent(clonedDeltas, primaryObject);
        auditRecord.addDeltas(clonedDeltas);
    } else {
        throw new IllegalStateException("Unknown audit stage " + stage);
    }
    if (timestamp != null) {
        auditRecord.setTimestamp(XmlTypeConverter.toMillis(timestamp));
    }
    addRecordMessage(auditRecord, result);
    auditService.audit(auditRecord, task);
    if (stage == AuditEventStage.EXECUTION) {
        // We need to clean up so these deltas will not be audited again in next wave
        context.markExecutedDeltasAudited();
        context.setExecutionAudited(true);
    } else if (stage == AuditEventStage.REQUEST) {
        context.setRequestAudited(true);
    } else {
        throw new IllegalStateException("Unknown audit stage " + stage);
    }
}
Also used : AuditEventType(com.evolveum.midpoint.audit.api.AuditEventType) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord)

Example 2 with ObjectDeltaOperation

use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.

the class LensObjectDeltaOperation method fromLensObjectDeltaOperationType.

public static LensObjectDeltaOperation fromLensObjectDeltaOperationType(LensObjectDeltaOperationType jaxb, PrismContext prismContext) throws SchemaException {
    ObjectDeltaOperation odo = DeltaConvertor.createObjectDeltaOperation(jaxb.getObjectDeltaOperation(), prismContext);
    LensObjectDeltaOperation retval = new LensObjectDeltaOperation();
    retval.setObjectDelta(odo.getObjectDelta());
    retval.setExecutionResult(odo.getExecutionResult());
    retval.setAudited(jaxb.isAudited());
    return retval;
}
Also used : ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation)

Example 3 with ObjectDeltaOperation

use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.

the class ModelWebService method executeChanges.

@Override
public ObjectDeltaOperationListType executeChanges(ObjectDeltaListType deltaList, ModelExecuteOptionsType optionsType) throws FaultMessage {
    notNullArgument(deltaList, "Object delta list must not be null.");
    Task task = createTaskInstance(EXECUTE_CHANGES);
    auditLogin(task);
    OperationResult operationResult = task.getResult();
    try {
        Collection<ObjectDelta> deltas = DeltaConvertor.createObjectDeltas(deltaList, prismContext);
        for (ObjectDelta delta : deltas) {
            prismContext.adopt(delta);
        }
        ModelExecuteOptions options = ModelExecuteOptions.fromModelExecutionOptionsType(optionsType);
        // brutally eliminating type-safety compiler barking
        Collection<ObjectDeltaOperation<? extends ObjectType>> objectDeltaOperations = modelService.executeChanges((Collection) deltas, options, task, operationResult);
        ObjectDeltaOperationListType retval = new ObjectDeltaOperationListType();
        for (ObjectDeltaOperation objectDeltaOperation : objectDeltaOperations) {
            ObjectDeltaOperationType objectDeltaOperationType = DeltaConvertor.toObjectDeltaOperationType(objectDeltaOperation, null);
            retval.getDeltaOperation().add(objectDeltaOperationType);
        }
        return retval;
    } catch (Exception ex) {
        LoggingUtils.logException(LOGGER, "# MODEL executeChanges() failed", ex);
        throwFault(ex, operationResult);
        // notreached
        return null;
    } finally {
        auditLogout(task);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) JAXBException(javax.xml.bind.JAXBException)

Example 4 with ObjectDeltaOperation

use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.

the class AuditController method rollBackTime.

private <O extends ObjectType> PrismObject<O> rollBackTime(PrismObject<O> object, List<AuditEventRecord> changeTrail) throws SchemaException {
    for (AuditEventRecord event : changeTrail) {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Applying event {} ({})", event.getEventIdentifier(), XmlTypeConverter.createXMLGregorianCalendar(event.getTimestamp()));
        }
        Collection<ObjectDeltaOperation<? extends ObjectType>> deltaOperations = event.getDeltas();
        if (deltaOperations != null) {
            for (ObjectDeltaOperation<? extends ObjectType> deltaOperation : deltaOperations) {
                ObjectDelta<O> objectDelta = (ObjectDelta<O>) deltaOperation.getObjectDelta();
                if (!isApplicable(deltaOperation, object, event)) {
                    continue;
                }
                if (objectDelta.isDelete()) {
                    throw new SchemaException("Delete delta found in the audit trail. Object history cannot be reconstructed.");
                }
                if (objectDelta.isAdd()) {
                    throw new SchemaException("Add delta found in the audit trail. Object history cannot be reconstructed.");
                }
                ObjectDelta<O> reverseDelta = objectDelta.createReverseDelta();
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Applying delta (reverse):\n{}", reverseDelta.debugDump(1));
                }
                reverseDelta.applyTo(object);
            }
        }
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Object after application of event {} ({}):\n{}", event.getEventIdentifier(), XmlTypeConverter.createXMLGregorianCalendar(event.getTimestamp()), object.debugDump(1));
        }
    }
    return object;
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord)

Example 5 with ObjectDeltaOperation

use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.

the class DefaultGuiProgressListener method updateStatusItemState.

private void updateStatusItemState(ProgressReportActivityDto si, ProgressInformation progressInformation, ModelContext modelContext) {
    si.setActivityType(progressInformation.getActivityType());
    si.setResourceShadowDiscriminator(progressInformation.getResourceShadowDiscriminator());
    if (progressInformation.getResourceShadowDiscriminator() != null) {
        String resourceOid = progressInformation.getResourceShadowDiscriminator().getResourceOid();
        String resourceName = resourceOid != null ? getResourceName(resourceOid) : "";
        si.setResourceName(resourceName);
    }
    if (progressInformation.getStateType() == null) {
        si.setStatus(null);
    } else if (progressInformation.getStateType() == ENTERING) {
        si.setStatus(OperationResultStatusType.IN_PROGRESS);
    } else {
        OperationResult result = progressInformation.getOperationResult();
        if (result != null) {
            OperationResultStatus status = result.getStatus();
            if (status == OperationResultStatus.UNKNOWN) {
                status = result.getComputeStatus();
            }
            si.setStatus(status.createStatusType());
        } else {
            si.setStatus(OperationResultStatusType.UNKNOWN);
        }
    }
    // information about modifications on a resource
    if (progressInformation.getActivityType() == RESOURCE_OBJECT_OPERATION && progressInformation.getStateType() == EXITING && progressInformation.getResourceShadowDiscriminator() != null && progressInformation.getResourceShadowDiscriminator().getResourceOid() != null) {
        ModelProjectionContext mpc = modelContext.findProjectionContext(progressInformation.getResourceShadowDiscriminator());
        if (mpc != null) {
            // it shouldn't be null!
            // operations performed (TODO aggregate them somehow?)
            List<ResourceOperationResult> resourceOperationResultList = new ArrayList<>();
            List<? extends ObjectDeltaOperation> executedDeltas = mpc.getExecutedDeltas();
            for (ObjectDeltaOperation executedDelta : executedDeltas) {
                ObjectDelta delta = executedDelta.getObjectDelta();
                if (delta != null) {
                    OperationResult r = executedDelta.getExecutionResult();
                    OperationResultStatus status = r.getStatus();
                    if (status == OperationResultStatus.UNKNOWN) {
                        status = r.getComputeStatus();
                    }
                    resourceOperationResultList.add(new ResourceOperationResult(delta.getChangeType(), status));
                }
            }
            si.setResourceOperationResultList(resourceOperationResultList);
            // object name
            PrismObject<ShadowType> object = mpc.getObjectNew();
            if (object == null) {
                object = mpc.getObjectOld();
            }
            String name = null;
            if (object != null) {
                if (object.asObjectable().getName() != null) {
                    name = PolyString.getOrig(object.asObjectable().getName());
                } else {
                    // determine from attributes
                    ResourceAttribute nameAttribute = ShadowUtil.getNamingAttribute(object);
                    if (nameAttribute != null) {
                        name = String.valueOf(nameAttribute.getAnyRealValue());
                    }
                }
            }
            if (name != null) {
                si.setResourceObjectName(name);
            }
        }
    }
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceOperationResult(com.evolveum.midpoint.web.component.progress.ProgressReportActivityDto.ResourceOperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) ModelProjectionContext(com.evolveum.midpoint.model.api.context.ModelProjectionContext) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) ResourceOperationResult(com.evolveum.midpoint.web.component.progress.ProgressReportActivityDto.ResourceOperationResult)

Aggregations

ObjectDeltaOperation (com.evolveum.midpoint.schema.ObjectDeltaOperation)51 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)24 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)15 Task (com.evolveum.midpoint.task.api.Task)12 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)11 Test (org.testng.annotations.Test)11 ArrayList (java.util.ArrayList)9 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)7 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6 ModelProjectionContext (com.evolveum.midpoint.model.api.context.ModelProjectionContext)4 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)4 ModelService (com.evolveum.midpoint.model.api.ModelService)3 TestValidityRecomputeTask (com.evolveum.midpoint.model.intest.sync.TestValidityRecomputeTask)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 CommonException (com.evolveum.midpoint.util.exception.CommonException)3 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)3 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)3 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)3 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)3 AuditEventType (com.evolveum.midpoint.audit.api.AuditEventType)2