use of org.nhindirect.policy.x509.SubjectAttributeField in project nhin-d by DirectProject.
the class SimpleTextV1LexiconPolicyParser method buildTBSField.
/**
* Builds a certificate reference expression that is an {@link TBSField}.
* @param token The token used to build the field.
* @return An {@link TBSField} object that represents the token. Returns null if the token does not represent an {@link TBSField}.
* @throws PolicyParseException
*/
protected PolicyExpression buildTBSField(String token) throws PolicyParseException {
TBSField<?> retVal = null;
final TBSFieldName fieldName = TBSFieldName.fromToken(token);
if (fieldName != null) {
try {
final Class<? extends TBSField<?>> fieldRefClass = fieldName.getReferenceClass(token);
if (fieldRefClass == null)
throw new PolicyParseException("TBSField with token name " + token + " has not been implemented yet.");
if (fieldRefClass.equals(IssuerAttributeField.class) || fieldRefClass.equals(SubjectAttributeField.class)) {
boolean required = token.endsWith("+");
final String rdnLookupToken = (required) ? token.substring(0, token.length() - 1) : token;
final RDNAttributeIdentifier identifier = RDNAttributeIdentifier.fromName(rdnLookupToken);
retVal = fieldRefClass.equals(IssuerAttributeField.class) ? new IssuerAttributeField(required, identifier) : new SubjectAttributeField(required, identifier);
} else {
retVal = fieldRefClass.newInstance();
}
} catch (PolicyParseException ex) {
throw ex;
}///CLOVER:OFF
catch (Exception e) {
throw new PolicyParseException("Error building TBSField", e);
}
///CLOVER:ON
}
return retVal;
}
use of org.nhindirect.policy.x509.SubjectAttributeField in project nhin-d by DirectProject.
the class SubjectAttributeField_injectReferenceValueTest method testInjectRefereneValue_distinguishedName_assertValue.
public void testInjectRefereneValue_distinguishedName_assertValue() throws Exception {
final X509Certificate cert = TestUtils.loadCertificate("altNameOnly.der");
final SubjectAttributeField field = new SubjectAttributeField(true, RDNAttributeIdentifier.DISTINGUISHED_NAME);
field.injectReferenceValue(cert);
final Collection<String> values = field.getPolicyValue().getPolicyValue();
assertEquals(1, values.size());
Iterator<String> str = values.iterator();
assertEquals("O=Cerner,L=Kansas City,ST=MO,C=US,CN=altNameOnly", str.next());
}
use of org.nhindirect.policy.x509.SubjectAttributeField in project nhin-d by DirectProject.
the class SubjectAttributeField_injectReferenceValueTest method testInjectRefereneValue_rdnAttributeDoesNotExist_notRequired_assertValueCollection.
public void testInjectRefereneValue_rdnAttributeDoesNotExist_notRequired_assertValueCollection() throws Exception {
final X509Certificate cert = TestUtils.loadCertificate("altNameOnly.der");
final SubjectAttributeField field = new SubjectAttributeField(false, RDNAttributeIdentifier.INITIALS);
field.injectReferenceValue(cert);
final Collection<String> values = field.getPolicyValue().getPolicyValue();
assertEquals(0, values.size());
}
use of org.nhindirect.policy.x509.SubjectAttributeField 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());
}
use of org.nhindirect.policy.x509.SubjectAttributeField in project nhin-d by DirectProject.
the class SubjectAttributeField_injectReferenceValueTest method testInjectRefereneValue_noInjection_getPolicyValue_assertException.
public void testInjectRefereneValue_noInjection_getPolicyValue_assertException() throws Exception {
final SubjectAttributeField field = new SubjectAttributeField(true, RDNAttributeIdentifier.COMMON_NAME);
boolean exceptionOccured = false;
try {
field.getPolicyValue();
} catch (IllegalStateException e) {
exceptionOccured = true;
}
assertTrue(exceptionOccured);
}
Aggregations