fail("One argument required: /path/to/xacml-policy-to-validate.xml"); fail("System property " + schemaPathProperty + " (path to XACML " + "schema) must be set. (e.g. -D" + schemaPathProperty + "=/path/to/schema)"); InputStream instance = getStream(args[0]); PolicyParser parser = new PolicyParser(getStream(schemaPath)); parser.parse(instance, true); System.out.println("Validation successful"); System.exit(0); } catch (ValidationException e) { if (e.getCause() != null && e.getCause() instanceof SAXParseException) { fail(e.getCause().getMessage()); } else { fail(e); fail(e);
/** * Creates an instance that will validate according to the given schema. * * @param schemaStream the XSD schema to use for schema validation * @throws IOException if the schema can't be read * @throws SAXException if the schema isn't valid */ public PolicyParser(InputStream schemaStream) throws IOException, SAXException { this(getSchema(schemaStream)); }
@Override public Map<String, AbstractPolicy> loadPolicies(PolicyParser policyParser, boolean validate, File dir) throws IOException, ValidationException { Map<String,AbstractPolicy> policies = new HashMap<String,AbstractPolicy>(); for (File file: dir.listFiles()) { if (file.isDirectory()) { policies.putAll(loadPolicies(policyParser, validate, file)); } else { if (file.getName().endsWith(".xml")) { logger.info("Loading policy: {}", file.getPath()); InputStream policyStream = new FileInputStream(file); policies.put(file.getPath(), policyParser.parse(policyStream, validate)); } } } return policies; }
/** * Gets a new instance that uses the same schema as this one. * * @return a copy of this instance */ public PolicyParser copy() { return new PolicyParser(m_validators); }
/** * Gets a deny-biased policy set that includes all repository-wide and * object-specific policies. */ @Override public PolicyFinderResult findPolicy(EvaluationCtx context) { PolicyFinderResult policyFinderResult = null; PolicySet policySet = m_repositoryPolicySet; try { String pid = getPid(context); if (pid != null && !pid.isEmpty()) { AbstractPolicy objectPolicyFromObject = m_policyLoader.loadObjectPolicy(m_policyParser.copy(), pid, m_validateObjectPoliciesFromDatastream); if (objectPolicyFromObject != null) { List<AbstractPolicy> policies = new ArrayList<AbstractPolicy>(m_repositoryPolicies); policies.add(objectPolicyFromObject); policySet = toPolicySet(policies, m_combiningAlgorithm); } } policyFinderResult = new PolicyFinderResult(policySet); } catch (Exception e) { logger.warn("PolicyFinderModule seriously failed to evaluate a policy ", e); policyFinderResult = new PolicyFinderResult(new Status(ERROR_CODE_LIST, e .getMessage())); } return policyFinderResult; }
private static InputStream getStream(String path) { try { return new FileInputStream(path); } catch (Exception e) { fail("File not found: " + path); return null; } }
@Override public Map<String, AbstractPolicy> loadPolicies(PolicyParser policyParser, boolean validate, File dir) throws IOException, ValidationException { Map<String,AbstractPolicy> policies = new HashMap<String,AbstractPolicy>(); for (File file: dir.listFiles()) { if (file.isDirectory()) { policies.putAll(loadPolicies(policyParser, validate, file)); } else { if (file.getName().endsWith(".xml")) { logger.info("Loading policy: {}", file.getPath()); InputStream policyStream = new FileInputStream(file); policies.put(file.getPath(), policyParser.parse(policyStream, validate)); } } } return policies; }
/** * Gets a new instance that uses the same schema as this one. * * @return a copy of this instance */ public PolicyParser copy() { return new PolicyParser(m_validators); }
/** * Gets a deny-biased policy set that includes all repository-wide and * object-specific policies. */ @Override public PolicyFinderResult findPolicy(EvaluationCtx context) { PolicyFinderResult policyFinderResult = null; PolicySet policySet = m_repositoryPolicySet; try { String pid = getPid(context); if (pid != null && !pid.isEmpty()) { AbstractPolicy objectPolicyFromObject = m_policyLoader.loadObjectPolicy(m_policyParser.copy(), pid, m_validateObjectPoliciesFromDatastream); if (objectPolicyFromObject != null) { List<AbstractPolicy> policies = new ArrayList<AbstractPolicy>(m_repositoryPolicies); policies.add(objectPolicyFromObject); policySet = toPolicySet(policies, m_combiningAlgorithm); } } policyFinderResult = new PolicyFinderResult(policySet); } catch (Exception e) { logger.warn("PolicyFinderModule seriously failed to evaluate a policy ", e); policyFinderResult = new PolicyFinderResult(new Status(ERROR_CODE_LIST, e .getMessage())); } return policyFinderResult; }
private static InputStream getStream(String path) { try { return new FileInputStream(path); } catch (Exception e) { fail("File not found: " + path); return null; } }
fail("One argument required: /path/to/xacml-policy-to-validate.xml"); fail("System property " + schemaPathProperty + " (path to XACML " + "schema) must be set. (e.g. -D" + schemaPathProperty + "=/path/to/schema)"); InputStream instance = getStream(args[0]); PolicyParser parser = new PolicyParser(getStream(schemaPath)); parser.parse(instance, true); System.out.println("Validation successful"); System.exit(0); } catch (ValidationException e) { if (e.getCause() != null && e.getCause() instanceof SAXParseException) { fail(e.getCause().getMessage()); } else { fail(e); fail(e);
@Override public Map<String, AbstractPolicy> loadPolicies(PolicyParser policyParser, boolean validate, File dir) throws IOException, ValidationException { Map<String,AbstractPolicy> policies = new HashMap<String,AbstractPolicy>(); File defaultDir = new File(dir,"default"); if (defaultDir.exists()){ policies.putAll(loadPolicies(policyParser, validate,defaultDir)); } for (File file: dir.listFiles()) { if (!file.getName().equals("default")){ if (file.isDirectory()) { policies.putAll(loadPolicies(policyParser, validate, file)); } else { if (file.getName().endsWith(".xml")) { logger.info("Loading policy: {}", file.getPath()); InputStream policyStream = new FileInputStream(file); AbstractPolicy policy = policyParser.parse(policyStream, validate); logger.info("Loaded policy ID: {}", policy.getId()); String key = null; if (m_override == Strategy.FILENAME) { key = file.getName(); } else key = policy.getId().toString(); policies.put(key, policy); } } } } return policies; }
+ schemaLocation; FileInputStream in = new FileInputStream(schemaPath); PolicyParser policyParser = new PolicyParser(in); ValidationUtility.setFeslPolicyParser(policyParser); } catch (IOException ioe) {
private static void fail(Exception e) { e.printStackTrace(); fail(e.getClass().getName() + ": See above for detail"); } /**
/** * Creates an instance that will validate according to the given schema. * * @param schemaStream the XSD schema to use for schema validation * @throws IOException if the schema can't be read * @throws SAXException if the schema isn't valid */ public PolicyParser(InputStream schemaStream) throws IOException, SAXException { this(getSchema(schemaStream)); }
private static void validateFESLPOLICY(InputStream content) throws ValidationException { // if FeSL is not enabled, this won't be set if (feslPolicyParser != null) { logger.debug("Validating FESLPOLICY datastream"); // FIXME: maintaining backwards compatibility; policy validation should really be enforced feslPolicyParser.copy().parse(content, validateFeslPolicy); logger.debug("FESLPOLICY datastream is valid"); } }
@Override public Map<String, AbstractPolicy> loadPolicies(PolicyParser policyParser, boolean validate, File dir) throws IOException, ValidationException { Map<String,AbstractPolicy> policies = new HashMap<String,AbstractPolicy>(); File defaultDir = new File(dir,"default"); if (defaultDir.exists()){ policies.putAll(loadPolicies(policyParser, validate,defaultDir)); } for (File file: dir.listFiles()) { if (!file.getName().equals("default")){ if (file.isDirectory()) { policies.putAll(loadPolicies(policyParser, validate, file)); } else { if (file.getName().endsWith(".xml")) { logger.info("Loading policy: {}", file.getPath()); InputStream policyStream = new FileInputStream(file); AbstractPolicy policy = policyParser.parse(policyStream, validate); logger.info("Loaded policy ID: {}", policy.getId()); String key = null; if (m_override == Strategy.FILENAME) { key = file.getName(); } else key = policy.getId().toString(); policies.put(key, policy); } } } } return policies; }
m_policyParser = new PolicyParser(in); ValidationUtility.setPolicyParser(m_policyParser); } catch (Exception e) {