use of com.evolveum.midpoint.audit.api.AuditEventRecord in project midpoint by Evolveum.
the class TestAudit method test310ConcurrentAuditsRaw.
/**
* Pure audit attempts (TODO move to some other test class in lower levels)
*/
@Test
public void test310ConcurrentAuditsRaw() throws Exception {
final int NUM_THREADS = 2;
final int ITERATIONS = 300;
final long TIMEOUT = 600_000;
// signal to kill other threads after a failure
final AtomicBoolean failed = new AtomicBoolean(false);
// creating threads + starting them
List<Thread> threads = new ArrayList<>(NUM_THREADS);
List<Throwable> results = new ArrayList<>(NUM_THREADS);
for (int i = 0; i < NUM_THREADS; i++) {
final int index = i;
Thread thread = new Thread(() -> {
try {
login(userAdministrator.clone());
Task threadTask = createTask();
OperationResult threadResult = threadTask.getResult();
for (int iteration = 0; iteration < ITERATIONS; iteration++) {
display("Executing iteration " + iteration + " in worker " + index);
AuditEventRecord record = new AuditEventRecord(AuditEventType.MODIFY_OBJECT, AuditEventStage.EXECUTION);
record.setEventIdentifier(iteration + ":" + System.currentTimeMillis() + "-" + (int) (Math.random() * 1_000_000));
ObjectDelta<? extends ObjectType> delta = prismContext.deltaFor(UserType.class).item(UserType.F_FULL_NAME).replace(PolyString.fromOrig("Hi" + iteration)).item(UserType.F_METADATA, MetadataType.F_MODIFY_TIMESTAMP).replace(XmlTypeConverter.createXMLGregorianCalendar(new Date())).asObjectDelta(String.format("61756469-746f-6964-3a20-%012d", index));
record.addDelta(new ObjectDeltaOperation<>(delta));
modelAuditService.audit(record, threadTask, threadResult);
if (failed.get()) {
results.set(index, new IllegalStateException("Some other thread failed"));
return;
}
}
results.set(index, null);
} catch (Throwable t) {
System.err.println("Thread " + index + " got an exception " + t);
LoggingUtils.logUnexpectedException(logger, "Thread {} got an exception", t, index);
results.set(index, t);
failed.set(true);
}
});
thread.setName("Worker " + i);
threads.add(thread);
// cleared on successful finish
results.add(new IllegalStateException("Thread not finished"));
}
threads.forEach(Thread::start);
// waiting for threads
long deadline = System.currentTimeMillis() + TIMEOUT;
for (int i = 0; i < NUM_THREADS; i++) {
long waitTime = deadline - System.currentTimeMillis();
if (waitTime > 0) {
threads.get(i).join(waitTime);
}
}
// checking results
int fails = 0;
for (int i = 0; i < NUM_THREADS; i++) {
if (results.get(i) != null) {
fails++;
display("Thread " + i + " produced an exception: " + results.get(i));
}
}
if (fails > 0) {
fail(fails + " thread(s) failed: " + results.stream().filter(Objects::nonNull).collect(Collectors.toList()));
}
// TODO check audit correctness
}
use of com.evolveum.midpoint.audit.api.AuditEventRecord in project midpoint by Evolveum.
the class TestAudit method test290QueryUnknown.
@Test
public void test290QueryUnknown() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
when();
AuditEventRecord record = new AuditEventRecord(AuditEventType.SYNCHRONIZATION, AuditEventStage.EXECUTION);
record.setOutcome(OperationResultStatus.UNKNOWN);
modelAuditService.audit(record, task, result);
List<AuditEventRecordType> records = modelAuditService.searchObjects(prismContext.queryFor(AuditEventRecordType.class).item(AuditEventRecordType.F_OUTCOME).eq(OperationResultStatusType.UNKNOWN).build(), null, task, result);
then();
display("records", records);
assertEquals("Wrong # of records", 1, records.size());
assertSuccess(result);
}
use of com.evolveum.midpoint.audit.api.AuditEventRecord in project midpoint by Evolveum.
the class TestUuid method assertReconAuditModifications.
private void assertReconAuditModifications(int expectedModifications, String taskOid) {
// Check audit
displayDumpable("Audit", dummyAuditService);
List<AuditEventRecord> auditRecords = dummyAuditService.getRecords();
// Record from some other task, skip it
auditRecords.removeIf(record -> record.getTaskOid() != null && !record.getTaskOid().equals(taskOid));
int i = 0;
while (i < (auditRecords.size() - 1)) {
AuditEventRecord reconStartRecord = auditRecords.get(i);
if (reconStartRecord.getEventType() == AuditEventType.EXECUTE_CHANGES_RAW) {
i++;
continue;
}
assertNotNull("No reconStartRecord audit record", reconStartRecord);
assertEquals("Wrong stage in reconStartRecord audit record: " + reconStartRecord, AuditEventStage.REQUEST, reconStartRecord.getEventStage());
assertEquals("Wrong type in reconStartRecord audit record: " + reconStartRecord, AuditEventType.RECONCILIATION, reconStartRecord.getEventType());
assertTrue("Unexpected delta in reconStartRecord audit record " + reconStartRecord, reconStartRecord.getDeltas().isEmpty());
i++;
break;
}
int modifications = 0;
for (; i < (auditRecords.size() - 1); i += 2) {
AuditEventRecord requestRecord = auditRecords.get(i);
assertNotNull("No request audit record (" + i + ")", requestRecord);
if (requestRecord.getEventStage() == AuditEventStage.EXECUTION && requestRecord.getEventType() == AuditEventType.RECONCILIATION) {
// end of audit records;
break;
}
assertEquals("Got this instead of request audit record (" + i + "): " + requestRecord, AuditEventStage.REQUEST, requestRecord.getEventStage());
// Request audit may or may not have a delta. Usual records will not have a delta. But e.g. disableAccount reactions will have.
AuditEventRecord executionRecord = auditRecords.get(i + 1);
assertNotNull("No execution audit record (" + i + ")", executionRecord);
assertEquals("Got this instead of execution audit record (" + i + "): " + executionRecord, AuditEventStage.EXECUTION, executionRecord.getEventStage());
assertThat(executionRecord.getDeltas()).withFailMessage("Empty deltas in execution audit record " + executionRecord).isNotEmpty();
modifications++;
while (i + 2 < auditRecords.size()) {
AuditEventRecord nextRecord = auditRecords.get(i + 2);
if (nextRecord.getEventStage() == AuditEventStage.EXECUTION && nextRecord.getEventType() == requestRecord.getEventType()) {
// this is an additional EXECUTION record due to changes in clockwork
i++;
} else {
break;
}
}
}
assertEquals("Unexpected number of audit modifications", expectedModifications, modifications);
AuditEventRecord reconStopRecord = auditRecords.get(i);
assertNotNull("No reconStopRecord audit record", reconStopRecord);
assertEquals("Wrong stage in reconStopRecord audit record: " + reconStopRecord, AuditEventStage.EXECUTION, reconStopRecord.getEventStage());
assertEquals("Wrong type in reconStopRecord audit record: " + reconStopRecord, AuditEventType.RECONCILIATION, reconStopRecord.getEventType());
assertTrue("Unexpected delta in reconStopRecord audit record " + reconStopRecord, reconStopRecord.getDeltas().isEmpty());
}
use of com.evolveum.midpoint.audit.api.AuditEventRecord in project midpoint by Evolveum.
the class TestRecomputeTask method test100RecomputeAll.
@Test
public void test100RecomputeAll() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = getTestOperationResult();
// Preconditions
assertUsers(6);
assertNoDummyAccount(RESOURCE_DUMMY_RED_NAME, ACCOUNT_GUYBRUSH_DUMMY_USERNAME);
assertNoDummyAccount(RESOURCE_DUMMY_RED_NAME, ACCOUNT_JACK_DUMMY_USERNAME);
// Do some ordinary operations
assignRole(USER_GUYBRUSH_OID, ROLE_PIRATE_OID, task, result);
assignRole(USER_JACK_OID, ROLE_JUDGE_OID, task, result);
addObject(USER_HERMAN_FILE);
assignRole(USER_HERMAN_OID, ROLE_JUDGE_OID, task, result);
result.computeStatus();
TestUtil.assertSuccess(result);
// Now do something evil
// change definition of role "pirate". midPoint will not recompute automatically
// the recompute task should do it
// One simple change
modifyRoleAddConstruction(ROLE_JUDGE_OID, 1111L, RESOURCE_DUMMY_RED_OID);
// More complicated change
PrismObject<RoleType> rolePirate = modelService.getObject(RoleType.class, ROLE_PIRATE_OID, null, task, result);
ItemPath attrItemPath = ItemPath.create(RoleType.F_INDUCEMENT, 1111L, AssignmentType.F_CONSTRUCTION, 60004L, ConstructionType.F_ATTRIBUTE);
PrismContainer<ResourceAttributeDefinitionType> attributeCont = rolePirate.findContainer(attrItemPath);
assertNotNull("No attribute property in " + rolePirate, attributeCont);
PrismContainerValue<ResourceAttributeDefinitionType> oldAttrContainer = null;
for (PrismContainerValue<ResourceAttributeDefinitionType> cval : attributeCont.getValues()) {
ResourceAttributeDefinitionType attrType = cval.getValue();
if (ItemPathTypeUtil.asSingleNameOrFail(attrType.getRef()).getLocalPart().equals(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME)) {
oldAttrContainer = cval;
}
}
assertNotNull("Definition for weapon attribute not found in " + rolePirate, oldAttrContainer);
PrismContainerValue<ResourceAttributeDefinitionType> newAttrContainer = oldAttrContainer.clone();
XNode daggerXNode = prismContext.xnodeFactory().primitive("dagger");
daggerXNode.freeze();
RawType daggerValueEvaluator = new RawType(daggerXNode, prismContext);
JAXBElement<?> daggerExpressionEvalJaxbElement = new JAXBElement<>(SchemaConstants.C_VALUE, Object.class, daggerValueEvaluator);
newAttrContainer.getValue().getOutbound().getExpression().getExpressionEvaluator().add(daggerExpressionEvalJaxbElement);
newAttrContainer.getValue().getOutbound().setStrength(MappingStrengthType.STRONG);
ObjectDelta<RoleType> rolePirateDelta = prismContext.deltaFactory().object().createModificationDeleteContainer(RoleType.class, ROLE_PIRATE_OID, attrItemPath, oldAttrContainer.getValue().clone());
ResourceAttributeDefinitionType newAttrCVal = newAttrContainer.getValue();
newAttrCVal.asPrismContainerValue().setId(null);
rolePirateDelta.addModificationAddContainer(attrItemPath, newAttrCVal);
displayDumpable("Role pirate delta", rolePirateDelta);
modelService.executeChanges(MiscSchemaUtil.createCollection(rolePirateDelta), null, task, result);
displayRoles(task, result);
assertDummyAccount(null, ACCOUNT_GUYBRUSH_DUMMY_USERNAME, "Guybrush Threepwood", true);
assertNoDummyAccount(RESOURCE_DUMMY_RED_NAME, ACCOUNT_GUYBRUSH_DUMMY_USERNAME);
assertUser(USER_JACK_OID, "user jack before").display().assignments().single().assertRole(ROLE_JUDGE_OID).end().end().roleMembershipRefs().single().assertOid(ROLE_JUDGE_OID);
assertDummyAccount(null, ACCOUNT_JACK_DUMMY_USERNAME, "Jack Sparrow", true);
assertNoDummyAccount(RESOURCE_DUMMY_RED_NAME, ACCOUNT_JACK_DUMMY_USERNAME);
result.computeStatus();
TestUtil.assertSuccess(result);
// WHEN
when();
addTask(TASK_USER_RECOMPUTE_FILE);
dummyAuditService.clear();
waitForTaskStart(TASK_USER_RECOMPUTE_OID, false);
// WHEN
when();
waitForTaskFinish(TASK_USER_RECOMPUTE_OID, false, 40000);
// THEN
then();
List<PrismObject<UserType>> users = modelService.searchObjects(UserType.class, null, null, task, result);
display("Users after recompute", users);
assertDummyAccount(null, ACCOUNT_GUYBRUSH_DUMMY_USERNAME, "Guybrush Threepwood", true);
assertDummyAccountAttribute(null, ACCOUNT_GUYBRUSH_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "cutlass", "dagger");
assertNoDummyAccount(RESOURCE_DUMMY_RED_NAME, ACCOUNT_GUYBRUSH_DUMMY_USERNAME);
assertUser(USER_JACK_OID, "user jack after").display().assertNoArchetypeRef();
assertNoDummyAccount(null, ACCOUNT_JACK_DUMMY_USERNAME);
assertDummyAccount(RESOURCE_DUMMY_RED_NAME, ACCOUNT_JACK_DUMMY_USERNAME, "Jack Sparrow", true);
assertUsers(7);
// Check audit
displayDumpable("Audit", dummyAuditService);
List<AuditEventRecord> auditRecords = dummyAuditService.getRecords();
int i = 0;
int modifications = 0;
for (; i < (auditRecords.size() - 1); i += 2) {
AuditEventRecord requestRecord = auditRecords.get(i);
assertNotNull("No request audit record (" + i + ")", requestRecord);
assertEquals("Got this instead of request audit record (" + i + "): " + requestRecord, AuditEventStage.REQUEST, requestRecord.getEventStage());
assertTrue("Unexpected delta in request audit record " + requestRecord, requestRecord.getDeltas().isEmpty());
AuditEventRecord executionRecord = auditRecords.get(i + 1);
assertNotNull("No execution audit record (" + i + ")", executionRecord);
assertEquals("Got this instead of execution audit record (" + i + "): " + executionRecord, AuditEventStage.EXECUTION, executionRecord.getEventStage());
assertThat(executionRecord.getDeltas()).withFailMessage("Empty deltas in execution audit record " + executionRecord).isNotEmpty();
modifications++;
// check next records
while (i < (auditRecords.size() - 2)) {
AuditEventRecord nextRecord = auditRecords.get(i + 2);
if (nextRecord.getEventStage() == AuditEventStage.EXECUTION) {
// more than one execution record is OK
i++;
} else {
break;
}
}
}
assertEquals("Unexpected number of audit modifications", 7, modifications);
deleteObject(TaskType.class, TASK_USER_RECOMPUTE_OID, task, result);
}
use of com.evolveum.midpoint.audit.api.AuditEventRecord in project midpoint by Evolveum.
the class TestCleanupTask method createHistoricAuditRecord.
private void createHistoricAuditRecord(Task task, OperationResult result) {
AuditEventRecord auditRecord = new AuditEventRecord(AuditEventType.ADD_OBJECT);
auditRecord.setTimestamp(HISTORIC_AUDIT_TIMESTAMP);
auditService.audit(auditRecord, task, result);
assertHistoricAuditRecordPresence(true);
}
Aggregations