use of org.nhindirect.policy.x509.X509Field in project nhin-d by DirectProject.
the class SimpleTextV1LexiconPolicyParser_buildExpressionTest method testBuildExpression_x509FieldsType_validatePolicyExpression.
public void testBuildExpression_x509FieldsType_validatePolicyExpression() throws Exception {
final SimpleTextV1LexiconPolicyParser parser = new SimpleTextV1LexiconPolicyParser();
final InputStream stream = FileUtils.openInputStream(new File("./src/test/resources/policies/lexiconWithCertificateStruct.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 X509Field);
expression = operationExpression.getOperands().get(1);
assertEquals(PolicyExpressionType.LITERAL, expression.getExpressionType());
assertEquals("1.2.840.113549.1.1.11", ((LiteralPolicyExpression<?>) expression).getPolicyValue().getPolicyValue());
}
use of org.nhindirect.policy.x509.X509Field in project nhin-d by DirectProject.
the class SimpleTextV1LexiconPolicyParser method buildX509Field.
/**
* Builds a certificate reference expression that is an {@link X509Field}.
* @param token The token used to build the field.
* @return An {@link X509Field} object that represents the token. Returns null if the token does not represent an {@link X509Field}.
* @throws PolicyParseException
*/
protected PolicyExpression buildX509Field(String token) throws PolicyParseException {
X509Field<?> retVal = null;
final X509FieldType fieldType = X509FieldType.fromToken(token);
if (fieldType != null) {
try {
Class<? extends X509Field<?>> fieldRefClass = fieldType.getReferenceClass();
if (fieldRefClass == null)
throw new PolicyParseException("X509Field with token name " + token + " has not been implemented yet.");
retVal = fieldRefClass.newInstance();
} catch (PolicyParseException ex) {
throw ex;
}///CLOVER:OFF
catch (Exception e) {
throw new PolicyParseException("Error building X509Field", e);
}
///CLOVER:ON
}
return retVal;
}
Aggregations