use of org.nhindirect.policy.PolicyLexicon 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.PolicyLexicon 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);
}
}
use of org.nhindirect.policy.PolicyLexicon in project nhin-d by DirectProject.
the class PoliciesController method updatePolicy.
/*********************************
*
* Update Policy Method
*
*********************************/
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/updatePolicy", method = RequestMethod.POST)
@ResponseBody
public String updatePolicy(@RequestParam("id") String id, @RequestParam("policyContent") String policyContent, @RequestParam("policyLexicon") String policyLexicon, @RequestParam("policyName") String policyName) {
String jsonResponse = "";
final org.nhindirect.policy.PolicyLexicon parseLexicon;
if (log.isDebugEnabled()) {
log.debug("Enter update policy #" + id);
}
log.error(policyName);
org.nhind.config.PolicyLexicon lex = null;
// Check the file for three types of policies
if (policyLexicon.isEmpty()) {
lex = org.nhind.config.PolicyLexicon.SIMPLE_TEXT_V1;
} else {
try {
// Convert string of file contents to lexicon object
lex = org.nhind.config.PolicyLexicon.fromString(policyLexicon);
} catch (Exception e) {
log.error("Invalid lexicon name.");
}
}
// Determine lexicon type
if (lex.equals(org.nhind.config.PolicyLexicon.JAVA_SER)) {
parseLexicon = org.nhindirect.policy.PolicyLexicon.JAVA_SER;
} else if (lex.equals(org.nhind.config.PolicyLexicon.SIMPLE_TEXT_V1)) {
parseLexicon = org.nhindirect.policy.PolicyLexicon.SIMPLE_TEXT_V1;
} else {
parseLexicon = org.nhindirect.policy.PolicyLexicon.XML;
}
// Convert policy content string to byte array
byte[] policyContentByteArray = policyContent.getBytes();
return jsonResponse;
}
Aggregations