Search in sources :

Example 1 with XMLLexiconPolicyParser

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

the class XMLLexiconPolicyParser_serializeTest method testDeserialize_nullStream_assertExecption.

public void testDeserialize_nullStream_assertExecption() throws Exception {
    boolean exceptionOccured = false;
    final XMLLexiconPolicyParser parser = new XMLLexiconPolicyParser();
    try {
        parser.deserialize(null);
    } catch (IllegalArgumentException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : XMLLexiconPolicyParser(org.nhindirect.policy.impl.XMLLexiconPolicyParser)

Example 2 with XMLLexiconPolicyParser

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

the class XMLLexiconPolicyParser_serializeTest method testDeserializeo_invalidXML_assertExecption.

public void testDeserializeo_invalidXML_assertExecption() throws Exception {
    boolean exceptionOccured = false;
    final XMLLexiconPolicyParser parser = new XMLLexiconPolicyParser();
    try {
        parser.deserialize(new ByteArrayInputStream(new byte[] { 0, 1, 2 }));
    } catch (PolicyParseException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) XMLLexiconPolicyParser(org.nhindirect.policy.impl.XMLLexiconPolicyParser) PolicyParseException(org.nhindirect.policy.PolicyParseException)

Example 3 with XMLLexiconPolicyParser

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

the class XMLLexiconPolicyParser_serializeTest method testSerialize_nullExpression_assertExecption.

public void testSerialize_nullExpression_assertExecption() throws Exception {
    boolean exceptionOccured = false;
    final XMLLexiconPolicyParser parser = new XMLLexiconPolicyParser();
    try {
        parser.serialize(null, null);
    } catch (IllegalArgumentException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : XMLLexiconPolicyParser(org.nhindirect.policy.impl.XMLLexiconPolicyParser)

Example 4 with XMLLexiconPolicyParser

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

the class XMLLexiconPolicyParser_serializeTest method testSerialize_complexExpression_validateExpression.

public void testSerialize_complexExpression_validateExpression() throws Exception {
    final XMLLexiconPolicyParser parser = new XMLLexiconPolicyParser();
    // build the expression
    final Integer keyUsage = KeyUsage.keyEncipherment;
    final PolicyValue<Integer> op1 = PolicyValueFactory.getInstance(keyUsage);
    final LiteralPolicyExpression<Integer> expr1 = LiteralPolicyExpressionFactory.getInstance(op1);
    final KeyUsageExtensionField expr2 = new KeyUsageExtensionField(true);
    final Vector<PolicyExpression> operands1 = new Vector<PolicyExpression>();
    operands1.add(expr1);
    operands1.add(expr2);
    final OperationPolicyExpression oper1 = OperationPolicyExpressionFactory.getInstance(PolicyOperator.BITWISE_AND, operands1);
    // build outer expression embedding the first operation as a parameter
    final PolicyValue<Integer> op3 = PolicyValueFactory.getInstance(0);
    final LiteralPolicyExpression<Integer> expr3 = LiteralPolicyExpressionFactory.getInstance(op3);
    final Vector<PolicyExpression> operands2 = new Vector<PolicyExpression>();
    operands2.add(oper1);
    operands2.add(expr3);
    final OperationPolicyExpression oper2 = OperationPolicyExpressionFactory.getInstance(PolicyOperator.GREATER, operands2);
    // build a separate expression for extended key usage
    final ExtendedKeyUsageExtensionField expr4 = new ExtendedKeyUsageExtensionField(true);
    final PolicyValue<String> op5 = PolicyValueFactory.getInstance(ExtendedKeyUsageIdentifier.ID_KP_EMAIL_PROTECTION.getId());
    final LiteralPolicyExpression<String> expr5 = LiteralPolicyExpressionFactory.getInstance(op5);
    final Vector<PolicyExpression> operands3 = new Vector<PolicyExpression>();
    operands3.add(expr4);
    operands3.add(expr5);
    final OperationPolicyExpression oper3 = OperationPolicyExpressionFactory.getInstance(PolicyOperator.CONTAINS, operands3);
    // build an and operator and make sure the cert has all policies met
    final Vector<PolicyExpression> operands4 = new Vector<PolicyExpression>();
    operands4.add(oper2);
    operands4.add(oper3);
    final OperationPolicyExpression oper4 = OperationPolicyExpressionFactory.getInstance(PolicyOperator.LOGICAL_AND, operands4);
    // serialize
    final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    parser.serialize(oper4, outStream);
    assertTrue(outStream.size() > 0);
    String XML = new String(outStream.toByteArray());
    System.out.println(XML);
    // deserialize
    final ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray());
    final PolicyExpression deserExpression = parser.parse(inStream);
    assertNotNull(deserExpression);
    assertEquals(PolicyExpressionType.OPERATION, deserExpression.getExpressionType());
}
Also used : ExtendedKeyUsageExtensionField(org.nhindirect.policy.x509.ExtendedKeyUsageExtensionField) LiteralPolicyExpression(org.nhindirect.policy.LiteralPolicyExpression) PolicyExpression(org.nhindirect.policy.PolicyExpression) OperationPolicyExpression(org.nhindirect.policy.OperationPolicyExpression) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XMLLexiconPolicyParser(org.nhindirect.policy.impl.XMLLexiconPolicyParser) OperationPolicyExpression(org.nhindirect.policy.OperationPolicyExpression) ByteArrayInputStream(java.io.ByteArrayInputStream) KeyUsageExtensionField(org.nhindirect.policy.x509.KeyUsageExtensionField) ExtendedKeyUsageExtensionField(org.nhindirect.policy.x509.ExtendedKeyUsageExtensionField) Vector(java.util.Vector)

Example 5 with XMLLexiconPolicyParser

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

the class XMLLexiconPolicyParser_serializeTest method testSerialize_simpleExpression_validateExpression.

public void testSerialize_simpleExpression_validateExpression() throws Exception {
    final XMLLexiconPolicyParser parser = new XMLLexiconPolicyParser();
    // build the expression
    //final PolicyValue<Boolean> op1 = PolicyValueFactory.getInstance(true);
    final LiteralPolicyExpression<Integer> expr = LiteralPolicyExpressionFactory.getInstance(KeyUsageBit.DATA_ENCIPHERMENT.getUsageBit());
    final KeyUsageExtensionField extensionField = new KeyUsageExtensionField(true);
    final Vector<PolicyExpression> operands = new Vector<PolicyExpression>();
    operands.add(expr);
    operands.add(extensionField);
    final OperationPolicyExpression oper = OperationPolicyExpressionFactory.getInstance(PolicyOperator.EQUALS, operands);
    // serialize
    final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    parser.serialize(oper, outStream);
    String XML = new String(outStream.toByteArray());
    System.out.println(XML);
/*
		
		// deserialize
		final ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray());

		final PolicyExpression deserExpression = parser.parse(inStream);
		
		assertNotNull(deserExpression);
		
		assertEquals(PolicyExpressionType.OPERATION, deserExpression.getExpressionType());
		*/
}
Also used : LiteralPolicyExpression(org.nhindirect.policy.LiteralPolicyExpression) PolicyExpression(org.nhindirect.policy.PolicyExpression) OperationPolicyExpression(org.nhindirect.policy.OperationPolicyExpression) KeyUsageExtensionField(org.nhindirect.policy.x509.KeyUsageExtensionField) ExtendedKeyUsageExtensionField(org.nhindirect.policy.x509.ExtendedKeyUsageExtensionField) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XMLLexiconPolicyParser(org.nhindirect.policy.impl.XMLLexiconPolicyParser) Vector(java.util.Vector) OperationPolicyExpression(org.nhindirect.policy.OperationPolicyExpression)

Aggregations

XMLLexiconPolicyParser (org.nhindirect.policy.impl.XMLLexiconPolicyParser)6 LiteralPolicyExpression (org.nhindirect.policy.LiteralPolicyExpression)3 OperationPolicyExpression (org.nhindirect.policy.OperationPolicyExpression)3 PolicyExpression (org.nhindirect.policy.PolicyExpression)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Vector (java.util.Vector)2 ExtendedKeyUsageExtensionField (org.nhindirect.policy.x509.ExtendedKeyUsageExtensionField)2 KeyUsageExtensionField (org.nhindirect.policy.x509.KeyUsageExtensionField)2 PolicyParseException (org.nhindirect.policy.PolicyParseException)1