Commit e7f03100 authored by cdanger's avatar cdanger

- Fixed #42

- Updated license headers for year 2020
- pdp-cli: fixed pretty-print (-p) option
- pdp-testutils:
  - Renamed class PdpTest to XacmlXmlPdpTest
(org.ow2.authzforce.core.pdp.testutil package)
  - Security fix: jackson-databind upgraded to v2.9.10.1
parent 5f20d185
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......@@ -69,29 +69,28 @@ public final class PdpCommandLineCallable implements Callable<Void>
*/
@Option(names = { "-t",
"--type" }, description = "Type of XACML request/response: 'XACML_XML' for XACML 3.0/XML (XACML core specification), 'XACML_JSON' for XACML 3.0/JSON (JSON Profile of XACML 3.0)")
private final RequestType requestType = RequestType.XACML_XML;
private RequestType requestType = RequestType.XACML_XML;
@Parameters(index = "0", description = "Path to PDP configuration file, valid against schema located at https://github.com/authzforce/core/blob/release-X.Y.Z/pdp-engine/src/main/resources/pdp.xsd (X.Y.Z is the version provided by -v option)")
private File confFile;
@Option(names = { "-c", "--catalog" }, description = "Path to XML catalog for resolving schemas used in extensions XSD specified by -e option, required only if -e specified")
private final String catalogLocation = null;
private String catalogLocation = null;
@Option(names = { "-e",
"--extensions" }, description = "Path to extensions XSD (contains XSD namespace imports for all extensions used in the PDP configuration), required only if using any extension in the PDP configuration file")
private final String extensionXsdLocation = null;
private String extensionXsdLocation = null;
@Parameters(index = "1", description = "XACML Request (format determined by -t option)")
private File reqFile;
@Option(names = { "-p", "--prettyprint" }, description = "Pretty-print output with line feeds and indentation")
private final boolean formattedOutput = false;
private boolean formattedOutput = false;
@Override
public Void call() throws Exception
{
final PdpEngineConfiguration configuration = PdpEngineConfiguration.getInstance(confFile, catalogLocation, extensionXsdLocation);
System.out.println();
switch (requestType)
{
......@@ -131,12 +130,12 @@ public final class PdpCommandLineCallable implements Callable<Void>
final PdpEngineInoutAdapter<Request, Response> xmlPdpEngineAdapter = PdpEngineAdapters.newXacmlJaxbInoutAdapter(configuration);
final Response xmlResponse = xmlPdpEngineAdapter.evaluate((Request) request, parser.getNamespacePrefixUriMap());
final Marshaller marshaller = Xacml3JaxbHelper.createXacml3Marshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, formattedOutput);
final Boolean formatted = Boolean.valueOf(formattedOutput);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, formatted);
marshaller.marshal(xmlResponse, System.out);
break;
}
System.out.println();
return null;
}
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......@@ -19,9 +19,29 @@ package org.ow2.authzforce.core.pdp.cli.test;
import static org.junit.Assert.assertTrue;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.xml.bind.JAXBException;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.junit.Test;
import org.ow2.authzforce.core.pdp.cli.PdpCommandLineCallable;
import org.ow2.authzforce.core.pdp.testutil.TestUtils;
import org.ow2.authzforce.xacml.Xacml3JaxbHelper;
import org.ow2.authzforce.xacml.json.model.XacmlJsonUtils;
import org.testng.Assert;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.Response;
import picocli.CommandLine;
public class CliTest
......@@ -30,14 +50,67 @@ public class CliTest
private static final String TEST_DATA_DIR = "src/test/resources/conformance/xacml-3.0-core/mandatory";
@Test
public void test()
public void testXml() throws UnsupportedEncodingException, JAXBException
{
/*
* Should throw IllegalArgumentException for invalid pdp config, not NPE (because of relative path with no
* parent path which used to cause NPE when trying to get the parent directory path)
*/
CommandLine.call(new PdpCommandLineCallable(), System.out, TEST_DATA_DIR + "/pdp.xml",
TEST_DATA_DIR + "/IIA001/Request.xml");
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (PrintStream ps = new PrintStream(baos, true, "UTF-8"))
{
/*
* Redirect system.out to the byte stream
*/
System.setOut(ps);
/*
* Should throw IllegalArgumentException for invalid pdp config, not NPE (because of relative path with no parent path which used to cause NPE when trying to get the parent directory path)
*/
CommandLine.call(new PdpCommandLineCallable(), System.out, "-p", TEST_DATA_DIR + "/pdp.xml", TEST_DATA_DIR + "/IIA001/Request.xml");
System.setOut(System.out);
}
final String output = new String(baos.toByteArray(), StandardCharsets.UTF_8);
System.out.println(output);
final Response expectedXacmlJaxbObj = (Response) Xacml3JaxbHelper.createXacml3Unmarshaller().unmarshal(new File(TEST_DATA_DIR + "/IIA001/Response.xml"));
final Response actualXacmlJaxbObj;
try
{
actualXacmlJaxbObj = (Response) Xacml3JaxbHelper.createXacml3Unmarshaller().unmarshal(new StringReader(output));
TestUtils.assertNormalizedEquals(TEST_DATA_DIR + "/IIA001", expectedXacmlJaxbObj, actualXacmlJaxbObj);
}
catch (final JAXBException e)
{
Assert.fail("Invalid XACML/XML Response returned", e);
}
}
@Test
public void testJson() throws IOException
{
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (PrintStream ps = new PrintStream(baos, true, "UTF-8"))
{
/*
* Redirect system.out to the byte stream
*/
System.setOut(ps);
/*
* Should throw IllegalArgumentException for invalid pdp config, not NPE (because of relative path with no parent path which used to cause NPE when trying to get the parent directory path)
*/
CommandLine.call(new PdpCommandLineCallable(), System.out, "-p", "-tXACML_JSON", TEST_DATA_DIR + "/pdp.xml", TEST_DATA_DIR + "/IIA001/Request.json");
System.setOut(System.out);
}
final String output = new String(baos.toByteArray(), StandardCharsets.UTF_8);
System.out.println(output);
final JSONObject normalizedExpectedResponse;
try (final BufferedReader reader = Files.newBufferedReader(Paths.get(TEST_DATA_DIR + "/IIA001/Response.json"), StandardCharsets.UTF_8))
{
normalizedExpectedResponse = XacmlJsonUtils.canonicalizeResponse(new JSONObject(new JSONTokener(reader)));
}
final JSONObject normalizedActualResponse = XacmlJsonUtils.canonicalizeResponse(new JSONObject(output));
Assert.assertTrue(normalizedActualResponse.similar(normalizedExpectedResponse), "Actual XACML/JSON Response does not match expected");
}
/**
......@@ -47,13 +120,11 @@ public class CliTest
public void IssueGH9()
{
/*
* Should throw IllegalArgumentException for invalid pdp config, not NPE (because of relative path with no
* parent path which used to cause NPE when trying to get the parent directory path)
* Should throw IllegalArgumentException for invalid pdp config, not NPE (because of relative path with no parent path which used to cause NPE when trying to get the parent directory path)
*/
try
{
CommandLine.call(new PdpCommandLineCallable(), System.out, "pom.xml",
TEST_DATA_DIR + "/IIA001/Request.xml");
CommandLine.call(new PdpCommandLineCallable(), System.out, "pom.xml", TEST_DATA_DIR + "/IIA001/Request.json");
}
catch (final CommandLine.ExecutionException e)
{
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......
/**
* Copyright 2012-2019 THALES.
* Copyright 2012-2020 THALES.
*
* This file is part of AuthzForce CE.
*
......