Search in sources :

Example 6 with AuditContext

use of org.nhindirect.common.audit.AuditContext 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 7 with AuditContext

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

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