use of org.nhindirect.policy.x509.IssuerAttributeField 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.IssuerAttributeField in project nhin-d by DirectProject.
the class IssuerAttributeField_injectReferenceValueTest method testInjectRefereneValue_rdnAttributeDoesNotExist_notRequired_assertValueCollection.
public void testInjectRefereneValue_rdnAttributeDoesNotExist_notRequired_assertValueCollection() throws Exception {
final X509Certificate cert = TestUtils.loadCertificate("altNameOnly.der");
final IssuerAttributeField field = new IssuerAttributeField(false, RDNAttributeIdentifier.INITIALS);
field.injectReferenceValue(cert);
final Collection<String> values = field.getPolicyValue().getPolicyValue();
assertEquals(0, values.size());
}
use of org.nhindirect.policy.x509.IssuerAttributeField in project nhin-d by DirectProject.
the class IssuerAttributeField_injectReferenceValueTest method testInjectRefereneValue_rdnSingleAttributeExists_assertValue.
public void testInjectRefereneValue_rdnSingleAttributeExists_assertValue() throws Exception {
final X509Certificate cert = TestUtils.loadCertificate("altNameOnly.der");
final IssuerAttributeField field = new IssuerAttributeField(true, RDNAttributeIdentifier.COMMON_NAME);
field.injectReferenceValue(cert);
final Collection<String> values = field.getPolicyValue().getPolicyValue();
assertEquals(1, values.size());
Iterator<String> str = values.iterator();
assertEquals("test.email.com", str.next());
}
use of org.nhindirect.policy.x509.IssuerAttributeField in project nhin-d by DirectProject.
the class IssuerAttributeField_injectReferenceValueTest method testInjectRefereneValue_rdnAttributeDoesNotExist_required_throwException.
public void testInjectRefereneValue_rdnAttributeDoesNotExist_required_throwException() throws Exception {
final X509Certificate cert = TestUtils.loadCertificate("altNameOnly.der");
final IssuerAttributeField field = new IssuerAttributeField(true, RDNAttributeIdentifier.INITIALS);
boolean exceptionOccured = false;
try {
field.injectReferenceValue(cert);
} catch (PolicyRequiredException e) {
exceptionOccured = true;
}
assertTrue(exceptionOccured);
}
use of org.nhindirect.policy.x509.IssuerAttributeField in project nhin-d by DirectProject.
the class IssuerAttributeField_injectReferenceValueTest method testInjectRefereneValue_distinguishedName_assertValue.
public void testInjectRefereneValue_distinguishedName_assertValue() throws Exception {
final X509Certificate cert = TestUtils.loadCertificate("altNameOnly.der");
final IssuerAttributeField field = new IssuerAttributeField(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=test.email.com", str.next());
}
Aggregations