Search in sources :

Example 21 with NHINDAddress

use of org.nhindirect.stagent.NHINDAddress in project nhin-d by DirectProject.

the class NHINDSecurityAndTrustMailet_service_Test method testService_RejectRecipients_AssertRejectedList.

@SuppressWarnings("unused")
public void testService_RejectRecipients_AssertRejectedList() throws Exception {
    final MimeMessage mimeMsg = EntitySerializer.Default.deserialize(TestUtils.readMessageResource("PlainOutgoingMessage.txt"));
    final SmtpAgent mockAgent = mock(SmtpAgent.class);
    when(mockAgent.processMessage((MimeMessage) any(), (NHINDAddressCollection) any(), (NHINDAddress) any())).thenAnswer(new Answer<MessageProcessResult>() {

        public MessageProcessResult answer(InvocationOnMock invocation) throws Throwable {
            usedRecipients = (NHINDAddressCollection) invocation.getArguments()[1];
            usedRecipients.get(0).setStatus(TrustEnforcementStatus.Failed);
            usedRecipients.get(1).setStatus(TrustEnforcementStatus.Success);
            usedSender = (NHINDAddress) invocation.getArguments()[2];
            MyMessageEnvelope env = new MyMessageEnvelope(new Message(mimeMsg), usedRecipients, usedSender);
            env.setAgent(new MockNHINDAgent(Arrays.asList("cerner.com")));
            env.categorizeRecipients(TrustEnforcementStatus.Success);
            NHINDAddressCollection rejectedRecips = env.getRejectedRecipients();
            return new MessageProcessResult(env, null);
        }
    });
    final Mail mockMail = mock(MockMail.class, CALLS_REAL_METHODS);
    mockMail.setRecipients(Arrays.asList(new MailAddress("you@cerner.com"), new MailAddress("they@cerner.com")));
    when(mockMail.getSender()).thenReturn(new MailAddress("me@cerner.com"));
    mockMail.setMessage(mimeMsg);
    NHINDSecurityAndTrustMailet mailet = new NHINDSecurityAndTrustMailet();
    mailet.agent = mockAgent;
    mailet.service(mockMail);
    assertEquals(1, mockMail.getRecipients().size());
}
Also used : MailAddress(org.apache.mailet.MailAddress) Message(org.nhindirect.stagent.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) NHINDAddressCollection(org.nhindirect.stagent.NHINDAddressCollection) SmtpAgent(org.nhindirect.gateway.smtp.SmtpAgent) MessageProcessResult(org.nhindirect.gateway.smtp.MessageProcessResult) NHINDAddress(org.nhindirect.stagent.NHINDAddress) MockNHINDAgent(org.nhindirect.stagent.MockNHINDAgent) Mail(org.apache.mailet.Mail) MimeMessage(javax.mail.internet.MimeMessage) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Example 22 with NHINDAddress

use of org.nhindirect.stagent.NHINDAddress in project nhin-d by DirectProject.

the class TrustModel method findTrustedSignature.

protected DefaultMessageSignatureImpl findTrustedSignature(IncomingMessage message, Collection<X509Certificate> anchors) {
    NHINDAddress sender = message.getSender();
    Collection<DefaultMessageSignatureImpl> signatures = message.getSenderSignatures();
    DefaultMessageSignatureImpl lastTrustedSignature = null;
    for (DefaultMessageSignatureImpl signature : signatures) {
        if (certChainValidator.isTrusted(signature.getSignerCert(), anchors) && signature.checkSignature()) {
            if (!sender.hasCertificates())
                // Can't really check thumbprints etc. So, this is about as good as its going to get
                return signature;
            if (signature.checkThumbprint(sender)) {
                return signature;
            }
            //
            // We'll save this guy, but keep looking for a signer whose thumbprint we can verify
            // If we can't find one, we'll use the last trusted signer we found.. and just mark the recipient's trust
            // enforcement status as Success_ThumbprintMismatch
            //    
            lastTrustedSignature = signature;
        }
    }
    return lastTrustedSignature;
}
Also used : NHINDAddress(org.nhindirect.stagent.NHINDAddress) DefaultMessageSignatureImpl(org.nhindirect.stagent.DefaultMessageSignatureImpl)

Aggregations

NHINDAddress (org.nhindirect.stagent.NHINDAddress)22 NHINDAddressCollection (org.nhindirect.stagent.NHINDAddressCollection)15 MimeMessage (javax.mail.internet.MimeMessage)11 ArrayList (java.util.ArrayList)6 Tx (org.nhindirect.common.tx.model.Tx)6 Address (javax.mail.Address)5 InternetAddress (javax.mail.internet.InternetAddress)5 MailAddress (org.apache.mailet.MailAddress)5 Message (org.nhindirect.stagent.mail.Message)5 NotificationMessage (org.nhindirect.stagent.mail.notifications.NotificationMessage)5 Collection (java.util.Collection)4 MessagingException (javax.mail.MessagingException)4 DefaultMessageSignatureImpl (org.nhindirect.stagent.DefaultMessageSignatureImpl)4 ServiceException (org.nhindirect.common.rest.exceptions.ServiceException)3 TxDetail (org.nhindirect.common.tx.model.TxDetail)3 MessageProcessResult (org.nhindirect.gateway.smtp.MessageProcessResult)3 Header (javax.mail.Header)2 MimeBodyPart (javax.mail.internet.MimeBodyPart)2 Mail (org.apache.mailet.Mail)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2