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);
}
use of org.nhindirect.policy.PolicyParseException in project nhin-d by DirectProject.
the class JavaSerializedObjectLexiconPolicyParser_serializeTest method testDeserializeo_invalidObject_assertExecption.
public void testDeserializeo_invalidObject_assertExecption() throws Exception {
boolean exceptionOccured = false;
final JavaSerializedObjectLexiconPolicyParser parser = new JavaSerializedObjectLexiconPolicyParser();
try {
parser.deserialize(new ByteArrayInputStream(new byte[] { 0, 1, 2 }));
} catch (PolicyParseException e) {
exceptionOccured = true;
}
assertTrue(exceptionOccured);
}
use of org.nhindirect.policy.PolicyParseException in project nhin-d by DirectProject.
the class WSSmtpAgentConfig method addPolicyToMap.
public void addPolicyToMap(Map<String, Collection<PolicyExpression>> policyMap, String domainName, CertPolicyGroupReltn 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.getCertPolicy();
final PolicyLexicon lexicon;
if (policy.getLexicon().equals(org.nhind.config.PolicyLexicon.JAVA_SER))
lexicon = PolicyLexicon.JAVA_SER;
else if (policy.getLexicon().equals(org.nhind.config.PolicyLexicon.SIMPLE_TEXT_V1))
lexicon = PolicyLexicon.SIMPLE_TEXT_V1;
else
lexicon = PolicyLexicon.XML;
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);
}
}
Aggregations