Commit 41023aea authored by cdanger's avatar cdanger

- BaseXacmlJsonResultPostprocessor.Factory: made abstract

- Added new class for default XACML/XML result postproc
org.ow2.authzforce.core.pdp.impl.io.DefaultXacmlJaxbResultPostprocessorFactory
to pdp-engine/ META-INF/services/...PdpExtension (for Java Service
Loader API)
- Added new class for default XACML/JSON result postproc
org.ow2.authzforce.core.pdp.io.xacml.json.BaseXacmlJsonResultPostprocessor$DefaultFactory
to pdp-io-xacml-json/ META-INF/services/...PdpExtension (for Java
Service Loader API)
- Applied DecisionCache.Factory interface change from core-pdp-pi (new
parameter EnvironmentProperties to getInstance(...)
parent fda8c01b
......@@ -60,8 +60,8 @@ public final class PdpExtensions
/**
* Types of zero-conf (non-JAXB-bound) extension
*/
private static final Set<Class<? extends PdpExtension>> NON_JAXB_BOUND_EXTENSION_CLASSES = HashCollections.newImmutableSet(Arrays.asList(AttributeValueFactory.class, Function.class,
CombiningAlg.class, DecisionRequestPreprocessor.Factory.class, DecisionResultPostprocessor.Factory.class));
private static final Set<Class<? extends PdpExtension>> NON_JAXB_BOUND_EXTENSION_CLASSES = HashCollections
.newImmutableSet(Arrays.asList(AttributeValueFactory.class, Function.class, CombiningAlg.class, DecisionRequestPreprocessor.Factory.class, DecisionResultPostprocessor.Factory.class));
/*
* For each type of zero-conf (non-JAXB-bound) extension, have a map (extension ID -> extension instance), so that the extension ID is scoped to the extension type among the ones listed in
......@@ -241,8 +241,8 @@ public final class PdpExtensions
if (!(ext instanceof CloseableRefPolicyProvider.Factory))
{
throw new IllegalArgumentException("No PDP extension of type " + CloseableRefPolicyProvider.Factory.class
+ " (Reference-based Policy Provider factory) supporting JAXB/XML (configuration) type: " + jaxbConfClass);
throw new IllegalArgumentException(
"No PDP extension of type " + CloseableRefPolicyProvider.Factory.class + " (Reference-based Policy Provider factory) supporting JAXB/XML (configuration) type: " + jaxbConfClass);
}
return (CloseableRefPolicyProvider.Factory<REF_POLICY_PROVIDER_CONF>) ext;
......@@ -271,8 +271,8 @@ public final class PdpExtensions
if (!(ext instanceof RootPolicyProvider.Factory))
{
throw new IllegalArgumentException("No PDP extension of type " + RootPolicyProvider.Factory.class + " (Root Policy Provider factory) supporting JAXB/XML (configuration) type: "
+ jaxbConfClass);
throw new IllegalArgumentException(
"No PDP extension of type " + RootPolicyProvider.Factory.class + " (Root Policy Provider factory) supporting JAXB/XML (configuration) type: " + jaxbConfClass);
}
return (RootPolicyProvider.Factory<ROOT_POLICY_PROVIDER_CONF>) ext;
......@@ -287,7 +287,7 @@ public final class PdpExtensions
* @throws java.lang.IllegalArgumentException
* if there is no extension of type {@link org.ow2.authzforce.core.pdp.api.DecisionCache.Factory} supporting {@code jaxbPdpExtensionClass}
*/
public static <DECISION_CACHE_CONF extends AbstractDecisionCache> DecisionCache.Factory<DECISION_CACHE_CONF> getDecisionCacheFactory(final DECISION_CACHE_CONF jaxbConfClass)
public static <DECISION_CACHE_CONF extends AbstractDecisionCache> DecisionCache.Factory<DECISION_CACHE_CONF> getDecisionCacheFactory(final Class<DECISION_CACHE_CONF> jaxbConfClass)
{
final JaxbBoundPdpExtension<DECISION_CACHE_CONF> ext = (JaxbBoundPdpExtension<DECISION_CACHE_CONF>) JAXB_BOUND_EXTENSIONS_BY_JAXB_CLASS.get(jaxbConfClass);
if (ext == null)
......
package org.ow2.authzforce.core.pdp.impl.io;
import org.ow2.authzforce.core.pdp.api.DecisionResultPostprocessor;
import org.ow2.authzforce.core.pdp.api.io.BaseXacmlJaxbResultPostprocessor;
import org.ow2.authzforce.core.pdp.api.io.IndividualXacmlJaxbRequest;
import org.ow2.authzforce.core.pdp.api.io.BaseXacmlJaxbResultPostprocessor.Factory;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.Response;
/**
*
* Default factory creating instances of {@link BaseXacmlJaxbResultPostprocessor}
*
*/
public final class DefaultXacmlJaxbResultPostprocessorFactory extends Factory
{
/**
* Result postprocessor ID, as returned by {@link #getId()}
*/
public static final String ID = "urn:ow2:authzforce:feature:pdp:result-postproc:xacml-xml:default";
/**
* No-arg constructor
*/
public DefaultXacmlJaxbResultPostprocessorFactory()
{
super(ID);
}
@Override
public DecisionResultPostprocessor<IndividualXacmlJaxbRequest, Response> getInstance(final int clientRequestErrorVerbosityLevel)
{
return new BaseXacmlJaxbResultPostprocessor(clientRequestErrorVerbosityLevel);
}
}
\ No newline at end of file
......@@ -4,4 +4,5 @@ org.ow2.authzforce.core.pdp.impl.policy.CoreRefBasedRootPolicyProvider$Factory
org.ow2.authzforce.core.pdp.impl.io.SingleDecisionXacmlJaxbRequestPreprocessor$LaxVariantFactory
org.ow2.authzforce.core.pdp.impl.io.SingleDecisionXacmlJaxbRequestPreprocessor$StrictVariantFactory
org.ow2.authzforce.core.pdp.impl.io.MultiDecisionXacmlJaxbRequestPreprocessor$LaxVariantFactory
org.ow2.authzforce.core.pdp.impl.io.MultiDecisionXacmlJaxbRequestPreprocessor$StrictVariantFactory
\ No newline at end of file
org.ow2.authzforce.core.pdp.impl.io.MultiDecisionXacmlJaxbRequestPreprocessor$StrictVariantFactory
org.ow2.authzforce.core.pdp.impl.io.DefaultXacmlJaxbResultPostprocessorFactory
......@@ -25,14 +25,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.Advice;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignment;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.DecisionType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.Obligation;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.Status;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.StatusCode;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.StatusDetail;
import org.json.JSONArray;
import org.json.JSONObject;
import org.ow2.authzforce.core.pdp.api.DecisionResult;
......@@ -45,6 +37,14 @@ import org.ow2.authzforce.core.pdp.api.policy.TopLevelPolicyElementType;
import com.google.common.collect.ImmutableList;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.Advice;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignment;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.DecisionType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.Obligation;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.Status;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.StatusCode;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.StatusDetail;
/**
* Convenient base class for {@link DecisionResultPostprocessor} implementations producing XACML/JSON (XACML-JSON-Profile-standard-compliant) output
*
......@@ -274,22 +274,22 @@ public class BaseXacmlJsonResultPostprocessor implements DecisionResultPostproce
}
/**
*
* Factory for this type of result postprocessor
*
* Convenient base class for {@link org.ow2.authzforce.core.pdp.api.DecisionResultPostprocessor.Factory} implementations supporting XACML/JSON output (JSON Profile of XACML)
*
*/
public static class Factory implements DecisionResultPostprocessor.Factory<IndividualXacmlJsonRequest, JSONObject>
public static abstract class Factory implements DecisionResultPostprocessor.Factory<IndividualXacmlJsonRequest, JSONObject>
{
private final String id;
/**
* Request filter ID, as returned by {@link #getId()}
*/
public static final String ID = "urn:ow2:authzforce:feature:pdp:result-postproc:xacml-json:default";
protected Factory(final String id)
{
this.id = id;
}
@Override
public final String getId()
{
return ID;
return id;
}
@Override
......@@ -303,6 +303,27 @@ public class BaseXacmlJsonResultPostprocessor implements DecisionResultPostproce
{
return JSONObject.class;
}
}
/**
*
* Default factory creating instances of {@link BaseXacmlJsonResultPostprocessor}
*
*/
public static final class DefaultFactory extends Factory
{
/**
* Result postprocessor ID, as returned by {@link #getId()}
*/
public static final String ID = "urn:ow2:authzforce:feature:pdp:result-postproc:xacml-json:default";
/**
* No-arg constructor
*/
public DefaultFactory()
{
super(ID);
}
@Override
public DecisionResultPostprocessor<IndividualXacmlJsonRequest, JSONObject> getInstance(final int clientRequestErrorVerbosityLevel)
......
org.ow2.authzforce.core.pdp.io.xacml.json.SingleDecisionXacmlJsonRequestPreprocessor$LaxVariantFactory
org.ow2.authzforce.core.pdp.io.xacml.json.SingleDecisionXacmlJsonRequestPreprocessor$StrictVariantFactory
org.ow2.authzforce.core.pdp.io.xacml.json.BaseXacmlJsonResultPostprocessor$Factory
org.ow2.authzforce.core.pdp.io.xacml.json.BaseXacmlJsonResultPostprocessor$DefaultFactory
......@@ -39,6 +39,8 @@ import org.json.JSONObject;
import org.json.JSONTokener;
import org.ow2.authzforce.core.pdp.api.io.PdpEngineInoutAdapter;
import org.ow2.authzforce.core.pdp.impl.PdpEngineConfiguration;
import org.ow2.authzforce.core.pdp.io.xacml.json.BaseXacmlJsonResultPostprocessor;
import org.ow2.authzforce.core.pdp.io.xacml.json.SingleDecisionXacmlJsonRequestPreprocessor;
import org.ow2.authzforce.core.pdp.testutil.TestUtils;
import org.ow2.authzforce.xacml.json.model.LimitsCheckingJSONObject;
import org.ow2.authzforce.xacml.json.model.Xacml3JsonUtils;
......@@ -84,9 +86,7 @@ public class JsonProfileConformanceV3Test
private static final boolean ENABLE_XPATH = false;
private static final String REQUEST_PREPROC_ID = "urn:ow2:authzforce:feature:pdp:request-preproc:xacml-json:default-lax";
private static final String RESULT_POSTPROC_ID = "urn:ow2:authzforce:feature:pdp:result-postproc:xacml-json:default";
// private static final String RESULT_POSTPROC_ID = "urn:ow2:authzforce:feature:pdp:result-postproc:xacml-json:default";
private static final int MAX_JSON_STRING_LENGTH = 100;
......@@ -134,9 +134,9 @@ public class JsonProfileConformanceV3Test
// normalize responses for comparison
final JSONObject normalizedExpectedResponse = Xacml3JsonUtils.canonicalizeResponse(expectedResponse);
final JSONObject normalizedActualResponse = Xacml3JsonUtils.canonicalizeResponse(actualResponseFromPDP);
Assert.assertTrue(normalizedActualResponse.similar(normalizedExpectedResponse), "Test '" + testId
+ "' (StatusMessage/StatusDetail/nested StatusCode elements removed/ignored for comparison): expected: <" + normalizedExpectedResponse + "> ; actual: <" + normalizedActualResponse
+ ">");
Assert.assertTrue(normalizedActualResponse.similar(normalizedExpectedResponse),
"Test '" + testId + "' (StatusMessage/StatusDetail/nested StatusCode elements removed/ignored for comparison): expected: <" + normalizedExpectedResponse + "> ; actual: <"
+ normalizedActualResponse + ">");
}
public static Collection<Object[]> params(final String testResourcesRootDirectory) throws URISyntaxException, IOException
......@@ -211,8 +211,10 @@ public class JsonProfileConformanceV3Test
* So far we assume the PDP engine configuration files are valid, because for the moment we only test Request/Response in JSON Profile since JSON Profile only applies to these elements (not to
* policies) at the moment. If some day, JSON Profile addresses policy format too, then we should do like in ConformanceV3fromV2 class from pdp-testutils package (policy syntax validation).
*/
final PdpEngineConfiguration pdpEngineConf = TestUtils.newPdpEngineConfiguration(rootPolicyFile.toUri().toURL().toString(), Files.exists(refPoliciesDir) ? refPoliciesDir.toUri().toURL()
.toString() : null, ENABLE_XPATH, Files.exists(attributeProviderConfFile) ? attributeProviderConfFile.toUri().toURL().toString() : null, REQUEST_PREPROC_ID, RESULT_POSTPROC_ID);
final PdpEngineConfiguration pdpEngineConf = TestUtils.newPdpEngineConfiguration(rootPolicyFile.toUri().toURL().toString(),
Files.exists(refPoliciesDir) ? refPoliciesDir.toUri().toURL().toString() : null, ENABLE_XPATH,
Files.exists(attributeProviderConfFile) ? attributeProviderConfFile.toUri().toURL().toString() : null, SingleDecisionXacmlJsonRequestPreprocessor.LaxVariantFactory.ID,
BaseXacmlJsonResultPostprocessor.DefaultFactory.ID);
try (final PdpEngineInoutAdapter<JSONObject, JSONObject> pdp = PdpEngineXacmlJsonAdapters.newXacmlJsonInoutAdapter(pdpEngineConf))
{
// this is an evaluation test with request/response (not a policy syntax check)
......
......@@ -64,7 +64,7 @@ import org.springframework.util.ResourceUtils;
* Configuration 2 for advanced/custom PDP configuration:
* <ul>
* <li>{@value #PDP_CONF_FILENAME}: PDP configuration file</li>
* <li>{@value #PDP_EXTENSION_XSD}: (optional) PDP extensions schema, required iff custom PDP extensions are required</li>
* <li>{@value #PDP_EXTENSION_XSD_FILENAME}: (optional) PDP extensions schema, required iff custom PDP extensions are required</li>
* <li>{@value #REQUEST_FILENAME}: (optional) XACML request file sent to the PDP for evaluation. If not present, the test is considered as a static policy test, i.e. test for invalid policy detection,
* such as invalid syntax, circular reference, etc.</li>
* <li>{@value #EXPECTED_RESPONSE_FILENAME}: (optional) expected XACML response from the PDP, to be compared with the actual response. Required only if {@value #REQUEST_FILENAME} is present.</li>
......@@ -86,7 +86,7 @@ public abstract class PdpTest
/**
* PDP extensions schema
*/
public final static String PDP_EXTENSION_XSD = "pdp-ext.xsd";
public final static String PDP_EXTENSION_XSD_FILENAME = "pdp-ext.xsd";
/**
* XACML policy filename used by default when no PDP configuration file found, i.e. no file named {@value #PDP_CONF_FILENAME} exists in the test directory
......@@ -226,7 +226,7 @@ public abstract class PdpTest
else
{
// PDP configuration filename found in test directory -> create PDP from it
final String pdpExtXsdLocation = testResourceLocationPrefix + PDP_EXTENSION_XSD;
final String pdpExtXsdLocation = testResourceLocationPrefix + PDP_EXTENSION_XSD_FILENAME;
File pdpExtXsdFile = null;
try
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment