Search in sources :

Example 36 with InternetAddress

use of javax.mail.internet.InternetAddress in project nhin-d by DirectProject.

the class DefaultNHINDAgent_bindAddressesIncomingMessageTest method testBindAddresses_singlePrivateCerts_plicyFiltered_assertNoBoundPrivateCerts.

public void testBindAddresses_singlePrivateCerts_plicyFiltered_assertNoBoundPrivateCerts() throws Exception {
    final X509Certificate cert = mock(X509Certificate.class);
    final CertificateResolver publicCertResolver = mock(CertificateResolver.class);
    when(publicCertResolver.getCertificates((InternetAddress) any())).thenReturn(new ArrayList<X509Certificate>());
    final CertificateResolver privateCertResolver = mock(CertificateResolver.class);
    when(privateCertResolver.getCertificates((InternetAddress) any())).thenReturn(Arrays.asList(cert));
    final DefaultNHINDAgent agent = new DefaultNHINDAgent("starugh-stateline.com", privateCertResolver, publicCertResolver, mock(TrustAnchorResolver.class)) {

        @Override
        protected Collection<X509Certificate> filterCertificatesByPolicy(InternetAddress sender, PolicyResolver resolver, Collection<X509Certificate> certsToFilter, boolean incoming) {
            return Collections.emptyList();
        }
    };
    final IncomingMessage message = buildIncomingMessage("MultipartMimeMessage.txt");
    message.setAgent(agent);
    agent.bindAddresses(message);
    for (NHINDAddress recipient : message.getRecipients()) assertEquals(0, recipient.getCertificates().size());
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) TrustAnchorResolver(org.nhindirect.stagent.trust.TrustAnchorResolver) PolicyResolver(org.nhindirect.stagent.policy.PolicyResolver) Collection(java.util.Collection) CertificateResolver(org.nhindirect.stagent.cert.CertificateResolver) X509Certificate(java.security.cert.X509Certificate)

Example 37 with InternetAddress

use of javax.mail.internet.InternetAddress in project nhin-d by DirectProject.

the class DefaultNHINDAgent_filterCertificateByPolicyTest method testFilterCertificateByPolicy_badPolicyExpression_assertNoCertsFiltered.

public void testFilterCertificateByPolicy_badPolicyExpression_assertNoCertsFiltered() throws Exception {
    final PolicyFilter filter = mock(PolicyFilter.class);
    doThrow(new PolicyProcessException("Just Passing Through")).when(filter).isCompliant((X509Certificate) any(), (PolicyExpression) any());
    final PolicyExpression expression = mock(PolicyExpression.class);
    final X509Certificate cert = mock(X509Certificate.class);
    final Collection<X509Certificate> certs = Arrays.asList(cert);
    final PolicyResolver resolver = mock(PolicyResolver.class);
    when(resolver.getIncomingPolicy((InternetAddress) any())).thenReturn(Arrays.asList(expression));
    final DefaultNHINDAgent agent = new DefaultNHINDAgent("", mock(CertificateResolver.class), mock(CertificateResolver.class), mock(TrustAnchorResolver.class));
    agent.setPolicyFilter(filter);
    boolean exceptionOccured = false;
    try {
        agent.filterCertificatesByPolicy(new InternetAddress("me@you.com"), resolver, certs, true);
    } catch (AgentException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) TrustAnchorResolver(org.nhindirect.stagent.trust.TrustAnchorResolver) PolicyFilter(org.nhindirect.policy.PolicyFilter) PolicyResolver(org.nhindirect.stagent.policy.PolicyResolver) PolicyExpression(org.nhindirect.policy.PolicyExpression) CertificateResolver(org.nhindirect.stagent.cert.CertificateResolver) PolicyProcessException(org.nhindirect.policy.PolicyProcessException) X509Certificate(java.security.cert.X509Certificate)

Example 38 with InternetAddress

use of javax.mail.internet.InternetAddress in project nhin-d by DirectProject.

the class DefaultNHINDAgent_filterCertificateByPolicyTest method testFilterCertificateByPolicy_nullResolver_assertNoCertsFiltered.

public void testFilterCertificateByPolicy_nullResolver_assertNoCertsFiltered() throws Exception {
    final X509Certificate cert = mock(X509Certificate.class);
    final Collection<X509Certificate> certs = Arrays.asList(cert);
    final DefaultNHINDAgent agent = new DefaultNHINDAgent("", mock(CertificateResolver.class), mock(CertificateResolver.class), mock(TrustAnchorResolver.class));
    Collection<X509Certificate> filteredCerts = agent.filterCertificatesByPolicy(new InternetAddress("me@you.com"), null, certs, true);
    assertEquals(1, filteredCerts.size());
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) TrustAnchorResolver(org.nhindirect.stagent.trust.TrustAnchorResolver) CertificateResolver(org.nhindirect.stagent.cert.CertificateResolver) X509Certificate(java.security.cert.X509Certificate)

Example 39 with InternetAddress

use of javax.mail.internet.InternetAddress in project nhin-d by DirectProject.

the class LdapCertificateStoreTest method testPublicLdapSearch_requestUserLevelCert_fallbackToOrgLevelCert_assertCertExists.

public void testPublicLdapSearch_requestUserLevelCert_fallbackToOrgLevelCert_assertCertExists() throws Exception {
    addStockPublicLDAPCertificats();
    PublicLdapCertificateStoreProvider provider = new PublicLdapCertificateStoreProvider(null, null);
    CertificateResolver resolver = provider.get();
    Collection<X509Certificate> certs = resolver.getCertificates(new InternetAddress("bogus_user@testdomain.com"));
    assertEquals(1, certs.size());
    X509Certificate cert = certs.iterator().next();
    assertTrue(cert.getSubjectX500Principal().toString().contains("direct.fnhubapp01.qa.medplus.com"));
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) CertificateResolver(org.nhindirect.stagent.cert.CertificateResolver) PublicLdapCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.PublicLdapCertificateStoreProvider) X509Certificate(java.security.cert.X509Certificate)

