use of com.evolveum.midpoint.audit.api.AuditEventRecord in project midpoint by Evolveum.
the class DummyAuditService method assertLoginLogout.
/**
* Checks that the first record is login and the last is logout.
*/
public void assertLoginLogout(String expectedChannel) {
AuditEventRecord firstRecord = records.get(0);
assertEquals("Wrong type of first audit record: " + firstRecord.getEventType(), AuditEventType.CREATE_SESSION, firstRecord.getEventType());
assertEquals("Wrong outcome of first audit record: " + firstRecord.getOutcome(), OperationResultStatus.SUCCESS, firstRecord.getOutcome());
AuditEventRecord lastRecord = records.get(records.size() - 1);
assertEquals("Wrong type of last audit record: " + lastRecord.getEventType(), AuditEventType.TERMINATE_SESSION, lastRecord.getEventType());
assertEquals("Wrong outcome of last audit record: " + lastRecord.getOutcome(), OperationResultStatus.SUCCESS, lastRecord.getOutcome());
assertEquals("Audit session ID does not match", firstRecord.getSessionIdentifier(), lastRecord.getSessionIdentifier());
assertFalse("Same login and logout event IDs", firstRecord.getEventIdentifier().equals(lastRecord.getEventIdentifier()));
if (expectedChannel != null) {
assertEquals("Wrong channel in first audit record", expectedChannel, firstRecord.getChannel());
assertEquals("Wrong channel in last audit record", expectedChannel, lastRecord.getChannel());
}
}
use of com.evolveum.midpoint.audit.api.AuditEventRecord in project midpoint by Evolveum.
the class SqlAuditServiceImpl method listRecordsIterativeAttempt.
private void listRecordsIterativeAttempt(String query, Map<String, Object> params, AuditResultHandler handler) {
Session session = null;
int count = 0;
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("List records attempt\n query: {}\n params:\n{}", query, DebugUtil.debugDump(params, 2));
}
try {
session = baseHelper.beginReadOnlyTransaction();
Query q;
if (StringUtils.isBlank(query)) {
query = "from RAuditEventRecord as aer where 1=1 order by aer.timestamp desc";
q = session.createQuery(query);
setParametersToQuery(q, params);
} else {
q = session.createQuery(query);
setParametersToQuery(q, params);
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("List records attempt\n processed query: {}", q);
}
ScrollableResults resultList = q.scroll();
while (resultList.next()) {
Object o = resultList.get(0);
if (!(o instanceof RAuditEventRecord)) {
throw new DtoTranslationException("Unexpected object in result set. Expected audit record, but got " + o.getClass().getSimpleName());
}
RAuditEventRecord raudit = (RAuditEventRecord) o;
AuditEventRecord audit = RAuditEventRecord.fromRepo(raudit, getPrismContext());
// TODO what if original name (in audit log) differs from the current one (in repo) ?
audit.setInitiator(resolve(session, raudit.getInitiatorOid(), raudit.getInitiatorName(), RObjectType.USER));
audit.setTarget(resolve(session, raudit.getTargetOid(), raudit.getTargetName(), raudit.getTargetType()));
audit.setTargetOwner(resolve(session, raudit.getTargetOwnerOid(), raudit.getTargetOwnerName(), RObjectType.USER));
count++;
if (!handler.handle(audit)) {
LOGGER.trace("Skipping handling of objects after {} was handled. ", audit);
break;
}
}
session.getTransaction().commit();
} catch (DtoTranslationException | SchemaException ex) {
baseHelper.handleGeneralCheckedException(ex, session, null);
} catch (RuntimeException ex) {
baseHelper.handleGeneralRuntimeException(ex, session, null);
} finally {
baseHelper.cleanupSessionAndResult(session, null);
}
LOGGER.trace("List records iterative attempt processed {} records", count);
}
use of com.evolveum.midpoint.audit.api.AuditEventRecord 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
}
use of com.evolveum.midpoint.audit.api.AuditEventRecord in project midpoint by Evolveum.
the class ReportWebService method evaluateAuditScript.
@Override
public AuditEventRecordListType evaluateAuditScript(String script, RemoteReportParametersType parameters) {
try {
Map<QName, Object> params = getParamsMap(parameters);
Collection<AuditEventRecord> resultList = reportService.evaluateAuditScript(script, params);
return createAuditEventRecordListType(resultList);
} catch (SchemaException | ExpressionEvaluationException | ObjectNotFoundException e) {
// TODO Auto-generated catch block
throw new Fault(e);
}
}
use of com.evolveum.midpoint.audit.api.AuditEventRecord in project midpoint by Evolveum.
the class ReportServiceImpl method evaluateAuditScript.
public Collection<AuditEventRecord> evaluateAuditScript(String script, Map<QName, Object> parameters) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
Collection<AuditEventRecord> results = new ArrayList<AuditEventRecord>();
ExpressionVariables variables = new ExpressionVariables();
variables.addVariableDefinition(new QName("auditParams"), getConvertedParams(parameters));
Task task = taskManager.createTaskInstance(ReportService.class.getName() + ".searchObjects()");
OperationResult parentResult = task.getResult();
Collection<FunctionLibrary> functions = createFunctionLibraries();
Jsr223ScriptEvaluator scripts = new Jsr223ScriptEvaluator("Groovy", prismContext, prismContext.getDefaultProtector());
ModelExpressionThreadLocalHolder.pushExpressionEnvironment(new ExpressionEnvironment<>(task, task.getResult()));
Object o = null;
try {
o = scripts.evaluateReportScript(script, variables, objectResolver, functions, "desc", parentResult);
} finally {
ModelExpressionThreadLocalHolder.popExpressionEnvironment();
}
if (o != null) {
if (Collection.class.isAssignableFrom(o.getClass())) {
Collection resultSet = (Collection) o;
if (resultSet != null && !resultSet.isEmpty()) {
for (Object obj : resultSet) {
if (!(obj instanceof AuditEventRecord)) {
LOGGER.warn("Skipping result, not an audit event record " + obj);
continue;
}
results.add((AuditEventRecord) obj);
}
}
} else {
results.add((AuditEventRecord) o);
}
}
return results;
}
Aggregations