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