Example 40 with InternetAddress

use of javax.mail.internet.InternetAddress in project nhin-d by DirectProject.

the class CertificateStore_getUsableCertsTest method testGetUsableCerts_inValidUserCert_noCertsRetrieved.

public void testGetUsableCerts_inValidUserCert_noCertsRetrieved() throws Exception {
    final X509CertificateEx userCert = TestUtils.getInternalCert("user1");
    final X509CertificateEx domainCert = TestUtils.getInternalCert("gm2552");
    CertificateStore store = new CertificateStoreAdapter() {

        protected Collection<X509Certificate> filterUsable(Collection<X509Certificate> certs) {
            if (certs.iterator().next().getSubjectDN().getName().contains("user1"))
                return null;
            else
                return certs;
        }

        public Collection<X509Certificate> getCertificates(String subjectName) {
            if (subjectName.contains("user1@domain.com"))
                return Arrays.asList((X509Certificate) userCert);
            else
                return Arrays.asList((X509Certificate) domainCert);
        }
    };
    boolean exceptionOccured = false;
    try {
        store.getCertificates(new InternetAddress("user1@domain.com"));
    } catch (NHINDException e) {
        assertEquals(e.getError(), AgentError.AllCertsInResolverInvalid);
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) Collection(java.util.Collection) NHINDException(org.nhindirect.stagent.NHINDException) X509Certificate(java.security.cert.X509Certificate)

Aggregations

InternetAddress (javax.mail.internet.InternetAddress)255 MimeMessage (javax.mail.internet.MimeMessage)106 MessagingException (javax.mail.MessagingException)69 Session (javax.mail.Session)49 Properties (java.util.Properties)45 ArrayList (java.util.ArrayList)42 Address (javax.mail.Address)41 Message (javax.mail.Message)40 Date (java.util.Date)38 JavaMailInternetAddress (com.zimbra.common.mime.shim.JavaMailInternetAddress)36 AddressException (javax.mail.internet.AddressException)34 X509Certificate (java.security.cert.X509Certificate)32 MimeBodyPart (javax.mail.internet.MimeBodyPart)30 Test (org.junit.Test)29 IOException (java.io.IOException)26 MimeMultipart (javax.mail.internet.MimeMultipart)26 PolicyExpression (org.nhindirect.policy.PolicyExpression)18 HashMap (java.util.HashMap)17 CertificateResolver (org.nhindirect.stagent.cert.CertificateResolver)17 PolicyResolver (org.nhindirect.stagent.policy.PolicyResolver)17