Class TestUtils
- java.lang.Object
-
- org.ow2.authzforce.core.pdp.testutil.TestUtils
-
public class TestUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static javax.xml.bind.JAXBContext
TEST_ATTRIBUTE_PROVIDER_JAXB_CONTEXT
JAXB context for (un)marshalling TestAttributeProvider configuration
-
Constructor Summary
Constructors Constructor Description TestUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
assertNormalizedEquals(String testId, oasis.names.tc.xacml._3_0.core.schema.wd_17.Response expectedResponse, oasis.names.tc.xacml._3_0.core.schema.wd_17.Response actualResponseFromPDP, boolean ignoreStatusMessageAndDetail)
assertEquals() for XACML responses (handles normalization of the responses)static oasis.names.tc.xacml._3_0.core.schema.wd_17.Request
createRequest(Path requestFile, org.ow2.authzforce.core.pdp.api.XmlUtils.XmlnsFilteringParser unmarshaller)
This creates the XACML request from file on classpathstatic oasis.names.tc.xacml._3_0.core.schema.wd_17.Response
createResponse(Path responseFile, org.ow2.authzforce.core.pdp.api.XmlUtils.XmlnsFilteringParser unmarshaller)
This creates the XACML response from file on classpathstatic TopLevelPolicyElementRef
getPolicyRef(Path path)
Gets policy ref from XACML policy filestatic PdpEngineConfiguration
newPdpEngineConfiguration(Path rootPolicyFile, boolean enableXPath, Optional<Path> attributeProviderConfFile, String requestPreprocId, String resultPostprocId)
Creates PDP engine configurationstatic PdpEngineConfiguration
newPdpEngineConfiguration(TopLevelPolicyElementRef rootPolicyRef, Path policiesDirectory, boolean enableXPath, Optional<Path> attributeProviderConfFile, String requestPreprocId, String resultPostprocId)
Creates PDP engine configurationstatic oasis.names.tc.xacml._3_0.core.schema.wd_17.Response
normalizeForComparison(oasis.names.tc.xacml._3_0.core.schema.wd_17.Response response, boolean removeStatusMessage, boolean removeStatusDetail)
Normalize a XACML response for comparison with another normalized one, allowing to remove StatusMessage and/or StatusDetail if there is any.static String
printResponse(oasis.names.tc.xacml._3_0.core.schema.wd_17.Response response)
-
-
-
Method Detail
-
createRequest
public static oasis.names.tc.xacml._3_0.core.schema.wd_17.Request createRequest(Path requestFile, org.ow2.authzforce.core.pdp.api.XmlUtils.XmlnsFilteringParser unmarshaller) throws javax.xml.bind.JAXBException, IllegalArgumentException, MalformedURLException
This creates the XACML request from file on classpath- Parameters:
requestFile
- file path (with Spring-supported URL prefixes: 'classpath:', etc.) path to the request file, relative to classpathunmarshaller
- XACML unmarshaller- Returns:
- the XML/JAXB Request or null if any error
- Throws:
javax.xml.bind.JAXBException
- error reading XACML 3.0 Request from the file atrequestFileLocation
MalformedURLException
- requestFile could not be converted to a URLIllegalArgumentException
- requestFile is invalid
-
createResponse
public static oasis.names.tc.xacml._3_0.core.schema.wd_17.Response createResponse(Path responseFile, org.ow2.authzforce.core.pdp.api.XmlUtils.XmlnsFilteringParser unmarshaller) throws javax.xml.bind.JAXBException, IllegalArgumentException, MalformedURLException
This creates the XACML response from file on classpath- Parameters:
responseFile
- path to the response fileunmarshaller
- XACML unmarshaller- Returns:
- the XML/JAXB Response or null if any error
- Throws:
javax.xml.bind.JAXBException
- error reading XACML 3.0 Request from the file atresponseFileLocation
MalformedURLException
- requestFile could not be converted to a URLIllegalArgumentException
- invalid requestFile
-
printResponse
public static String printResponse(oasis.names.tc.xacml._3_0.core.schema.wd_17.Response response)
-
normalizeForComparison
public static oasis.names.tc.xacml._3_0.core.schema.wd_17.Response normalizeForComparison(oasis.names.tc.xacml._3_0.core.schema.wd_17.Response response, boolean removeStatusMessage, boolean removeStatusDetail)
Normalize a XACML response for comparison with another normalized one, allowing to remove StatusMessage and/or StatusDetail if there is any. Indeed, a PDP implementation might return a perfectly XACML-compliant response but with extra Status Message/Detail that we would not expect and of minor importance. Responses having any Result with nested StatusCode are not supported and will be rejected.- Parameters:
response
- input XACML Response without any nested StatusCode in results.removeStatusMessage
- remove the StatusMessage if there is anyremoveStatusDetail
- remove the StatusDetail if there is any- Returns:
- normalized response
-
getPolicyRef
public static TopLevelPolicyElementRef getPolicyRef(Path path) throws javax.xml.bind.JAXBException
Gets policy ref from XACML policy file- Parameters:
path
- path to XACML Policy(Set) file- Returns:
- Policy(Set)Id
- Throws:
javax.xml.bind.JAXBException
- unmarshalling error
-
newPdpEngineConfiguration
public static PdpEngineConfiguration newPdpEngineConfiguration(TopLevelPolicyElementRef rootPolicyRef, Path policiesDirectory, boolean enableXPath, Optional<Path> attributeProviderConfFile, String requestPreprocId, String resultPostprocId) throws IllegalArgumentException, IOException, javax.xml.bind.JAXBException
Creates PDP engine configuration- Parameters:
policiesDirectory
- directory containing files of XACML Policy(Set)s, including the root policy and other policies referred to from the root policyrootPolicyId
via Policy(Set)IdReference.rootPolicyRef
- ID (and optional version) of root XACML policy, to be located inpoliciesDirectory
enableXPath
- Enable support for AttributeSelectors and xpathExpression datatype. Reminder: AttributeSelector and xpathExpression datatype support are marked as optional in XACML 3.0 core specification, so set this to false if you are testing mandatory features only.attributeProviderConfFile
- (optional)TestAttributeProvider
XML configuration locationrequestPreprocId
- Request preprocessor IDresultPostprocId
- Result postprocessor ID- Returns:
- PDP instance
- Throws:
IllegalArgumentException
- invalid XACML policy located atrootPolicyLocation
orrefPoliciesDirectoryLocation
IOException
- if error closing some resources used by the PDP afterIllegalArgumentException
occurredjavax.xml.bind.JAXBException
- cannot create Attribute Provider configuration (XML) unmarshaller
-
newPdpEngineConfiguration
public static PdpEngineConfiguration newPdpEngineConfiguration(Path rootPolicyFile, boolean enableXPath, Optional<Path> attributeProviderConfFile, String requestPreprocId, String resultPostprocId) throws IllegalArgumentException, IOException, javax.xml.bind.JAXBException
Creates PDP engine configuration- Parameters:
rootPolicyFile
- ID of root XACML policy, to be located inpoliciesDirectoryLocation
(with Spring-supported URL prefixes: 'classpath:', etc.)enableXPath
- Enable support for AttributeSelectors and xpathExpression datatype. Reminder: AttributeSelector and xpathExpression datatype support are marked as optional in XACML 3.0 core specification, so set this to false if you are testing mandatory features only.attributeProviderConfFile
- (optional)TestAttributeProvider
XML configuration locationrequestPreprocId
- Request preprocessor IDresultPostprocId
- Result postprocessor ID- Returns:
- PDP instance
- Throws:
IllegalArgumentException
- invalid XACML policy located atrootPolicyLocation
orrefPoliciesDirectoryLocation
IOException
- if error closing some resources used by the PDP afterIllegalArgumentException
occurredjavax.xml.bind.JAXBException
- cannot create Attribute Provider configuration (XML) unmarshaller
-
assertNormalizedEquals
public static void assertNormalizedEquals(String testId, oasis.names.tc.xacml._3_0.core.schema.wd_17.Response expectedResponse, oasis.names.tc.xacml._3_0.core.schema.wd_17.Response actualResponseFromPDP, boolean ignoreStatusMessageAndDetail) throws javax.xml.bind.JAXBException
assertEquals() for XACML responses (handles normalization of the responses)- Parameters:
testId
- test identifierexpectedResponse
- expected responseactualResponseFromPDP
- actual response- Throws:
javax.xml.bind.JAXBException
- error creating JAXB Marshaller for XACML output
-
-