Search in sources :

Example 1 with TBSFieldName

use of org.nhindirect.policy.x509.TBSFieldName 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;
}
Also used : IssuerAttributeField(org.nhindirect.policy.x509.IssuerAttributeField) RDNAttributeIdentifier(org.nhindirect.policy.x509.RDNAttributeIdentifier) TBSFieldName(org.nhindirect.policy.x509.TBSFieldName) SubjectAttributeField(org.nhindirect.policy.x509.SubjectAttributeField) PolicyParseException(org.nhindirect.policy.PolicyParseException) PolicyGrammarException(org.nhindirect.policy.PolicyGrammarException) IOException(java.io.IOException) PolicyParseException(org.nhindirect.policy.PolicyParseException)

Aggregations

IOException (java.io.IOException)1 PolicyGrammarException (org.nhindirect.policy.PolicyGrammarException)1 PolicyParseException (org.nhindirect.policy.PolicyParseException)1 IssuerAttributeField (org.nhindirect.policy.x509.IssuerAttributeField)1 RDNAttributeIdentifier (org.nhindirect.policy.x509.RDNAttributeIdentifier)1 SubjectAttributeField (org.nhindirect.policy.x509.SubjectAttributeField)1 TBSFieldName (org.nhindirect.policy.x509.TBSFieldName)1