Search in sources :

Example 6 with ObjectDeltaOperation

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

the class AccCertUpdateHelper method addObject.

//endregion
//region ================================ Model and repository operations ================================
void addObject(ObjectType objectType, Task task, OperationResult result) throws ObjectAlreadyExistsException, SchemaException, ObjectNotFoundException {
    ObjectDelta<? extends ObjectType> objectDelta = ObjectDelta.createAddDelta(objectType.asPrismObject());
    Collection<ObjectDeltaOperation<? extends ObjectType>> ops;
    try {
        ops = modelService.executeChanges(Collections.singleton(objectDelta), ModelExecuteOptions.createRaw().setPreAuthorized(), task, result);
    } catch (ExpressionEvaluationException | CommunicationException | ConfigurationException | PolicyViolationException | SecurityViolationException e) {
        throw new SystemException("Unexpected exception when adding object: " + e.getMessage(), e);
    }
    ObjectDeltaOperation odo = ops.iterator().next();
    objectType.setOid(odo.getObjectDelta().getOid());
/* ALTERNATIVELY, we can go directly into the repository. (No audit there.)
        String oid = repositoryService.addObject(objectType.asPrismObject(), null, result);
        objectType.setOid(oid);
         */
}
Also used : ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException)

Example 7 with ObjectDeltaOperation

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

the class PrimaryChangeProcessor method prepareProcessInstanceAuditRecord.

//endregion
//region Auditing
@Override
public AuditEventRecord prepareProcessInstanceAuditRecord(WfTask wfTask, AuditEventStage stage, Map<String, Object> variables, OperationResult result) {
    AuditEventRecord auditEventRecord = baseAuditHelper.prepareProcessInstanceAuditRecord(wfTask, stage, result);
    ObjectTreeDeltas<?> deltas;
    try {
        if (stage == REQUEST) {
            deltas = wfTaskUtil.retrieveDeltasToProcess(wfTask.getTask());
        } else {
            deltas = wfTaskUtil.retrieveResultingDeltas(wfTask.getTask());
        }
    } catch (SchemaException e) {
        throw new SystemException("Couldn't retrieve delta(s) from task " + wfTask.getTask(), e);
    }
    if (deltas != null) {
        List<ObjectDelta<?>> deltaList = deltas.getDeltaList();
        for (ObjectDelta delta : deltaList) {
            auditEventRecord.addDelta(new ObjectDeltaOperation(delta));
        }
    }
    return auditEventRecord;
}
Also used : ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord)

Example 8 with ObjectDeltaOperation

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

the class RAuditEventRecord method fromRepo.

public static AuditEventRecord fromRepo(RAuditEventRecord repo, PrismContext prismContext) throws DtoTranslationException {
    AuditEventRecord audit = new AuditEventRecord();
    audit.setChannel(repo.getChannel());
    audit.setEventIdentifier(repo.getEventIdentifier());
    if (repo.getEventStage() != null) {
        audit.setEventStage(repo.getEventStage().getStage());
    }
    if (repo.getEventType() != null) {
        audit.setEventType(repo.getEventType().getType());
    }
    audit.setHostIdentifier(repo.getHostIdentifier());
    audit.setRemoteHostAddress(repo.getRemoteHostAddress());
    audit.setNodeIdentifier(repo.getNodeIdentifier());
    audit.setMessage(repo.getMessage());
    if (repo.getOutcome() != null) {
        audit.setOutcome(repo.getOutcome().getStatus());
    }
    audit.setParameter(repo.getParameter());
    audit.setResult(repo.getResult());
    audit.setSessionIdentifier(repo.getSessionIdentifier());
    audit.setTaskIdentifier(repo.getTaskIdentifier());
    audit.setTaskOID(repo.getTaskOID());
    if (repo.getTimestamp() != null) {
        audit.setTimestamp(repo.getTimestamp().getTime());
    }
    List<ObjectDeltaOperation> odos = new ArrayList<>();
    for (RObjectDeltaOperation rodo : repo.getDeltas()) {
        try {
            ObjectDeltaOperation odo = RObjectDeltaOperation.fromRepo(rodo, prismContext);
            if (odo != null) {
                odos.add(odo);
            }
        } catch (Exception ex) {
        // TODO: for now thi is OK, if we cannot parse detla, just skipp
        // it.. Have to be resolved later;
        }
    }
    audit.getDeltas().addAll((Collection) odos);
    for (RAuditPropertyValue rPropertyValue : repo.getPropertyValues()) {
        audit.addPropertyValue(rPropertyValue.getName(), rPropertyValue.getValue());
    }
    for (RAuditReferenceValue rRefValue : repo.getReferenceValues()) {
        audit.addReferenceValue(rRefValue.getName(), rRefValue.fromRepo());
    }
    audit.setRepoId(repo.getId());
    return audit;
// initiator, target, targetOwner
}
Also used : ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException)

Example 9 with ObjectDeltaOperation

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

the class TestActivation method test160ModifyUserJackAssignAccountKhaki.

/**
 * Khaki resource has simulated activation capability.
 */
