use of org.nhindirect.policy.PolicyParseException in project nhin-d by DirectProject.
the class RESTSmtpAgentConfig method addPolicyToMap.
public void addPolicyToMap(Map<String, Collection<PolicyExpression>> policyMap, String domainName, CertPolicyGroupUse policyReltn) {
// check to see if the domain is in the map
Collection<PolicyExpression> policyExpressionCollection = policyMap.get(domainName);
if (policyExpressionCollection == null) {
policyExpressionCollection = new ArrayList<PolicyExpression>();
policyMap.put(domainName, policyExpressionCollection);
}
final CertPolicy policy = policyReltn.getPolicy();
final PolicyLexicon lexicon = policy.getLexicon();
final InputStream inStr = new ByteArrayInputStream(policy.getPolicyData());
try {
// grab a parser and compile this policy
final PolicyLexiconParser parser = PolicyLexiconParserFactory.getInstance(lexicon);
policyExpressionCollection.add(parser.parse(inStr));
} catch (PolicyParseException ex) {
throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "Failed parse policy into policy expression: " + ex.getMessage(), ex);
} finally {
IOUtils.closeQuietly(inStr);
}
}
use of org.nhindirect.policy.PolicyParseException in project nhin-d by DirectProject.
the class JavaSerializedObjectLexiconPolicyParser method deserialize.
/**
* {@inheritDoc}
*/
@Override
public PolicyExpression deserialize(InputStream stream) throws PolicyParseException {
if (stream == null)
throw new IllegalArgumentException("POJO serialization input stream cannot be null.");
try {
final ObjectInputStream in = new ObjectInputStream(stream);
final PolicyExpression retVal = (PolicyExpression) in.readObject();
return retVal;
} catch (Exception e) {
throw new PolicyParseException("Could not deseriale policy expression from serialized POJO.", e);
}
}
use of org.nhindirect.policy.PolicyParseException in project nhin-d by DirectProject.
the class JavaSerializedObjectLexiconPolicyParser method serialize.
/**
* {@inheritDoc}
*/
@Override
public void serialize(PolicyExpression expression, OutputStream out) throws PolicyParseException {
if (expression == null)
throw new IllegalArgumentException("Policy expression cannot be null.");
if (out == null)
throw new IllegalArgumentException("POJO output stream cannot be null.");
try {
final ObjectOutputStream objectStream = new ObjectOutputStream(out);
objectStream.writeObject(expression);
objectStream.close();
}///CLOVER:OFF
catch (IOException e) {
throw new PolicyParseException("Could not serialize policy expression to serialized POJO.", e);
}
///CLOVER:ON
}
use of org.nhindirect.policy.PolicyParseException 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.PolicyParseException 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);
}
Aggregations