Search in sources :

Example 31 with PolicyExpression

use of org.nhindirect.policy.PolicyExpression 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 32 with PolicyExpression

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

the class SimpleTextV1LexiconPolicyParser_buildExpressionTest method testBuildExpression_extensionName_keyUsage_validatePolicyExpression.

public void testBuildExpression_extensionName_keyUsage_validatePolicyExpression() throws Exception {
    final SimpleTextV1LexiconPolicyParser parser = new SimpleTextV1LexiconPolicyParser();
    final InputStream stream = FileUtils.openInputStream(new File("./src/test/resources/policies/lexiconWithKeyUsage.txt"));
    final 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 cert reference and a literal
    expression = operationExpression.getOperands().get(0);
    assertEquals(PolicyExpressionType.REFERENCE, expression.getExpressionType());
    assertTrue(expression instanceof KeyUsageExtensionField);
    expression = operationExpression.getOperands().get(1);
    assertEquals(PolicyExpressionType.LITERAL, expression.getExpressionType());
    assertEquals("1", ((LiteralPolicyExpression<?>) expression).getPolicyValue().getPolicyValue());
}
Also used : LiteralPolicyExpression(org.nhindirect.policy.LiteralPolicyExpression) InputStream(java.io.InputStream) LiteralPolicyExpression(org.nhindirect.policy.LiteralPolicyExpression) PolicyExpression(org.nhindirect.policy.PolicyExpression) OperationPolicyExpression(org.nhindirect.policy.OperationPolicyExpression) KeyUsageExtensionField(org.nhindirect.policy.x509.KeyUsageExtensionField) File(java.io.File) OperationPolicyExpression(org.nhindirect.policy.OperationPolicyExpression)

Example 33 with PolicyExpression

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

the class SimpleTextV1LexiconPolicyParser_buildExpressionTest method testBuildExpression_tinaryExpression_operatorExpressionOperands_validatePolicyExpression.

public void testBuildExpression_tinaryExpression_operatorExpressionOperands_validatePolicyExpression() throws Exception {
    final SimpleTextV1LexiconPolicyParser parser = new SimpleTextV1LexiconPolicyParser();
    InputStream stream = IOUtils.toInputStream("false = !true && !false");
    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.LOGICAL_AND, operationExpression.getPolicyOperator());
    // break down the sub operation parameters... should be two operations
    OperationPolicyExpression subOperation = (OperationPolicyExpression) operationExpression.getOperands().get(0);
    assertEquals(PolicyExpressionType.OPERATION, subOperation.getExpressionType());
    assertEquals(PolicyOperator.EQUALS, subOperation.getPolicyOperator());
    expression = subOperation.getOperands().get(0);
    assertEquals(PolicyExpressionType.LITERAL, expression.getExpressionType());
    assertEquals("false", ((LiteralPolicyExpression<?>) expression).getPolicyValue().getPolicyValue());
    OperationPolicyExpression subSubOperation = (OperationPolicyExpression) subOperation.getOperands().get(1);
    assertEquals(PolicyExpressionType.OPERATION, subSubOperation.getExpressionType());
    assertEquals(PolicyOperator.LOGICAL_NOT, subSubOperation.getPolicyOperator());
    subOperation = (OperationPolicyExpression) operationExpression.getOperands().get(1);
    assertEquals(PolicyExpressionType.OPERATION, subOperation.getExpressionType());
    assertEquals(PolicyOperator.LOGICAL_NOT, subOperation.getPolicyOperator());
    expression = subOperation.getOperands().get(0);
    assertEquals(PolicyExpressionType.LITERAL, expression.getExpressionType());
    assertEquals("false", ((LiteralPolicyExpression<?>) expression).getPolicyValue().getPolicyValue());
}
Also used : LiteralPolicyExpression(org.nhindirect.policy.LiteralPolicyExpression) InputStream(java.io.InputStream) LiteralPolicyExpression(org.nhindirect.policy.LiteralPolicyExpression) PolicyExpression(org.nhindirect.policy.PolicyExpression) OperationPolicyExpression(org.nhindirect.policy.OperationPolicyExpression) OperationPolicyExpression(org.nhindirect.policy.OperationPolicyExpression)

Example 34 with PolicyExpression

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

the class SimpleTextV1LexiconPolicyParser_buildExpressionTest method testBuildExpression_tbsFieldName_rdnAttribute_validatePolicyExpression.

