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());
}
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");
}
}
}
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());
}
}
Aggregations