use of org.ow2.authzforce.core.pdp.api.XmlUtils.XmlnsFilteringParser in project core by authzforce.
the class ComparativePdpTest method policyEval.
@Test
public void policyEval() throws IOException, JAXBException {
final Response actualResponse;
try {
actualResponse = pdpEngineInvoker.eval(this.testDirPath);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("XACML Response received from the PDP: {}", TestUtils.printResponse(actualResponse));
}
} catch (final JAXBException e) {
e.printStackTrace();
Assert.fail("PDP returned invalid response: " + e.getMessage());
return;
}
final XmlnsFilteringParser unmarshaller = XACML_PARSER_FACTORY.getInstance();
final Response expectedResponse = TestUtils.createResponse(this.testDirPath.resolve(EXPECTED_RESPONSE_FILENAME), unmarshaller);
TestUtils.assertNormalizedEquals(testDirPath.toString(), expectedResponse, actualResponse);
}
use of org.ow2.authzforce.core.pdp.api.XmlUtils.XmlnsFilteringParser in project core by authzforce.
the class PdpCommandLineCallable method call.
@Override
public Void call() throws Exception {
final PdpEngineConfiguration configuration = PdpEngineConfiguration.getInstance(confFile, catalogLocation, extensionXsdLocation);
switch(requestType) {
case XACML_JSON:
final JSONObject jsonRequest;
try (InputStream inputStream = new FileInputStream(reqFile)) {
jsonRequest = new JSONObject(new JSONTokener(inputStream));
if (!jsonRequest.has("Request")) {
throw new IllegalArgumentException("Invalid XACML JSON Request file: " + reqFile + ". Expected root key: \"Request\"");
}
XacmlJsonUtils.REQUEST_SCHEMA.validate(jsonRequest);
}
final DecisionResultPostprocessor<IndividualXacmlJsonRequest, JSONObject> defaultResultPostproc = new BaseXacmlJsonResultPostprocessor(configuration.getClientRequestErrorVerbosityLevel());
final DecisionRequestPreprocessor<JSONObject, IndividualXacmlJsonRequest> defaultReqPreproc = SingleDecisionXacmlJsonRequestPreprocessor.LaxVariantFactory.INSTANCE.getInstance(configuration.getAttributeValueFactoryRegistry(), configuration.isStrictAttributeIssuerMatchEnabled(), configuration.isXPathEnabled(), defaultResultPostproc.getFeatures());
final PdpEngineInoutAdapter<JSONObject, JSONObject> jsonPdpEngineAdapter = PdpEngineAdapters.newInoutAdapter(JSONObject.class, JSONObject.class, configuration, defaultReqPreproc, defaultResultPostproc);
final JSONObject jsonResponse = jsonPdpEngineAdapter.evaluate(jsonRequest);
System.out.println(jsonResponse.toString(formattedOutput ? 4 : 0));
break;
default:
final XmlnsFilteringParser parser = XacmlJaxbParsingUtils.getXacmlParserFactory(true).getInstance();
final Object request = parser.parse(reqFile.toURI().toURL());
if (!(request instanceof Request)) {
throw new IllegalArgumentException("Invalid XACML/XML Request file (according to XACML 3.0 schema): " + reqFile);
}
final PdpEngineInoutAdapter<Request, Response> xmlPdpEngineAdapter = PdpEngineAdapters.newXacmlJaxbInoutAdapter(configuration);
final Response xmlResponse = xmlPdpEngineAdapter.evaluate((Request) request, parser.getNamespacePrefixUriMap());
final Marshaller marshaller = Xacml3JaxbHelper.createXacml3Marshaller();
final Boolean formatted = formattedOutput;
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, formatted);
marshaller.marshal(xmlResponse, System.out);
break;
}
return null;
}
Aggregations