Search in sources :

Example 6 with XmlnsFilteringParser

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);
}
Also used : DOMResponse(com.att.research.xacml.std.dom.DOMResponse) Response(oasis.names.tc.xacml._3_0.core.schema.wd_17.Response) XmlnsFilteringParser(org.ow2.authzforce.core.pdp.api.XmlUtils.XmlnsFilteringParser) JAXBException(javax.xml.bind.JAXBException) Test(org.junit.Test)

Example 7 with XmlnsFilteringParser

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;
}
Also used : XmlnsFilteringParser(org.ow2.authzforce.core.pdp.api.XmlUtils.XmlnsFilteringParser) PdpEngineConfiguration(org.ow2.authzforce.core.pdp.impl.PdpEngineConfiguration) Marshaller(javax.xml.bind.Marshaller) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IndividualXacmlJsonRequest(org.ow2.authzforce.core.pdp.io.xacml.json.IndividualXacmlJsonRequest) Request(oasis.names.tc.xacml._3_0.core.schema.wd_17.Request) IndividualXacmlJsonRequest(org.ow2.authzforce.core.pdp.io.xacml.json.IndividualXacmlJsonRequest) FileInputStream(java.io.FileInputStream) JSONTokener(org.json.JSONTokener) Response(oasis.names.tc.xacml._3_0.core.schema.wd_17.Response) JSONObject(org.json.JSONObject) BaseXacmlJsonResultPostprocessor(org.ow2.authzforce.core.pdp.io.xacml.json.BaseXacmlJsonResultPostprocessor) JSONObject(org.json.JSONObject)

Aggregations

XmlnsFilteringParser (org.ow2.authzforce.core.pdp.api.XmlUtils.XmlnsFilteringParser)7 Response (oasis.names.tc.xacml._3_0.core.schema.wd_17.Response)5 JAXBException (javax.xml.bind.JAXBException)4 Request (oasis.names.tc.xacml._3_0.core.schema.wd_17.Request)4 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 Test (org.junit.Test)3 PdpEngineConfiguration (org.ow2.authzforce.core.pdp.impl.PdpEngineConfiguration)3 File (java.io.File)2 Path (java.nio.file.Path)2 IndeterminateEvaluationException (org.ow2.authzforce.core.pdp.api.IndeterminateEvaluationException)2 DOMResponse (com.att.research.xacml.std.dom.DOMResponse)1 HashBasedTable (com.google.common.collect.HashBasedTable)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Table (com.google.common.collect.Table)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1