public void testBuildExpression_tbsFieldName_rdnAttribute_validatePolicyExpression() throws Exception {
    final SimpleTextV1LexiconPolicyParser parser = new SimpleTextV1LexiconPolicyParser();
    final InputStream stream = FileUtils.openInputStream(new File("./src/test/resources/policies/literalWithSpaces.txt"));
    final 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 cert reference and a literal
    expression = operationExpression.getOperands().get(0);
    assertEquals(PolicyExpressionType.REFERENCE, expression.getExpressionType());
    assertTrue(expression instanceof SubjectAttributeField);
    expression = operationExpression.getOperands().get(1);
    assertEquals(PolicyExpressionType.LITERAL, expression.getExpressionType());
    assertEquals("United States", ((LiteralPolicyExpression<?>) expression).getPolicyValue().getPolicyValue());
}
Also used : LiteralPolicyExpression(org.nhindirect.policy.LiteralPolicyExpression) InputStream(java.io.InputStream) SubjectAttributeField(org.nhindirect.policy.x509.SubjectAttributeField) LiteralPolicyExpression(org.nhindirect.policy.LiteralPolicyExpression) PolicyExpression(org.nhindirect.policy.PolicyExpression) OperationPolicyExpression(org.nhindirect.policy.OperationPolicyExpression) File(java.io.File) OperationPolicyExpression(org.nhindirect.policy.OperationPolicyExpression)

Example 35 with PolicyExpression

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

the class SimpleTextV1LexiconPolicyParser_buildExpressionTest method testBuildExpression_simpleExpression_validatePolicyExpression.

public void testBuildExpression_simpleExpression_validatePolicyExpression() throws Exception {
    final SimpleTextV1LexiconPolicyParser parser = new SimpleTextV1LexiconPolicyParser();
    final InputStream stream = FileUtils.openInputStream(new File("./src/test/resources/policies/simpleLexiconSamp1.txt"));
    final Vector<SimpleTextV1LexiconPolicyParser.TokenTypeAssociation> tokens = parser.parseToTokens(stream);
    // now build expressions
    PolicyExpression expression = parser.buildExpression(tokens.iterator());
    // check that the expression is a logical and
    assertNotNull(expression);
    assertEquals(PolicyExpressionType.OPERATION, expression.getExpressionType());
    OperationPolicyExpression operationExpression = (OperationPolicyExpression) expression;
    assertEquals(PolicyOperator.LOGICAL_AND, operationExpression.getPolicyOperator());
    // now break down the operands which should each be a operator expressions
    // operator 1
    // should be an equals operator expressions
    expression = operationExpression.getOperands().get(0);
    assertEquals(PolicyExpressionType.OPERATION, expression.getExpressionType());
    OperationPolicyExpression param1operationExpression = (OperationPolicyExpression) expression;
    assertEquals(PolicyOperator.EQUALS, param1operationExpression.getPolicyOperator());
    // break down the sub operation parameters... should be two literals
    expression = param1operationExpression.getOperands().get(0);
    assertEquals(PolicyExpressionType.LITERAL, expression.getExpressionType());
    assertEquals("1", ((LiteralPolicyExpression<?>) expression).getPolicyValue().getPolicyValue());
    expression = param1operationExpression.getOperands().get(1);
    assertEquals(PolicyExpressionType.LITERAL, expression.getExpressionType());
    assertEquals("2", ((LiteralPolicyExpression<?>) expression).getPolicyValue().getPolicyValue());
    // operator 2
    // should be an equals operator expressions
    expression = operationExpression.getOperands().get(1);
    assertEquals(PolicyExpressionType.OPERATION, expression.getExpressionType());
    OperationPolicyExpression param2operationExpression = (OperationPolicyExpression) expression;
    assertEquals(PolicyOperator.NOT_EQUALS, param2operationExpression.getPolicyOperator());
    // break down the sub operation parameters... should be two literals
    expression = param2operationExpression.getOperands().get(0);
    assertEquals(PolicyExpressionType.LITERAL, expression.getExpressionType());
    assertEquals("2", ((LiteralPolicyExpression<?>) expression).getPolicyValue().getPolicyValue());
    expression = param2operationExpression.getOperands().get(1);
    assertEquals(PolicyExpressionType.LITERAL, expression.getExpressionType());
    assertEquals("1", ((LiteralPolicyExpression<?>) expression).getPolicyValue().getPolicyValue());
}
Also used : LiteralPolicyExpression(org.nhindirect.policy.LiteralPolicyExpression) InputStream(java.io.InputStream) LiteralPolicyExpression(org.nhindirect.policy.LiteralPolicyExpression) PolicyExpression(org.nhindirect.policy.PolicyExpression) OperationPolicyExpression(org.nhindirect.policy.OperationPolicyExpression) File(java.io.File) OperationPolicyExpression(org.nhindirect.policy.OperationPolicyExpression)

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