Search in sources :

Example 1 with AuditContext

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);
    }
}
Also used : NotificationMessage(org.nhindirect.stagent.mail.notifications.NotificationMessage) IncomingMessage(org.nhindirect.stagent.IncomingMessage) AuditEvent(org.nhindirect.common.audit.AuditEvent) AuditContext(org.nhindirect.common.audit.AuditContext) DefaultAuditContext(org.nhindirect.common.audit.DefaultAuditContext) MessagingException(javax.mail.MessagingException) AgentException(org.nhindirect.stagent.AgentException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) NHINDException(org.nhindirect.stagent.NHINDException)

Example 2 with AuditContext

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();
}
Also used : AuditContext(org.nhindirect.common.audit.AuditContext)

Example 3 with AuditContext

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();
}
Also used : AuditContext(org.nhindirect.common.audit.AuditContext)

Example 4 with AuditContext

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);
    }
}
Also used : AuditEvent(org.nhindirect.common.audit.AuditEvent) AuditContext(org.nhindirect.common.audit.AuditContext) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with AuditContext

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;
}
Also used : AuditEvent(org.nhindirect.common.audit.AuditEvent) DefaultMessageEnvelope(org.nhindirect.stagent.DefaultMessageEnvelope) MessageEnvelope(org.nhindirect.stagent.MessageEnvelope) AuditContext(org.nhindirect.common.audit.AuditContext) DefaultAuditContext(org.nhindirect.common.audit.DefaultAuditContext)

Aggregations

AuditContext (org.nhindirect.common.audit.AuditContext)7 AuditEvent (org.nhindirect.common.audit.AuditEvent)5 DefaultAuditContext (org.nhindirect.common.audit.DefaultAuditContext)3 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 Entry (java.util.Map.Entry)1 MessagingException (javax.mail.MessagingException)1 BaseTestPlan (org.nhindirect.gateway.testutils.BaseTestPlan)1 AgentException (org.nhindirect.stagent.AgentException)1 DefaultMessageEnvelope (org.nhindirect.stagent.DefaultMessageEnvelope)1 IncomingMessage (org.nhindirect.stagent.IncomingMessage)1 MessageEnvelope (org.nhindirect.stagent.MessageEnvelope)1 NHINDAddress (org.nhindirect.stagent.NHINDAddress)1 NHINDException (org.nhindirect.stagent.NHINDException)1 OutgoingMessage (org.nhindirect.stagent.OutgoingMessage)1 NotificationMessage (org.nhindirect.stagent.mail.notifications.NotificationMessage)1 Transactional (org.springframework.transaction.annotation.Transactional)1