use of org.forgerock.openam.audit.AMAuditEventBuilder in project OpenAM by OpenRock.
the class LogWriter method logToAuditService.
private static void logToAuditService(int type, String msgid, String[] msgdata, SSOToken ssoToken, LogMessageProvider msgProvider, SSOToken adminSSOToken) throws Exception {
String operation = msgid.substring(msgid.indexOf('_') + 1);
LogMessageID logMessageID = msgProvider.getAllHashMessageIDs().get(msgid);
if (logMessageID == null) {
DEBUG.error("Attempted audit logging for unknown message ID {}", msgid);
return;
}
List<String> fields = logMessageID.getDataColumns();
AMAuditEventBuilder builder;
String topic;
if ("LOGIN".equals(operation) && !msgid.startsWith("ATTEMPT")) {
builder = authenticationEventBuilder(type, msgid, fields, msgdata);
topic = AuditConstants.AUTHENTICATION_TOPIC;
} else if (!"LOGIN".equals(operation)) {
builder = accessEventBuilder(type, msgid, msgdata, operation, fields);
topic = AuditConstants.ACCESS_TOPIC;
} else {
return;
}
JsonValue eventJson = builder.transactionId(CommandManager.TRANSACTION_ID.getValue()).timestamp(System.currentTimeMillis()).userId(ssoToken.getPrincipal().getName()).trackingIdFromSSOToken(ssoToken).component(AuditConstants.Component.SSOADM).toEvent().getValue();
String sessionId = adminSSOToken.getTokenID().toString();
sendEvent(topic, eventJson, sessionId, new SessionID(sessionId).getSessionServerURL());
}
Aggregations