Search in sources :

Example 46 with PolicyExpression

use of org.nhindirect.policy.PolicyExpression in project nhin-d by DirectProject.

the class DefaultNHINDAgent_filterCertificateByPolicyTest method testFilterCertificateByPolicy_incomingPolicyCompliant_assertNoCertsFiltered.

public void testFilterCertificateByPolicy_incomingPolicyCompliant_assertNoCertsFiltered() throws Exception {
    final PolicyFilter filter = mock(PolicyFilter.class);
    when(filter.isCompliant((X509Certificate) any(), (PolicyExpression) any())).thenReturn(true);
    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);
    Collection<X509Certificate> filteredCerts = agent.filterCertificatesByPolicy(new InternetAddress("me@you.com"), resolver, certs, true);
    assertEquals(1, filteredCerts.size());
}
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) X509Certificate(java.security.cert.X509Certificate)

Example 47 with PolicyExpression

use of org.nhindirect.policy.PolicyExpression in project nhin-d by DirectProject.

the class DefaultNHINDAgent_filterCertificateByPolicyTest method testFilterCertificateByPolicy_noIncomingExpressions_assertNoCertsFiltered.

public void testFilterCertificateByPolicy_noIncomingExpressions_assertNoCertsFiltered() throws Exception {
    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(new ArrayList<PolicyExpression>());
    final DefaultNHINDAgent agent = new DefaultNHINDAgent("", mock(CertificateResolver.class), mock(CertificateResolver.class), mock(TrustAnchorResolver.class));
    Collection<X509Certificate> filteredCerts = agent.filterCertificatesByPolicy(new InternetAddress("me@you.com"), resolver, certs, true);
    assertEquals(1, filteredCerts.size());
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) TrustAnchorResolver(org.nhindirect.stagent.trust.TrustAnchorResolver) PolicyResolver(org.nhindirect.stagent.policy.PolicyResolver) PolicyExpression(org.nhindirect.policy.PolicyExpression) CertificateResolver(org.nhindirect.stagent.cert.CertificateResolver) X509Certificate(java.security.cert.X509Certificate)

Example 48 with PolicyExpression

use of org.nhindirect.policy.PolicyExpression in project nhin-d by DirectProject.

the class DefaultNHINDAgent_filterCertificateByPolicyTest method testFilterCertificateByPolicy_requiredFieldMissing_assertNoCertsFiltered.

public void testFilterCertificateByPolicy_requiredFieldMissing_assertNoCertsFiltered() throws Exception {
    final PolicyFilter filter = mock(PolicyFilter.class);
    doThrow(new PolicyRequiredException("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);
    Collection<X509Certificate> filteredCerts = agent.filterCertificatesByPolicy(new InternetAddress("me@you.com"), resolver, certs, true);
    assertEquals(0, filteredCerts.size());
}
Also used : PolicyRequiredException(org.nhindirect.policy.PolicyRequiredException) 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) X509Certificate(java.security.cert.X509Certificate)

Example 49 with PolicyExpression

use of org.nhindirect.policy.PolicyExpression in project nhin-d by DirectProject.

the class DomainPolicyResolver_getPolicyTest method testGetPolicy_incomingPolicyExists_assertPolicies.

public void testGetPolicy_incomingPolicyExists_assertPolicies() throws Exception {
    final PolicyExpression expression = mock(PolicyExpression.class);
    final List<PolicyExpression> expressions = Arrays.asList(expression);
    final Map<String, Collection<PolicyExpression>> policies = new HashMap<String, Collection<PolicyExpression>>();
    policies.put("testdomain.com", expressions);
    final DomainPolicyResolver resolver = new DomainPolicyResolver(policies);
    Collection<PolicyExpression> retrievedExpressions = resolver.getIncomingPolicy(new InternetAddress("me@testdomain.com"));
    assertNotNull(retrievedExpressions);
    assertEquals(1, retrievedExpressions.size());
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) HashMap(java.util.HashMap) Collection(java.util.Collection) PolicyExpression(org.nhindirect.policy.PolicyExpression)

Example 50 with PolicyExpression

use of org.nhindirect.policy.PolicyExpression in project nhin-d by DirectProject.

the class DomainPolicyResolver_getPolicyTest method testGetPolicy_outgoingPolicyExists_assertPolicies.

public void testGetPolicy_outgoingPolicyExists_assertPolicies() throws Exception {
    final PolicyExpression expression = mock(PolicyExpression.class);
    final List<PolicyExpression> expressions = Arrays.asList(expression);
    final Map<String, Collection<PolicyExpression>> policies = new HashMap<String, Collection<PolicyExpression>>();
    policies.put("testdomain.com", expressions);
    final DomainPolicyResolver resolver = new DomainPolicyResolver(policies);
    Collection<PolicyExpression> retrievedExpressions = resolver.getOutgoingPolicy(new InternetAddress("me@testdomain.com"));
    assertNotNull(retrievedExpressions);
    assertEquals(1, retrievedExpressions.size());
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) HashMap(java.util.HashMap) Collection(java.util.Collection) PolicyExpression(org.nhindirect.policy.PolicyExpression)

Aggregations

PolicyExpression (org.nhindirect.policy.PolicyExpression)54 X509Certificate (java.security.cert.X509Certificate)21 InternetAddress (javax.mail.internet.InternetAddress)18 LiteralPolicyExpression (org.nhindirect.policy.LiteralPolicyExpression)16 OperationPolicyExpression (org.nhindirect.policy.OperationPolicyExpression)16 PolicyResolver (org.nhindirect.stagent.policy.PolicyResolver)12 InputStream (java.io.InputStream)11 PolicyFilter (org.nhindirect.policy.PolicyFilter)10 Vector (java.util.Vector)9 Collection (java.util.Collection)8 HashMap (java.util.HashMap)8 Opcode (org.nhindirect.policy.Opcode)7 KeyUsageExtensionField (org.nhindirect.policy.x509.KeyUsageExtensionField)7 CertificateResolver (org.nhindirect.stagent.cert.CertificateResolver)7 TrustAnchorResolver (org.nhindirect.stagent.trust.TrustAnchorResolver)7 File (java.io.File)6 StackMachineCompiler (org.nhindirect.policy.impl.machine.StackMachineCompiler)6 ExtendedKeyUsageExtensionField (org.nhindirect.policy.x509.ExtendedKeyUsageExtensionField)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5