/** * Tries to read an XACML policy or policy set from the given stream. * * @param input * the stream containing the policy to read * @return a (potentially schema-validated) policy loaded from the given * file * @throws ParsingException * if an error occurs while reading or parsing the policy */ public synchronized Document readPolicy(InputStream input) throws ParsingException { try { return builder.parse(input); } catch (IOException ioe) { throw new ParsingException("Failed to read the stream", ioe); } catch (SAXException saxe) { throw new ParsingException("Failed to parse the stream", saxe); } }
@Override public Map<String, AbstractPolicy> getPolicies(EvaluationCtx eval, PolicyFinder policyFinder) throws PolicyIndexException { // no indexing, return everything // return a copy, otherwise the map could change during evaluation if policies are added, deleted etc readLock.lock(); try { Map<String, AbstractPolicy> result = new ConcurrentHashMap<String, AbstractPolicy>(); for(String id:policies.keySet()){ AbstractPolicy policy = handleDocument(m_policyReader.readPolicy(policies.get(id)),policyFinder); result.put(id, policy); } return result; } catch (ParsingException pe) { throw new PolicyIndexException(pe.getMessage(),pe); }finally { readLock.unlock(); } }
/** * Tries to read an XACML policy or policy set from the given file. * * @param file * the file containing the policy to read * @return a (potentially schema-validated) policy loaded from the given * file * @throws ParsingException * if an error occurs while reading or parsing the policy */ public synchronized Document readPolicy(File file) throws ParsingException { try { return builder.parse(file); } catch (IOException ioe) { throw new ParsingException("Failed to read the file", ioe); } catch (SAXException saxe) { throw new ParsingException("Failed to parse the file", saxe); } }
@Override public AbstractPolicy getPolicy(String name, PolicyFinder policyFinder) throws PolicyIndexException { readLock.lock(); try { logger.debug("Getting policy named: " + name); if (policies.containsKey(name)) { return handleDocument(m_policyReader.readPolicy(policies.get(name)), policyFinder); } else { throw new PolicyIndexException("Attempting to get non-existent policy " + name); } } catch (ParsingException pe) { throw new PolicyIndexException(pe.getMessage(),pe); } finally { readLock.unlock(); } }
/** * Returns a <code>BooleanAttribute</code> that represents * the xs:boolean value indicated by the string provided. * * @param value a string representing the desired value * @return a <code>BooleanAttribute</code> representing the * appropriate value (null if there is a parsing error) */ public static BooleanAttribute getInstance(String value) throws ParsingException { if (value.equals("true")) return trueInstance; if (value.equals("false")) return falseInstance; throw new ParsingException("Boolean string must be true or false"); }
@Override public AbstractPolicy getPolicy(String name, PolicyFinder policyFinder) throws PolicyIndexException { try { readLock.lock(); XMLResource resource = (XMLResource) m_collection.getResource(nameToId(name)); if (resource == null) { log.error("Attempting to get non-existant resource " + name); throw new PolicyIndexException("Attempting to get non-existant resource " + name); } Document policyDoc = m_policyReader.readPolicy(((String)resource.getContent()).getBytes("UTF-8")); return handleDocument(policyDoc, policyFinder); } catch (UnsupportedEncodingException e) { // Should never happen throw new RuntimeException("Unsupported encoding " + e.getMessage(), e); } catch (XMLDBException e) { log.error("Error getting policy " + name + " " + e.getMessage(), e); throw new PolicyIndexException("Error getting policy " + name + " " + e.getMessage(), e); } catch (ParsingException e) { log.error("Error getting policy " + name + " " + e.getMessage(), e); throw new PolicyIndexException("Error getting policy " + name + " " + e.getMessage(), e); } finally { readLock.unlock(); } }
/** * Private helper routine that converts text into a node */ private Node textToNode(String encoded) throws ParsingException { try { String text = "<?xml version=\"1.0\"?>\n"; byte [] bytes = (text + encoded).getBytes(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder db = factory.newDocumentBuilder(); Document doc = db.parse(new ByteArrayInputStream(bytes)); return doc.getDocumentElement(); } catch (Exception e) { throw new ParsingException("invalid XML for status detail"); } }
Status status = new Status(code, pe.getMessage());
/** * Tries to read an XACML policy or policy set from the given file. * * @param file the file containing the policy to read * * @return a (potentially schema-validated) policy loaded from the * given file * * @throws ParsingException if an error occurs while reading or * parsing the policy */ public synchronized AbstractPolicy readPolicy(File file) throws ParsingException { try { return handleDocument(builder.parse(file)); } catch (IOException ioe) { throw new ParsingException("Failed to read the file", ioe); } catch (SAXException saxe) { throw new ParsingException("Failed to parse the file", saxe); } }
@Override public AbstractPolicy getPolicy(String name, PolicyFinder policyFinder) throws PolicyIndexException { log.debug("Getting document: " + name); XmlDocument doc = null; DbXmlManager.readLock.lock(); try { doc = m_dbXmlManager.container.getDocument(name); return handleDocument(m_policyReader.readPolicy(doc.getContent()), policyFinder); } catch (XmlException xe) { throw new PolicyIndexException("Error getting Policy: " + name + xe.getMessage() + " - " + xe.getDatabaseException().getMessage(), xe); } catch (ParsingException pe) { throw new PolicyIndexException("Error getting Policy: " + name + pe.getMessage(), pe); } finally { DbXmlManager.readLock.unlock(); } }
/** * Tries to read an XACML policy or policy set from the given stream. * * @param input the stream containing the policy to read * * @return a (potentially schema-validated) policy loaded from the * given file * * @throws ParsingException if an error occurs while reading or * parsing the policy */ public synchronized AbstractPolicy readPolicy(InputStream input) throws ParsingException { try { return handleDocument(builder.parse(input)); } catch (IOException ioe) { throw new ParsingException("Failed to read the stream", ioe); } catch (SAXException saxe) { throw new ParsingException("Failed to parse the stream", saxe); } }
return createProcessingError(pe.getMessage()); } catch (UnknownIdentifierException uie) { return createProcessingError("unknown attribute type: " + type);
db = dbFactory.newDocumentBuilder(); } catch (ParserConfigurationException pce) { throw new ParsingException("couldn't get a document builder", pce); doc = db.parse(new FileInputStream(configFile)); } catch (IOException ioe) { throw new ParsingException("failed to load the file ", ioe); } catch (SAXException saxe) { throw new ParsingException("error parsing the XML tree", saxe); } catch (IllegalArgumentException iae) { throw new ParsingException("no data to parse", iae); throw new ParsingException("unknown document type: " + root.getTagName());
throw new PolicyIndexException("Error retrieving query results " + e.getMessage(), e); } catch (ParsingException e) { log.error("Error retrieving query results " + e.getMessage(), e); throw new PolicyIndexException("Error retrieving query results " + e.getMessage(), e); } catch (UnsupportedEncodingException e) {
/** * Helper method that handles the obligations */ private static Set parseObligations(Node root) throws ParsingException { Set set = new HashSet(); NodeList nodes = root.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (SunxacmlUtil.getNodeName(node).equals("Obligation")) set.add(Obligation.getInstance(node)); } if (set.size() == 0) throw new ParsingException("ObligationsType must not be empty"); return set; }
throw new PolicyIndexException("Error getting query results." + xe.getMessage(), xe); } catch (ParsingException pe) { log.error("Error getting query results." + pe.getMessage()); throw new PolicyIndexException("Error getting query results." + pe.getMessage(), pe); } finally { DbXmlManager.readLock.unlock();
/** * Tries to read an XACML policy or policy set based on the given URL. This * may be any resolvable URL, like a file or http pointer. * * @param url * a URL pointing to the policy to read * @return a (potentially schema-validated) policy loaded from the given * file * @throws ParsingException * if an error occurs while reading or parsing the policy, or if the * URL can't be resolved */ public synchronized Document readPolicy(URL url) throws ParsingException { try { return readPolicy(url.openStream()); } catch (IOException ioe) { throw new ParsingException("Failed to resolve the URL: " + url.toString(), ioe); } }
/** * Tries to read an XACML policy or policy set based on the given URL. * This may be any resolvable URL, like a file or http pointer. * * @param url a URL pointing to the policy to read * * @return a (potentially schema-validated) policy loaded from the * given file * * @throws ParsingException if an error occurs while reading or * parsing the policy, or if the URL can't * be resolved */ public synchronized AbstractPolicy readPolicy(URL url) throws ParsingException { try { return readPolicy(url.openStream()); } catch (IOException ioe) { throw new ParsingException("Failed to resolve the URL: " + url.toString(), ioe); } }
/** * Default constructor. This constructor uses the * <code>PDP_CONFIG_PROPERTY</code> property to load the configuration. * If the property isn't set, if it names a file that can't be accessed, * or if the file is invalid, then an exception is thrown. * * @throws ParsingException if anything goes wrong during the parsing * of the configuration file, the class loading, * or the factory and pdp setup */ public ConfigurationStore() throws ParsingException { String configFile = System.getProperty(PDP_CONFIG_PROPERTY); // make sure that the right property was set if (configFile == null) { logger.severe("A property defining a config file was expected, " + "but none was provided"); throw new ParsingException("Config property " + PDP_CONFIG_PROPERTY + " needs to be set"); } try { setupConfig(new File(configFile)); } catch (ParsingException pe) { logger.log(Level.SEVERE, "Runtime config file couldn't be loaded" + " so no configurations will be available", pe); throw pe; } }
nodes = doc.getElementsByTagName(rootTag); } catch (Exception e) { throw new ParsingException("Error tring to parse " + rootTag + "Type", e); throw new ParsingException("Only one " + rootTag + "Type allowed " + "at the root of a Context doc");