use of org.nhindirect.common.audit.AuditContext in project nhin-d by DirectProject.
the class DefaultSmtpAgent method postProcessIncomingMessage.
private void postProcessIncomingMessage(MessageProcessResult result) {
this.copyMessage(result.getProcessedMessage().getMessage(), settings.getIncomingMessageSettings());
// check if we need to create notification messages
try {
if (settings.getNotificationProducer() != null) {
result.setNotificationMessages(settings.getNotificationProducer().produce((IncomingMessage) result.getProcessedMessage()));
if (result.getNotificationMessages() != null && auditor != null) {
for (NotificationMessage noteMsg : result.getNotificationMessages()) {
Collection<AuditContext> contexts = createContextCollectionFromMessage(noteMsg, Arrays.asList(AuditEvents.MDN_HEADER_CONTEXT));
auditor.audit(PRINICPAL, new AuditEvent(AuditEvents.PRODUCE_MDN_NAME, AuditEvents.EVENT_TYPE), contexts);
}
}
}
} catch (Exception e) {
// don't bail on the whole process if we can't create notifications messages
LOGGER.error("Failed to create notification messages.", e);
}
// check if this is an incoming MDN message... is so, audit it
if (NotificationHelper.isMDN(result.getProcessedMessage().getMessage())) {
Collection<AuditContext> contexts = createContextCollectionFromMessage(result.getProcessedMessage(), Arrays.asList(AuditEvents.MDN_RECEIVED_CONTEXT));
auditor.audit(PRINICPAL, new AuditEvent(AuditEvents.MDN_RECEIVED_NAME, AuditEvents.EVENT_TYPE), contexts);
}
}
use of org.nhindirect.common.audit.AuditContext in project nhin-d by DirectProject.
the class FileAuditor method buildRecordText.
/*
* builds the text of the record that will be placed in the file
*/
private String buildRecordText(UUID eventId, Calendar eventTimeStamp, String principal, AuditEvent event, Collection<? extends AuditContext> contexts) {
StringBuilder builder = new StringBuilder();
builder.append("\r\n" + EVENT_ID + ": " + eventId + EVENT_TAG_DELIMITER);
builder.append("\t" + EVENT_TIME + ": " + df.format(eventTimeStamp.getTime()) + EVENT_TAG_DELIMITER);
builder.append("\t" + EVENT_PRINCIPAL + ": " + principal + EVENT_TAG_DELIMITER);
builder.append("\t" + EVENT_NAME + ": " + event.getName() + EVENT_TAG_DELIMITER);
builder.append("\t" + EVENT_TYPE + ": " + event.getType() + EVENT_TAG_DELIMITER);
if (contexts != null && contexts.size() > 0) {
builder.append("\t" + EVENT_CTX + CONTEXT_TAG_DELIMITER);
for (AuditContext context : contexts) builder.append("\t\t" + context.getContextName() + ":" + context.getContextValue() + CONTEXT_TAG_DELIMITER);
builder.append(EVENT_TAG_DELIMITER);
}
builder.append("\r\n");
return builder.toString();
}
use of org.nhindirect.common.audit.AuditContext in project nhin-d by DirectProject.
the class LoggingAuditor method buildEventString.
/*
* Builds the string that will be written to the logging sub system.
*/
private String buildEventString(UUID eventId, String principal, AuditEvent event, Collection<? extends AuditContext> contexts) {
StringBuilder builder = new StringBuilder(EVENT_TAG);
builder.append("\r\n\t" + EVENT_ID + ": " + eventId);
builder.append("\r\n\t" + EVENT_PRINCIPAL + ": " + principal);
builder.append("\r\n\t" + EVENT_NAME + ": " + event.getName());
builder.append("\r\n\t" + EVENT_TYPE + ": " + event.getType());
if (contexts != null && contexts.size() > 0) {
builder.append("\r\n\t" + EVENT_CTX);
for (AuditContext context : contexts) builder.append("\r\n\t\t" + context.getContextName() + ":" + context.getContextValue());
}
return builder.toString();
}
use of org.nhindirect.common.audit.AuditContext in project nhin-d by DirectProject.
the class RDBMSDaoImpl method writeRDBMSEvent.
@Override
@Transactional(readOnly = false)
public void writeRDBMSEvent(UUID eventId, Calendar eventTimeStamp, String principal, AuditEvent event, Collection<? extends AuditContext> contexts) {
try {
validateState();
final org.nhindirect.common.audit.impl.entity.AuditEvent newEvent = new org.nhindirect.common.audit.impl.entity.AuditEvent();
newEvent.setEventName(event.getName());
newEvent.setEventType(event.getType());
newEvent.setEventTime(Calendar.getInstance(Locale.getDefault()));
newEvent.setPrincipal(principal);
newEvent.setUUID(eventId.toString());
if (contexts != null) {
final Collection<org.nhindirect.common.audit.impl.entity.AuditContext> entityContexts = newEvent.getAuditContexts();
for (AuditContext context : contexts) {
final org.nhindirect.common.audit.impl.entity.AuditContext newContext = new org.nhindirect.common.audit.impl.entity.AuditContext();
newContext.setContextName(context.getContextName());
newContext.setContextValue(context.getContextValue());
newContext.setAuditEvent(newEvent);
entityContexts.add(newContext);
}
}
entityManager.persist(newEvent);
entityManager.flush();
} catch (Throwable e) {
LOGGER.error("Failed to write audit event to RDBMS store: " + e.getMessage(), e);
}
}
use of org.nhindirect.common.audit.AuditContext in project nhin-d by DirectProject.
the class DefaultSmtpAgent method processEnvelope.
/*
* Processes a message using the securty and trust agent.
*/
protected MessageEnvelope processEnvelope(MessageEnvelope envelope) {
MessageEnvelope processedMessage = null;
boolean isOutgoing = isOutgoing(envelope);
if (isOutgoing) {
if (auditor != null) {
Collection<AuditContext> contexts = createContextCollectionFromMessage(envelope, Arrays.asList(AuditEvents.DEFAULT_HEADER_CONTEXT));
auditor.audit(PRINICPAL, new AuditEvent(AuditEvents.OUTGOING_MESSAGE_NAME, AuditEvents.EVENT_TYPE), contexts);
}
LOGGER.debug("Sending outgoing message from " + envelope.getSender().toString() + " to STAgent");
} else {
if (auditor != null) {
Collection<AuditContext> contexts = createContextCollectionFromMessage(envelope, Arrays.asList(AuditEvents.DEFAULT_HEADER_CONTEXT));
auditor.audit(PRINICPAL, new AuditEvent(AuditEvents.INCOMING_MESSAGE_NAME, AuditEvents.EVENT_TYPE), contexts);
}
LOGGER.debug("Sending incoming message from " + envelope.getSender().toString() + " to STAgent");
}
processedMessage = (isOutgoing) ? agent.processOutgoing(envelope) : agent.processIncoming(envelope);
return processedMessage;
}
Aggregations