Search in sources :

Example 16 with AuditEventRecord

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());
    }
}
Also used : AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord)

Example 17 with AuditEventRecord

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);
}
Also used : DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SQLQuery(org.hibernate.SQLQuery) Query(org.hibernate.Query) PrismObject(com.evolveum.midpoint.prism.PrismObject) ScrollableResults(org.hibernate.ScrollableResults) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) Session(org.hibernate.Session)

Example 18 with AuditEventRecord

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
}
Also used : ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException)

Example 19 with AuditEventRecord

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);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) QName(javax.xml.namespace.QName) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismObject(com.evolveum.midpoint.prism.PrismObject) Fault(org.apache.cxf.interceptor.Fault) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord)

Example 20 with AuditEventRecord

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;
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) Jsr223ScriptEvaluator(com.evolveum.midpoint.model.common.expression.script.jsr223.Jsr223ScriptEvaluator) Task(com.evolveum.midpoint.task.api.Task) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) FunctionLibrary(com.evolveum.midpoint.model.common.expression.functions.FunctionLibrary) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Collection(java.util.Collection) PrismObject(com.evolveum.midpoint.prism.PrismObject) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord)

Aggregations

AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)83 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)28 Task (com.evolveum.midpoint.task.api.Task)18 Test (org.testng.annotations.Test)18 ObjectDeltaOperation (com.evolveum.midpoint.schema.ObjectDeltaOperation)11 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)9 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)7 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)6 ArrayList (java.util.ArrayList)6 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)5 NullTaskImpl (com.evolveum.midpoint.task.api.test.NullTaskImpl)5 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 MAuditEventRecord (com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord)4 AuditResultHandler (com.evolveum.midpoint.audit.api.AuditResultHandler)3 MidpointAuthentication (com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)3 Message (com.evolveum.midpoint.notifications.api.transports.Message)3 QAuditEventRecord (com.evolveum.midpoint.repo.sql.audit.querymodel.QAuditEventRecord)3 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3 AuditEventRecordType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType)3