Search in sources :

Example 1 with SubjectKeyIdentifierExtensionField

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

the class SimpleTextV1LexiconPolicyParser_buildExpressionTest method testBuildExpression_requiredCertField_validateTokens.

public void testBuildExpression_requiredCertField_validateTokens() throws Exception {
    final SimpleTextV1LexiconPolicyParser parser = new SimpleTextV1LexiconPolicyParser();
    final InputStream stream = IOUtils.toInputStream("X509.TBS.EXTENSION.SubjectKeyIdentifier+ = 1.3.2.3");
    Vector<SimpleTextV1LexiconPolicyParser.TokenTypeAssociation> tokens = parser.parseToTokens(stream);
    // now build expressions
    PolicyExpression expression = parser.buildExpression(tokens.iterator());
    // check that the expression is an equals
    assertNotNull(expression);
    assertEquals(PolicyExpressionType.OPERATION, expression.getExpressionType());
    OperationPolicyExpression operationExpression = (OperationPolicyExpression) expression;
    assertEquals(PolicyOperator.EQUALS, operationExpression.getPolicyOperator());
    // break down the sub operation parameters... should be a literal and an operation
    expression = operationExpression.getOperands().get(0);
    assertEquals(PolicyExpressionType.REFERENCE, expression.getExpressionType());
    assertTrue(expression instanceof SubjectKeyIdentifierExtensionField);
    assertTrue(((SubjectKeyIdentifierExtensionField) expression).isRequired());
    expression = operationExpression.getOperands().get(1);
    assertEquals(PolicyExpressionType.LITERAL, expression.getExpressionType());
    stream.close();
}
Also used : InputStream(java.io.InputStream) LiteralPolicyExpression(org.nhindirect.policy.LiteralPolicyExpression) PolicyExpression(org.nhindirect.policy.PolicyExpression) OperationPolicyExpression(org.nhindirect.policy.OperationPolicyExpression) SubjectKeyIdentifierExtensionField(org.nhindirect.policy.x509.SubjectKeyIdentifierExtensionField) OperationPolicyExpression(org.nhindirect.policy.OperationPolicyExpression)

Example 2 with SubjectKeyIdentifierExtensionField

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

the class SubjectKeyIdentifierExtensionField_injectReferenceValueTest method testInjectRefereneValue_keyIdDoesNotExist_notRequired_assertValue0.

public void testInjectRefereneValue_keyIdDoesNotExist_notRequired_assertValue0() throws Exception {
    final X509Certificate cert = TestUtils.loadCertificate("cernerDemosCaCert.der");
    final SubjectKeyIdentifierExtensionField field = new SubjectKeyIdentifierExtensionField(false);
    field.injectReferenceValue(cert);
    assertEquals("", field.getPolicyValue().getPolicyValue());
}
Also used : SubjectKeyIdentifierExtensionField(org.nhindirect.policy.x509.SubjectKeyIdentifierExtensionField) X509Certificate(java.security.cert.X509Certificate)

Example 3 with SubjectKeyIdentifierExtensionField

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

the class SubjectKeyIdentifierExtensionField_injectReferenceValueTest method testInjectRefereneValue_keyIdDoesNotExist_required_assertException.

public void testInjectRefereneValue_keyIdDoesNotExist_required_assertException() throws Exception {
    final X509Certificate cert = TestUtils.loadCertificate("cernerDemosCaCert.der");
    final SubjectKeyIdentifierExtensionField field = new SubjectKeyIdentifierExtensionField(true);
    boolean exceptionOccured = false;
    try {
        field.injectReferenceValue(cert);
    } catch (PolicyRequiredException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : PolicyRequiredException(org.nhindirect.policy.PolicyRequiredException) SubjectKeyIdentifierExtensionField(org.nhindirect.policy.x509.SubjectKeyIdentifierExtensionField) X509Certificate(java.security.cert.X509Certificate)

Example 4 with SubjectKeyIdentifierExtensionField

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

the class SubjectKeyIdentifierExtensionField_injectReferenceValueTest method testInjectRefereneValue_noInjection_getPolicyValue_assertException.

public void testInjectRefereneValue_noInjection_getPolicyValue_assertException() throws Exception {
    final SubjectKeyIdentifierExtensionField field = new SubjectKeyIdentifierExtensionField(true);
    boolean exceptionOccured = false;
    try {
        field.getPolicyValue();
    } catch (IllegalStateException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : SubjectKeyIdentifierExtensionField(org.nhindirect.policy.x509.SubjectKeyIdentifierExtensionField)

Example 5 with SubjectKeyIdentifierExtensionField

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

the class SubjectKeyIdentifierExtensionField_injectReferenceValueTest method testInjectRefereneValue_keyIdUsageExists_assertValue.

public void testInjectRefereneValue_keyIdUsageExists_assertValue() throws Exception {
    final X509Certificate cert = TestUtils.loadCertificate("AlAnderson@hospitalA.direct.visionshareinc.com.der");
    final SubjectKeyIdentifierExtensionField field = new SubjectKeyIdentifierExtensionField(false);
    field.injectReferenceValue(cert);
    assertEquals("e0f63ccfeb5ce3eef5c04efe8084c92bc628682c", field.getPolicyValue().getPolicyValue());
}
Also used : SubjectKeyIdentifierExtensionField(org.nhindirect.policy.x509.SubjectKeyIdentifierExtensionField) X509Certificate(java.security.cert.X509Certificate)

Aggregations

SubjectKeyIdentifierExtensionField (org.nhindirect.policy.x509.SubjectKeyIdentifierExtensionField)5 X509Certificate (java.security.cert.X509Certificate)3 InputStream (java.io.InputStream)1 LiteralPolicyExpression (org.nhindirect.policy.LiteralPolicyExpression)1 OperationPolicyExpression (org.nhindirect.policy.OperationPolicyExpression)1 PolicyExpression (org.nhindirect.policy.PolicyExpression)1 PolicyRequiredException (org.nhindirect.policy.PolicyRequiredException)1