Search in sources :

Example 16 with AuditEvent

use of org.nhindirect.common.audit.AuditEvent in project nhin-d by DirectProject.

the class RDBMSAuditor_getEventsTest method testGetEvents_RequestMoreThanAvailable_AssertGotAllAvailableRecords.

@Test
public void testGetEvents_RequestMoreThanAvailable_AssertGotAllAvailableRecords() {
    AuditEvent event1 = new AuditEvent("Category" + UUID.randomUUID(), "type");
    AuditEvent event2 = new AuditEvent("Category" + UUID.randomUUID(), "type");
    DefaultAuditContext context1 = new DefaultAuditContext("name1", "value1");
    DefaultAuditContext context2 = new DefaultAuditContext("name2", "value2");
    auditorImpl.audit(PRINCIPAL, event1);
    auditorImpl.audit(PRINCIPAL, event2, Arrays.asList(context1, context2));
    CompositeData[] events = auditorImpl.getEvents(5);
    assertNotNull(events);
    assertEquals(2, events.length);
    CompositeData lastMessage = events[0];
    assertEquals(event2.getName(), lastMessage.get("Event Name"));
    assertEquals(event2.getType(), lastMessage.get("Event Type"));
    assertTrue(lastMessage.get("Event Id").toString().length() > 0);
    assertTrue(lastMessage.get("Event Time").toString().length() > 0);
    assertNotNull(lastMessage.get("Contexts"));
    String[] contexts = (String[]) lastMessage.get("Contexts");
    assertEquals(2, contexts.length);
    assertEquals("name1:value1", contexts[0]);
    assertEquals("name2:value2", contexts[1]);
}
Also used : DefaultAuditContext(org.nhindirect.common.audit.DefaultAuditContext) CompositeData(javax.management.openmbean.CompositeData) AuditEvent(org.nhindirect.common.audit.AuditEvent) Test(org.junit.Test)

Example 17 with AuditEvent

use of org.nhindirect.common.audit.AuditEvent in project nhin-d by DirectProject.

the class RDBMSAuditor_getLastEventTest method testGetLastEventTest_noContexts_lastEventRetrieved.

@Test
public void testGetLastEventTest_noContexts_lastEventRetrieved() throws Exception {
    final AuditEvent auditEvent = new AuditEvent("name1", "value1");
    this.auditorImpl.audit("testPin", auditEvent, null);
    final CompositeData lastMessage = auditorImpl.getLastEvent();
    assertNotNull(lastMessage);
    assertEquals(auditEvent.getName(), lastMessage.get("Event Name"));
    assertEquals(auditEvent.getType(), lastMessage.get("Event Type"));
    assertTrue(lastMessage.get("Event Id").toString().length() > 0);
    assertTrue(lastMessage.get("Event Time").toString().length() > 0);
    assertNotNull(lastMessage.get("Contexts"));
    String[] contexts = (String[]) lastMessage.get("Contexts");
    assertEquals(1, contexts.length);
}
Also used : CompositeData(javax.management.openmbean.CompositeData) AuditEvent(org.nhindirect.common.audit.AuditEvent) Test(org.junit.Test)

Example 18 with AuditEvent

use of org.nhindirect.common.audit.AuditEvent in project nhin-d by DirectProject.

the class RDBMSAuditor_getLastEventTest method testGetLastEventTest_withContexts_lastEventRetrieved.

@Test
public void testGetLastEventTest_withContexts_lastEventRetrieved() throws Exception {
    final AuditEvent auditEvent = new AuditEvent("name1", "value1");
    final DefaultAuditContext context1 = new DefaultAuditContext("name1", "value1");
    final DefaultAuditContext context2 = new DefaultAuditContext("name2", "value2");
    this.auditorImpl.audit("testPin", auditEvent, Arrays.asList(context1, context2));
    final CompositeData lastMessage = auditorImpl.getLastEvent();
    assertNotNull(lastMessage);
    assertEquals(auditEvent.getName(), lastMessage.get("Event Name"));
    assertEquals(auditEvent.getType(), lastMessage.get("Event Type"));
    assertTrue(lastMessage.get("Event Id").toString().length() > 0);
    assertTrue(lastMessage.get("Event Time").toString().length() > 0);
    assertNotNull(lastMessage.get("Contexts"));
    String[] contexts = (String[]) lastMessage.get("Contexts");
    assertEquals(2, contexts.length);
    assertEquals("name1:value1", contexts[0]);
    assertEquals("name2:value2", contexts[1]);
}
Also used : DefaultAuditContext(org.nhindirect.common.audit.DefaultAuditContext) CompositeData(javax.management.openmbean.CompositeData) AuditEvent(org.nhindirect.common.audit.AuditEvent) Test(org.junit.Test)

Example 19 with AuditEvent

use of org.nhindirect.common.audit.AuditEvent 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)

Example 20 with AuditEvent

use of org.nhindirect.common.audit.AuditEvent in project nhin-d by DirectProject.

the class DefaultSmtpAgent method postProcessMessage.

private void postProcessMessage(MessageProcessResult result) {
    boolean isOutgoing = (result.getProcessedMessage() instanceof OutgoingMessage);
    // check for rejected recipients
    if (auditor != null && result.getProcessedMessage().getRejectedRecipients() != null && result.getProcessedMessage().getRejectedRecipients().size() > 0) {
        Collection<AuditContext> contexts = createContextCollectionFromMessage(result.getProcessedMessage(), Arrays.asList(AuditEvents.DEFAULT_HEADER_CONTEXT));
        StringBuffer rejectedRecips = new StringBuffer();
        int cnt = 0;
        for (NHINDAddress address : result.getProcessedMessage().getRejectedRecipients()) {
            rejectedRecips.append(address.getAddress());
            if (++cnt < result.getProcessedMessage().getRejectedRecipients().size())
                rejectedRecips.append(", ");
        }
        contexts.add(new DefaultAuditContext(AuditEvents.REJECTED_RECIPIENTS_CONTEXT, rejectedRecips.toString()));
        auditor.audit(PRINICPAL, new AuditEvent(AuditEvents.REJECTED_RECIP_NAME, AuditEvents.EVENT_TYPE), contexts);
    }
    if (isOutgoing)
        postProcessOutgoingMessage(result);
    else
        postProcessIncomingMessage(result);
}
Also used : DefaultAuditContext(org.nhindirect.common.audit.DefaultAuditContext) NHINDAddress(org.nhindirect.stagent.NHINDAddress) OutgoingMessage(org.nhindirect.stagent.OutgoingMessage) AuditEvent(org.nhindirect.common.audit.AuditEvent) AuditContext(org.nhindirect.common.audit.AuditContext) DefaultAuditContext(org.nhindirect.common.audit.DefaultAuditContext)

Aggregations

AuditEvent (org.nhindirect.common.audit.AuditEvent)21 DefaultAuditContext (org.nhindirect.common.audit.DefaultAuditContext)15 CompositeData (javax.management.openmbean.CompositeData)14 Test (org.junit.Test)14 AuditContext (org.nhindirect.common.audit.AuditContext)5 IOException (java.io.IOException)2 UnknownHostException (java.net.UnknownHostException)2 MessagingException (javax.mail.MessagingException)2 AgentException (org.nhindirect.stagent.AgentException)2 DefaultMessageEnvelope (org.nhindirect.stagent.DefaultMessageEnvelope)2 IncomingMessage (org.nhindirect.stagent.IncomingMessage)2 MessageEnvelope (org.nhindirect.stagent.MessageEnvelope)2 NHINDAddress (org.nhindirect.stagent.NHINDAddress)2 NHINDException (org.nhindirect.stagent.NHINDException)2 OutgoingMessage (org.nhindirect.stagent.OutgoingMessage)2 NotificationMessage (org.nhindirect.stagent.mail.notifications.NotificationMessage)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Entry (java.util.Map.Entry)1