use of com.evolveum.midpoint.audit.api.AuditEventRecord in project midpoint by Evolveum.
the class SecurityHelper method auditLogout.
@Override
public void auditLogout(ConnectionEnvironment connEnv, Task task, OperationResult result) {
if (!SecurityUtil.isAuditedLoginAndLogout(getSystemConfig(), connEnv.getChannel())) {
return;
}
AuditEventRecord record = new AuditEventRecord(AuditEventType.TERMINATE_SESSION, AuditEventStage.REQUEST);
PrismObject<? extends FocusType> taskOwner = task.getOwner(result);
record.setInitiatorAndLoginParameter(taskOwner);
record.setTimestamp(System.currentTimeMillis());
record.setOutcome(OperationResultStatus.SUCCESS);
storeConnectionEnvironment(record, connEnv);
auditHelper.audit(record, null, task, result);
}
use of com.evolveum.midpoint.audit.api.AuditEventRecord in project midpoint by Evolveum.
the class SqaleRepoSmokeTest method test600AuditRecord.
@Test
public void test600AuditRecord() {
given("audit event record");
AuditEventRecord record = new AuditEventRecord(AuditEventType.ADD_OBJECT, AuditEventStage.EXECUTION);
OperationResult result = createOperationResult();
when("saving the event record");
auditService.audit(record, NullTaskImpl.INSTANCE, result);
then("operation is success and record ID is assigned");
assertThatOperationResult(result).isSuccess();
assertThat(record.getRepoId()).isNotNull();
}
use of com.evolveum.midpoint.audit.api.AuditEventRecord in project midpoint by Evolveum.
the class SqaleRepoSmokeTest method test601AuditRecordIgnoresProvidedId.
@Test
public void test601AuditRecordIgnoresProvidedId() {
given("audit event record with repoId");
AuditEventRecord record = new AuditEventRecord(AuditEventType.ADD_OBJECT, AuditEventStage.EXECUTION);
record.setRepoId(-47L);
OperationResult result = createOperationResult();
when("saving the event record");
auditService.audit(record, NullTaskImpl.INSTANCE, result);
then("operation is success and record ID is assigned, disregarding the provided one");
assertThatOperationResult(result).isSuccess();
assertThat(record.getRepoId()).isNotNull().isNotEqualTo(-47L);
}
use of com.evolveum.midpoint.audit.api.AuditEventRecord in project midpoint by Evolveum.
the class TestStrings method test222FormApproveByCheese.
/**
* Cheese approves, filling-in a form.
*/
@Test
public void test222FormApproveByCheese() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
dummyAuditService.clear();
dummyTransport.clearMessages();
given();
login(userAdministrator);
SearchResultList<CaseWorkItemType> workItems = getWorkItems(task, result);
CaseWorkItemType workItem = sortByOriginalAssignee(workItems).get(USER_CHEESE.oid);
assertNotNull("No work item for cheese", workItem);
when();
PrismObject<UserType> cheese = getUserFromRepo(USER_CHEESE.oid);
login(cheese);
ObjectDelta<UserType> formDelta = prismContext.deltaFor(UserType.class).item(UserType.F_DESCRIPTION).replace("Hello").asObjectDelta(USER_BOB.oid);
caseService.completeWorkItem(WorkItemId.of(workItem), ApprovalUtils.createApproveOutput(prismContext).comment("OK. LeChuck"), formDelta, task, result);
then();
login(userAdministrator);
workItems = getWorkItems(task, result);
displayWorkItems("Work item after 2nd approval", workItems);
assertEquals("Wrong # of work items after 2nd approval", 0, workItems.size());
CaseType aCase = getCase(CaseWorkItemUtil.getCaseRequired(workItem).getOid());
display("aCase after 2nd approval", aCase);
assertStage(aCase, 2, 2, "Role approvers (first)", null);
// notifications
List<Message> lifecycleMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_LIFECYCLE);
List<Message> allocationMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_ALLOCATION);
List<Message> processMessages = dummyTransport.getMessages(DUMMY_PROCESS);
display("work items lifecycle notifications", lifecycleMessages);
display("work items allocation notifications", allocationMessages);
display("processes notifications", processMessages);
// audit
displayDumpable("audit", dummyAuditService);
List<AuditEventRecord> records = dummyAuditService.getRecords();
if (records.size() != 4 && records.size() != 5) {
fail("Wrong # of audit records: " + records.size() + " (expected 4 or 5)");
}
AuditEventRecord record = records.get(0);
Collection<ObjectDeltaOperation<? extends ObjectType>> deltas = record.getDeltas();
assertEquals("Wrong # of deltas in audit record", 1, deltas.size());
ObjectDeltaOperation<? extends ObjectType> delta = deltas.iterator().next();
assertEquals("Wrong # of modifications in audit record delta", 2, delta.getObjectDelta().getModifications().size());
ItemDelta<?, ?> itemDelta = delta.getObjectDelta().getModifications().stream().filter(d -> UserType.F_DESCRIPTION.equivalent(d.getPath())).findFirst().orElse(null);
assertNotNull("No user.description item delta found", itemDelta);
assertEquals("Wrong value in delta", "Hello", itemDelta.getValuesToReplace().iterator().next().getRealValue());
// record #1, #2: cancellation of work items of other approvers
// record #3: finishing process execution
// optional #4: asynchronous execution in task
CaseType rootCase = getCase(aCase.getParentRef().getOid());
waitForCaseClose(rootCase, CASE_WAIT_TIMEOUT);
assertAssignedRole(getUser(USER_BOB.oid), ROLE_A_TEST_4.oid);
}
use of com.evolveum.midpoint.audit.api.AuditEventRecord in project midpoint by Evolveum.
the class AuditedLogoutHandler method auditEvent.
protected void auditEvent(HttpServletRequest request, Authentication authentication) {
// Eventually we should get this from the caller
OperationResult result = new OperationResult(OP_AUDIT_EVENT);
MidPointPrincipal principal = AuthUtil.getPrincipalUser(authentication);
PrismObject<? extends FocusType> user = principal != null ? principal.getFocus().asPrismObject() : null;
String channel = SchemaConstants.CHANNEL_USER_URI;
String sessionId = request.getRequestedSessionId();
if (authentication instanceof MidpointAuthentication && ((MidpointAuthentication) authentication).getAuthenticationChannel() != null) {
channel = ((MidpointAuthentication) authentication).getAuthenticationChannel().getChannelId();
if (((MidpointAuthentication) authentication).getSessionId() != null) {
sessionId = ((MidpointAuthentication) authentication).getSessionId();
}
}
SystemConfigurationType system = null;
try {
system = systemObjectCache.getSystemConfiguration(result).asObjectable();
} catch (SchemaException e) {
LOGGER.error("Couldn't get system configuration from cache", e);
}
if (!SecurityUtil.isAuditedLoginAndLogout(system, channel)) {
return;
}
Task task = taskManager.createTaskInstance();
task.setOwner(user);
task.setChannel(channel);
AuditEventRecord record = new AuditEventRecord(AuditEventType.TERMINATE_SESSION, AuditEventStage.REQUEST);
record.setInitiator(user);
record.setParameter(AuthSequenceUtil.getName(user));
record.setChannel(channel);
record.setTimestamp(System.currentTimeMillis());
record.setOutcome(OperationResultStatus.SUCCESS);
// probably not needed, as audit service would take care of it; but it doesn't hurt so let's keep it here
record.setHostIdentifier(request.getLocalName());
record.setRemoteHostAddress(request.getLocalAddr());
record.setNodeIdentifier(taskManager.getNodeId());
record.setSessionIdentifier(sessionId);
auditService.audit(record, task, result);
}
Aggregations