Search in sources :

Example 16 with NHINDAddressCollection

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

the class NHINDSecurityAndTrustMailet_service_Test method testService_UseToHeader_AssertRecipientsUsed.

public void testService_UseToHeader_AssertRecipientsUsed() 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];
            return new MessageProcessResult(new DefaultMessageEnvelope(new Message(mimeMsg)), null);
        }
    });
    final Mail mockMail = mock(MockMail.class, CALLS_REAL_METHODS);
    when(mockMail.getRecipients()).thenReturn(null);
    when(mockMail.getSender()).thenReturn(new MailAddress("me@cerner.com"));
    mockMail.setMessage(mimeMsg);
    NHINDSecurityAndTrustMailet mailet = new NHINDSecurityAndTrustMailet();
    mailet.agent = mockAgent;
    mailet.service(mockMail);
    assertNotNull(usedRecipients);
    assertEquals(1, usedRecipients.size());
    assertEquals("externUser1@starugh-stateline.com", usedRecipients.iterator().next().toString());
}
Also used : Mail(org.apache.mailet.Mail) MailAddress(org.apache.mailet.MailAddress) Message(org.nhindirect.stagent.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) MimeMessage(javax.mail.internet.MimeMessage) InvocationOnMock(org.mockito.invocation.InvocationOnMock) NHINDAddressCollection(org.nhindirect.stagent.NHINDAddressCollection) DefaultMessageEnvelope(org.nhindirect.stagent.DefaultMessageEnvelope) SmtpAgent(org.nhindirect.gateway.smtp.SmtpAgent) MessageProcessResult(org.nhindirect.gateway.smtp.MessageProcessResult)

Example 17 with NHINDAddressCollection

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

the class TrustModel method enforce.

/**
     * Enforces the trust policy an incoming message.  Each domain recipient's trust status is set according the models trust policy. 
     */
public void enforce(IncomingMessage message) {
    if (message == null)
        throw new IllegalArgumentException();
    if (!message.hasSignatures())
        throw new AgentException(AgentError.UntrustedMessage);
    findSenderSignatures(message);
    if (!message.hasSenderSignatures())
        throw new AgentException(AgentError.MissingSenderSignature);
    // 
    // For each domain recipient, find at least one valid sender signature that the recipient trusts
    // the default value of the trust status is false, so only change the status if a trusted
    // certificate is found
    //        
    NHINDAddressCollection recipients = message.getDomainRecipients();
    for (NHINDAddress recipient : recipients) {
        recipient.setStatus(TrustEnforcementStatus.Failed);
        // be a bogus recipient
        if (recipient.getCertificates() != null) {
            // Find a trusted signature
            DefaultMessageSignatureImpl trustedSignature = findTrustedSignature(message, recipient, recipient.getTrustAnchors());
            // verify the signature
            if (trustedSignature != null) {
                recipient.setStatus(trustedSignature.isThumbprintVerified() ? TrustEnforcementStatus.Success : TrustEnforcementStatus.Success_ThumbprintMismatch);
            } else {
                LOGGER.warn("enforce(IncomingMessage message) - could not find a trusted certificate for recipient " + recipient.getAddress());
            }
        } else {
            LOGGER.warn("enforce(IncomingMessage message) - recipient " + recipient.getAddress() + " does not have a bound certificate");
        }
    }
}
Also used : NHINDAddress(org.nhindirect.stagent.NHINDAddress) DefaultMessageSignatureImpl(org.nhindirect.stagent.DefaultMessageSignatureImpl) AgentException(org.nhindirect.stagent.AgentException) NHINDAddressCollection(org.nhindirect.stagent.NHINDAddressCollection)

Example 18 with NHINDAddressCollection

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

the class TrustModel method enforce.

/**
     * {@inheritDoc}}
     */
public void enforce(OutgoingMessage message) {
    if (message == null) {
        throw new IllegalArgumentException();
    }
    NHINDAddress sender = message.getSender();
    NHINDAddressCollection recipients = message.getRecipients();
    for (NHINDAddress recipient : recipients) {
        recipient.setStatus(TrustEnforcementStatus.Failed);
        Collection<X509Certificate> certs = recipient.getCertificates();
        if (certs == null || certs.size() == 0)
            LOGGER.warn("enforce(OutgoingMessage message) - recipient " + recipient.getAddress() + " has no bound certificates");
        recipient.setCertificates(findTrustedCerts(certs, sender.getTrustAnchors()));
        if (recipient.hasCertificates())
            recipient.setStatus(TrustEnforcementStatus.Success);
        else
            LOGGER.warn("enforce(OutgoingMessage message) - could not trust any certificates for recipient " + recipient.getAddress());
    }
}
Also used : NHINDAddress(org.nhindirect.stagent.NHINDAddress) NHINDAddressCollection(org.nhindirect.stagent.NHINDAddressCollection) X509Certificate(java.security.cert.X509Certificate)

Aggregations

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