Class TestUtils


  • public class TestUtils
    extends Object
    • Field Detail

      • TEST_ATTRIBUTE_PROVIDER_JAXB_CONTEXT

        public static final javax.xml.bind.JAXBContext TEST_ATTRIBUTE_PROVIDER_JAXB_CONTEXT
        JAXB context for (un)marshalling TestAttributeProvider configuration
    • Constructor Detail

      • TestUtils

        public TestUtils()
    • 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 classpath
        unmarshaller - 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 at requestFileLocation
        MalformedURLException - requestFile could not be converted to a URL
        IllegalArgumentException - 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 file
        unmarshaller - 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 at responseFileLocation
        MalformedURLException - requestFile could not be converted to a URL
        IllegalArgumentException - 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 any
        removeStatusDetail - 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 policy rootPolicyId via Policy(Set)IdReference.
        rootPolicyRef - ID (and optional version) of root XACML policy, to be located in policiesDirectory
        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 location
        requestPreprocId - Request preprocessor ID
        resultPostprocId - Result postprocessor ID
        Returns:
        PDP instance
        Throws:
        IllegalArgumentException - invalid XACML policy located at rootPolicyLocation or refPoliciesDirectoryLocation
        IOException - if error closing some resources used by the PDP after IllegalArgumentException occurred
        javax.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 in policiesDirectoryLocation (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 location
        requestPreprocId - Request preprocessor ID
        resultPostprocId - Result postprocessor ID
        Returns:
        PDP instance
        Throws:
        IllegalArgumentException - invalid XACML policy located at rootPolicyLocation or refPoliciesDirectoryLocation
        IOException - if error closing some resources used by the PDP after IllegalArgumentException occurred
        javax.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 identifier
        expectedResponse - expected response
        actualResponseFromPDP - actual response
        Throws:
        javax.xml.bind.JAXBException - error creating JAXB Marshaller for XACML output