Search in sources :

Example 1 with PolicyFilter

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

the class DefaultNHINDAgent_filterCertificateByPolicyTest method testFilterCertificateByPolicy_outgoingPolicyCompliant_assertNoCertsFiltered.

public void testFilterCertificateByPolicy_outgoingPolicyCompliant_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.getOutgoingPolicy((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, false);
    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 2 with PolicyFilter

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

the class DefaultNHINDAgent_filterCertificateByPolicyTest method testFilterCertificateByPolicy_notCompliant_assertNoCertsFiltered.

public void testFilterCertificateByPolicy_notCompliant_assertNoCertsFiltered() throws Exception {
    final PolicyFilter filter = mock(PolicyFilter.class);
    when(filter.isCompliant((X509Certificate) any(), (PolicyExpression) any())).thenReturn(false);
    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 : 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 3 with PolicyFilter

use of org.nhindirect.policy.PolicyFilter 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 4 with PolicyFilter

use of org.nhindirect.policy.PolicyFilter 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 5 with PolicyFilter

use of org.nhindirect.policy.PolicyFilter 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)

Aggregations

X509Certificate (java.security.cert.X509Certificate)11 PolicyFilter (org.nhindirect.policy.PolicyFilter)11 PolicyExpression (org.nhindirect.policy.PolicyExpression)10 InternetAddress (javax.mail.internet.InternetAddress)9 PolicyResolver (org.nhindirect.stagent.policy.PolicyResolver)9 CertificateResolver (org.nhindirect.stagent.cert.CertificateResolver)5 TrustAnchorResolver (org.nhindirect.stagent.trust.TrustAnchorResolver)5 PolicyRequiredException (org.nhindirect.policy.PolicyRequiredException)3 PolicyProcessException (org.nhindirect.policy.PolicyProcessException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1 PrintStream (java.io.PrintStream)1 URL (java.net.URL)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 PolicyGrammarException (org.nhindirect.policy.PolicyGrammarException)1 PolicyLexiconParser (org.nhindirect.policy.PolicyLexiconParser)1 StackMachineCompiler (org.nhindirect.policy.impl.machine.StackMachineCompiler)1 AgentException (org.nhindirect.stagent.AgentException)1