Search in sources :

Example 41 with InternetAddress

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

the class LdapCertificateStoreTest method testPublicLdapSearch_userLevelCert_assertCertExists.

public void testPublicLdapSearch_userLevelCert_assertCertExists() throws Exception {
    addStockPublicLDAPCertificats();
    PublicLdapCertificateStoreProvider provider = new PublicLdapCertificateStoreProvider(null, null);
    CertificateResolver resolver = provider.get();
    Collection<X509Certificate> certs = resolver.getCertificates(new InternetAddress("user@testdomain.com"));
    assertEquals(1, certs.size());
    X509Certificate cert = certs.iterator().next();
    assertTrue(cert.getSubjectX500Principal().toString().contains("moe@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 42 with InternetAddress

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

the class TrustModel_isCertPolicyCompliantTest method testIsCertPolicyCompliant_policyExpressionError_assertExecption.

public void testIsCertPolicyCompliant_policyExpressionError_assertExecption() throws Exception {
    final TrustModel model = new TrustModel();
    final PolicyFilter filter = mock(PolicyFilter.class);
    doThrow(new PolicyProcessException("Just Passing Through")).when(filter).isCompliant((X509Certificate) any(), (PolicyExpression) any());
    final PolicyResolver resolver = mock(PolicyResolver.class);
    final PolicyExpression expression = mock(PolicyExpression.class);
    when(resolver.getIncomingPolicy((InternetAddress) any())).thenReturn(Arrays.asList(expression));
    model.setTrustPolicyResolver(resolver);
    model.setPolicyFilter(filter);
    final X509Certificate cert = mock(X509Certificate.class);
    boolean exceptionOccured = false;
    try {
        model.isCertPolicyCompliant(new InternetAddress("me@test.com"), cert);
    } catch (AgentException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) PolicyFilter(org.nhindirect.policy.PolicyFilter) AgentException(org.nhindirect.stagent.AgentException) PolicyResolver(org.nhindirect.stagent.policy.PolicyResolver) PolicyExpression(org.nhindirect.policy.PolicyExpression) PolicyProcessException(org.nhindirect.policy.PolicyProcessException) X509Certificate(java.security.cert.X509Certificate)

Example 43 with InternetAddress

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

the class TrustModel_isCertPolicyCompliantTest method testIsCertPolicyCompliant_missingRequiredField_assertFalse.

public void testIsCertPolicyCompliant_missingRequiredField_assertFalse() throws Exception {
    final TrustModel model = new TrustModel();
    final PolicyFilter filter = mock(PolicyFilter.class);
    doThrow(new PolicyRequiredException("Just Passing Through")).when(filter).isCompliant((X509Certificate) any(), (PolicyExpression) any());
    final PolicyResolver resolver = mock(PolicyResolver.class);
    final PolicyExpression expression = mock(PolicyExpression.class);
    when(resolver.getIncomingPolicy((InternetAddress) any())).thenReturn(Arrays.asList(expression));
    model.setTrustPolicyResolver(resolver);
    model.setPolicyFilter(filter);
    final X509Certificate cert = mock(X509Certificate.class);
    assertFalse(model.isCertPolicyCompliant(new InternetAddress("me@test.com"), cert));
}
Also used : PolicyRequiredException(org.nhindirect.policy.PolicyRequiredException) InternetAddress(javax.mail.internet.InternetAddress) PolicyFilter(org.nhindirect.policy.PolicyFilter) PolicyResolver(org.nhindirect.stagent.policy.PolicyResolver) PolicyExpression(org.nhindirect.policy.PolicyExpression) X509Certificate(java.security.cert.X509Certificate)

Example 44 with InternetAddress

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

the class TrustModel_isCertPolicyCompliantTest method testIsCertPolicyCompliant_noPolicyFilter_assertTrue.

public void testIsCertPolicyCompliant_noPolicyFilter_assertTrue() throws Exception {
    final TrustModel model = new TrustModel();
    model.setTrustPolicyResolver(mock(PolicyResolver.class));
    model.setPolicyFilter(null);
    final X509Certificate cert = mock(X509Certificate.class);
    assertTrue(model.isCertPolicyCompliant(new InternetAddress("me@test.com"), cert));
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) PolicyResolver(org.nhindirect.stagent.policy.PolicyResolver) X509Certificate(java.security.cert.X509Certificate)

Example 45 with InternetAddress

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

the class TrustModel_isCertPolicyCompliantTest method testIsCertPolicyCompliant_policyNotCompliant_assertFalse.

public void testIsCertPolicyCompliant_policyNotCompliant_assertFalse() throws Exception {
    final TrustModel model = new TrustModel();
    final PolicyFilter filter = mock(PolicyFilter.class);
    when(filter.isCompliant((X509Certificate) any(), (PolicyExpression) any())).thenReturn(false);
    final PolicyResolver resolver = mock(PolicyResolver.class);
    final PolicyExpression expression = mock(PolicyExpression.class);
    when(resolver.getIncomingPolicy((InternetAddress) any())).thenReturn(Arrays.asList(expression));
    model.setTrustPolicyResolver(resolver);
    model.setPolicyFilter(filter);
    final X509Certificate cert = mock(X509Certificate.class);
    assertFalse(model.isCertPolicyCompliant(new InternetAddress("me@test.com"), cert));
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) PolicyFilter(org.nhindirect.policy.PolicyFilter) PolicyResolver(org.nhindirect.stagent.policy.PolicyResolver) PolicyExpression(org.nhindirect.policy.PolicyExpression) 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