@Test
public void test160ModifyUserJackAssignAccountKhaki() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
    dummyAuditService.clear();
    XMLGregorianCalendar start = clock.currentTimeXMLGregorianCalendar();
    // WHEN
    when();
    assignAccountToUser(USER_JACK_OID, RESOURCE_DUMMY_KHAKI_OID, null, task, result);
    // THEN
    then();
    XMLGregorianCalendar end = clock.currentTimeXMLGregorianCalendar();
    result.computeStatus();
    TestUtil.assertSuccess("executeChanges result", result);
    PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
    display("User after", userAfter);
    assertUserJack(userAfter);
    String accountKhakiOid = getLiveLinkRefOid(userAfter, RESOURCE_DUMMY_KHAKI_OID);
    // Check shadow
    PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountKhakiOid, null, result);
    display("Shadow (repo)", accountShadow);
    assertAccountShadowRepo(accountShadow, accountKhakiOid, "jack", resourceDummyKhakiType);
    TestUtil.assertCreateTimestamp(accountShadow, start, end);
    assertEnableTimestampShadow(accountShadow, start, end);
    // Check account
    PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountKhakiOid, null, task, result);
    display("Shadow (model)", accountModel);
    assertAccountShadowModel(accountModel, accountKhakiOid, "jack", resourceDummyKhakiType);
    TestUtil.assertCreateTimestamp(accountModel, start, end);
    assertEnableTimestampShadow(accountModel, start, end);
    // Check account in dummy resource
    assertDummyAccount(RESOURCE_DUMMY_KHAKI_NAME, "jack", "Jack Sparrow", true);
    assertDummyEnabled(RESOURCE_DUMMY_KHAKI_NAME, "jack");
    TestUtil.assertModifyTimestamp(userAfter, start, end);
    checkAdminStatusFor15x(userAfter, true, true, true);
    // Check audit
    displayDumpable("Audit", dummyAuditService);
    dummyAuditService.assertRecords(2);
    dummyAuditService.assertSimpleRecordSanity();
    dummyAuditService.assertAnyRequestDeltas();
    // fourth one (trigger-related) was here by mistake
    dummyAuditService.assertExecutionDeltas(3);
    dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
    dummyAuditService.assertHasDelta(ChangeType.ADD, ShadowType.class);
    dummyAuditService.assertTarget(USER_JACK_OID);
    dummyAuditService.assertExecutionSuccess();
    Collection<ObjectDeltaOperation<? extends ObjectType>> executionDeltas = dummyAuditService.getExecutionDeltas();
    boolean found = false;
    for (ObjectDeltaOperation<? extends ObjectType> executionDelta : executionDeltas) {
        ObjectDelta<? extends ObjectType> objectDelta = executionDelta.getObjectDelta();
        if (objectDelta.getObjectTypeClass() == ShadowType.class) {
            // Actually, there should be no F_TRIGGER delta! It was there by mistake.
            // if (objectDelta.findContainerDelta(ShadowType.F_TRIGGER) != null) {
            // continue;
            // }
            PropertyDelta<Object> enableTimestampDelta = objectDelta.findPropertyDelta(PATH_ACTIVATION_ENABLE_TIMESTAMP);
            displayDumpable("Audit enableTimestamp delta", enableTimestampDelta);
            assertNotNull("EnableTimestamp delta vanished from audit record, delta: " + objectDelta, enableTimestampDelta);
            found = true;
        }
    }
    assertTrue("Shadow delta not found", found);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) TestValidityRecomputeTask(com.evolveum.midpoint.model.intest.sync.TestValidityRecomputeTask) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) PrismObject(com.evolveum.midpoint.prism.PrismObject) Test(org.testng.annotations.Test)

Example 10 with ObjectDeltaOperation

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

the class TestActivation method test600AddUser1.

// attempt to simulate MID-3348 (unsuccessful for now)
@Test
public void test600AddUser1() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    PrismObject<UserType> user1 = prismContext.createObject(UserType.class);
    prismContext.deltaFor(UserType.class).item(UserType.F_NAME).replace(new PolyString("user1")).item(UserType.F_ASSIGNMENT).add(ObjectTypeUtil.createAssignmentTo(resourceDummyCoral, prismContext).asPrismContainerValue()).item(ACTIVATION_ADMINISTRATIVE_STATUS_PATH).replace(ActivationStatusType.DISABLED).<UserType>asObjectDelta(null).applyTo(user1);
    ObjectDelta<UserType> addDelta = user1.createAddDelta();
    // WHEN
    when();
    Collection<ObjectDeltaOperation<? extends ObjectType>> executedChanges = executeChanges(addDelta, null, task, result);
    // THEN
    then();
    user1 = getUser(ObjectDeltaOperation.findFocusDeltaOidInCollection(executedChanges));
    display("User after change execution", user1);
    DummyAccount dummyAccount = dummyResourceCoral.getAccountByUsername("user1");
    displayDumpable("Dummy account", dummyAccount);
    checkSuspendedAttribute(dummyAccount, Boolean.TRUE);
    String accountOid = getSingleLinkOid(user1);
    PrismObject<ShadowType> shadow = getShadowModel(accountOid);
    display("Shadow: ", shadow);
// TODO check real state of the account and shadow
}
Also used : Task(com.evolveum.midpoint.task.api.Task) TestValidityRecomputeTask(com.evolveum.midpoint.model.intest.sync.TestValidityRecomputeTask) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test)

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