Search in sources :

Example 11 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)

Example 12 with AuditEvent

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

the class DefaultSmtpAgent_AuditMessage_Test method testAuditIncomingMessage_AssertEventsAudited.

public void testAuditIncomingMessage_AssertEventsAudited() throws Exception {
    new TestPlan() {

        protected String getMessageToProcess() throws Exception {
            return TestUtils.readMessageResource("PlainIncomingMessage.txt");
        }

        @Override
        protected void doAssertions(MessageProcessResult result) throws Exception {
            DefaultSmtpAgent smtpAgent = (DefaultSmtpAgent) agent;
            assertNotNull(smtpAgent.getAuditor());
            assertTrue(smtpAgent.getAuditor() instanceof MockAuditor);
            assertTrue(auditor.getEvents().size() > 0);
            boolean foundIncomingType = false;
            boolean foundMDNType = false;
            for (Entry<AuditEvent, Collection<? extends AuditContext>> entry : auditor.getEvents().entrySet()) {
                AuditEvent event = entry.getKey();
                assertEquals(event.getType(), "SMTP Direct Message Processing");
                if (event.getName().equals(AuditEvents.INCOMING_MESSAGE_NAME))
                    foundIncomingType = true;
                else if (event.getName().equals(AuditEvents.PRODUCE_MDN_NAME)) {
                    boolean foundFinalRecip = false;
                    boolean foundOrigMsgId = false;
                    boolean foundDisp = false;
                    for (AuditContext ctx : entry.getValue()) {
                        if (ctx.getContextName().equals(MDNStandard.Headers.FinalRecipient)) {
                            foundFinalRecip = true;
                        } else if (ctx.getContextName().equals(MDNStandard.Headers.OriginalMessageID)) {
                            foundOrigMsgId = true;
                        } else if (ctx.getContextName().equals(MDNStandard.Headers.Disposition)) {
                            assertEquals("automatic-action/MDN-sent-automatically;processed", ctx.getContextValue());
                            foundDisp = true;
                        }
                    }
                    assertTrue(foundFinalRecip);
                    assertTrue(foundOrigMsgId);
                    assertTrue(foundDisp);
                    foundMDNType = true;
                // assert attributes of the event
                }
            }
            assertTrue(foundIncomingType);
            assertTrue(foundMDNType);
        }
    }.perform();
}
Also used : Entry(java.util.Map.Entry) BaseTestPlan(org.nhindirect.gateway.testutils.BaseTestPlan) AuditEvent(org.nhindirect.common.audit.AuditEvent) AuditContext(org.nhindirect.common.audit.AuditContext)

Example 13 with AuditEvent

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

the class FileAuditorTest method testGetEvents_RequestLessThanAvailable_AssertGotOnlyRecords.

@Test
public void testGetEvents_RequestLessThanAvailable_AssertGotOnlyRecords() {
    FileAuditor auditor = new FileAuditor(auditFile);
    auditor.clear();
    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");
    auditor.audit(PRINCIPAL, event1);
    auditor.audit(PRINCIPAL, event2, Arrays.asList(context1, context2));
    CompositeData[] events = auditor.getEvents(1);
    assertNotNull(events);
    assertEquals(1, 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 14 with AuditEvent

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

the class FileAuditorTest method testGetEvents_NoRecordsRequested_ReturnedRecords.

@Test
public void testGetEvents_NoRecordsRequested_ReturnedRecords() {
    FileAuditor auditor = new FileAuditor(auditFile);
    auditor.clear();
    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");
    auditor.audit(PRINCIPAL, event1);
    auditor.audit(PRINCIPAL, event2, Arrays.asList(context1, context2));
    CompositeData[] events = auditor.getEvents(0);
    assertNull(events);
}
Also used : DefaultAuditContext(org.nhindirect.common.audit.DefaultAuditContext) CompositeData(javax.management.openmbean.CompositeData) AuditEvent(org.nhindirect.common.audit.AuditEvent) Test(org.junit.Test)

Example 15 with AuditEvent

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

the class FileAuditorTest method testGetLastEvent_AssertRecordContent.

@Test
public void testGetLastEvent_AssertRecordContent() {
    FileAuditor auditor = new FileAuditor(auditFile);
    AuditEvent event1 = new AuditEvent("Category" + UUID.randomUUID(), "type");
    AuditEvent event2 = new AuditEvent("Category" + UUID.randomUUID(), "type");
    auditor.audit(PRINCIPAL, event1);
    auditor.audit(PRINCIPAL, event2);
    assertNotNull(auditor.getLastEvent());
    CompositeData lastMessage = auditor.getLastEvent();
    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"));
}
Also used : CompositeData(javax.management.openmbean.CompositeData) AuditEvent(org.nhindirect.common.audit.AuditEvent) Test(org.junit.Test)

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