use of org.ow2.authzforce.jaxrs.util.JsonRiJaxrsProvider in project restful-pdp by authzforce.
the class XacmlRestProfileJaxRsTest method testInvalidPdpRequest.
@Test
public void testInvalidPdpRequest() throws IOException {
// Request body (invalid according to JSON schema)
final String reqLocation = "src/test/resources/server/IIA001/Request-missing-category-id.json";
try (InputStream reqIn = new FileInputStream(reqLocation)) {
final JSONObject jsonRequest = new LimitsCheckingJSONObject(new InputStreamReader(reqIn, StandardCharsets.UTF_8), MAX_JSON_STRING_LENGTH, MAX_JSON_CHILDREN_COUNT, MAX_JSON_DEPTH);
if (!jsonRequest.has("Request")) {
throw new IllegalArgumentException("Invalid XACML JSON Request file: " + reqLocation + ". Expected root key: \"Request\"");
}
/*
* No preliminary request schema validation this time, let the server reject it
*/
// send request
final WebClient client = WebClient.create("http://localhost:" + port + "/services", Collections.singletonList(new JsonRiJaxrsProvider()));
final Response actualResponse = client.path("pdp").type("application/xacml+json").accept("application/xacml+json").post(jsonRequest);
// check response
Assert.assertEquals(Status.BAD_REQUEST.getStatusCode(), actualResponse.getStatus());
}
}
use of org.ow2.authzforce.jaxrs.util.JsonRiJaxrsProvider in project restful-pdp by authzforce.
the class XacmlRestProfileJaxRsTest method testPdpRequest.
@Test
public void testPdpRequest() throws IOException {
// Request body
final String reqLocation = "src/test/resources/IIA001/Request.json";
final JSONObject jsonRequest = new LimitsCheckingJSONObject(new FileReader(reqLocation, StandardCharsets.UTF_8), MAX_JSON_STRING_LENGTH, MAX_JSON_CHILDREN_COUNT, MAX_JSON_DEPTH);
if (!jsonRequest.has("Request")) {
throw new IllegalArgumentException("Invalid XACML JSON Request file: " + reqLocation + ". Expected root key: \"Request\"");
}
XacmlJsonUtils.REQUEST_SCHEMA.validate(jsonRequest);
// expected response
final String respLocation = "src/test/resources/IIA001/Response.json";
final JSONObject expectedResponse = new LimitsCheckingJSONObject(new FileReader(respLocation, StandardCharsets.UTF_8), MAX_JSON_STRING_LENGTH, MAX_JSON_CHILDREN_COUNT, MAX_JSON_DEPTH);
if (!expectedResponse.has("Response")) {
throw new IllegalArgumentException("Invalid XACML JSON Response file: " + respLocation + ". Expected root key: \"Response\"");
}
XacmlJsonUtils.RESPONSE_SCHEMA.validate(expectedResponse);
// send request
final WebClient client = WebClient.create(ENDPOINT_ADDRESS, Collections.singletonList(new JsonRiJaxrsProvider()));
final JSONObject actualResponse = client.path("pdp").type("application/xacml+json").accept("application/xacml+json").post(jsonRequest, JSONObject.class);
// check response
Assert.assertTrue(expectedResponse.similar(actualResponse), "JSON response does not match expected one.");
}
use of org.ow2.authzforce.jaxrs.util.JsonRiJaxrsProvider in project restful-pdp by authzforce.
the class XacmlRestProfileJaxRsTest method startServer.
private static void startServer(String pdpConfigLocation) throws Exception {
final PdpEngineConfiguration pdpConf = PdpEngineConfiguration.getInstance(pdpConfigLocation, "src/test/resources/catalog.xml", "src/test/resources/pdp-ext.xsd");
/*
* See also http://cxf.apache.org/docs/secure-jax-rs-services.html
*/
final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(XacmlPdpResource.class);
sf.setResourceProvider(XacmlPdpResource.class, new SingletonResourceProvider(new XacmlPdpResource(pdpConf)));
// add custom providers if any
sf.setProviders(Collections.singletonList(new JsonRiJaxrsProvider()));
final LoggingFeature loggingFeature = new LoggingFeature();
loggingFeature.setPrettyLogging(true);
loggingFeature.setVerbose(true);
sf.setFeatures(Collections.singletonList(loggingFeature));
sf.setAddress(ENDPOINT_ADDRESS);
server = sf.create();
}
use of org.ow2.authzforce.jaxrs.util.JsonRiJaxrsProvider in project restful-pdp by authzforce.
the class XacmlRestProfileJaxRsTest method testPdpRequest.
// @Autowired
// private TestRestTemplate restTemplate;
@Test
public void testPdpRequest() throws IOException {
// Request body
final String reqLocation = "src/test/resources/server/IIA001/Request.json";
try (InputStream reqIn = new FileInputStream(reqLocation)) {
final JSONObject jsonRequest = new LimitsCheckingJSONObject(new InputStreamReader(reqIn, StandardCharsets.UTF_8), MAX_JSON_STRING_LENGTH, MAX_JSON_CHILDREN_COUNT, MAX_JSON_DEPTH);
if (!jsonRequest.has("Request")) {
throw new IllegalArgumentException("Invalid XACML JSON Request file: " + reqLocation + ". Expected root key: \"Request\"");
}
XacmlJsonUtils.REQUEST_SCHEMA.validate(jsonRequest);
// expected response
final String respLocation = "src/test/resources/server/IIA001/Response.json";
try (final InputStream respIn = new FileInputStream(respLocation)) {
final JSONObject expectedResponse = new LimitsCheckingJSONObject(new InputStreamReader(respIn, StandardCharsets.UTF_8), MAX_JSON_STRING_LENGTH, MAX_JSON_CHILDREN_COUNT, MAX_JSON_DEPTH);
if (!expectedResponse.has("Response")) {
throw new IllegalArgumentException("Invalid XACML JSON Response file: " + respLocation + ". Expected root key: \"Response\"");
}
XacmlJsonUtils.RESPONSE_SCHEMA.validate(expectedResponse);
// send request
final WebClient client = WebClient.create("http://localhost:" + port + "/services", Collections.singletonList(new JsonRiJaxrsProvider()));
final JSONObject actualResponse = client.path("pdp").type("application/xacml+json").accept("application/xacml+json").post(jsonRequest, JSONObject.class);
// check response
Assert.assertTrue(expectedResponse.similar(actualResponse));
}
}
}
Aggregations