Search in sources :

Example 6 with PdpEngineConfiguration

use of org.ow2.authzforce.core.pdp.impl.PdpEngineConfiguration in project core by authzforce.

the class TestUtils method newPdpEngineConfiguration.

private static PdpEngineConfiguration newPdpEngineConfiguration(final TopLevelPolicyElementRef rootPolicyRef, final List<String> policyLocations, final boolean enableXPath, final Optional<Path> attributeProviderConfFile, final String requestPreprocId, final String resultPostprocId) throws JAXBException, IllegalArgumentException, IOException {
    Preconditions.checkNotNull(rootPolicyRef, "Root policy reference (ID, version) undefined");
    Preconditions.checkNotNull(policyLocations, "Policy location(s) undefined");
    final StaticPolicyProvider jaxbPolicyProvider = new StaticPolicyProvider(new ArrayList<>(policyLocations), true);
    jaxbPolicyProvider.setId("policyProvider");
    final List<AbstractPolicyProvider> policyProviders = Collections.singletonList(jaxbPolicyProvider);
    // test attribute provider
    final List<AbstractAttributeProvider> attProviders;
    if (attributeProviderConfFile.isPresent()) {
        final Unmarshaller unmarshaller = TEST_ATTRIBUTE_PROVIDER_JAXB_CONTEXT.createUnmarshaller();
        @SuppressWarnings("unchecked") final JAXBElement<TestAttributeProviderDescriptor> testAttributeProviderElt = (JAXBElement<TestAttributeProviderDescriptor>) unmarshaller.unmarshal(attributeProviderConfFile.get().toFile());
        attProviders = Collections.singletonList(testAttributeProviderElt.getValue());
    } else {
        attProviders = Collections.emptyList();
    }
    final List<InOutProcChain> ioProcChains;
    if (requestPreprocId != null) {
        final InOutProcChain ioProcChain = new InOutProcChain(requestPreprocId, resultPostprocId);
        ioProcChains = Collections.singletonList(ioProcChain);
    } else {
        ioProcChains = Collections.emptyList();
    }
    // set max PolicySet reference depth to max possible depth automatically
    final Pdp jaxbPDP = new Pdp(null, null, null, attProviders, policyProviders, rootPolicyRef, null, ioProcChains, "8.0", true, true, true, true, enableXPath, false, null, null, BigInteger.valueOf(jaxbPolicyProvider.getPolicySetsAndPolicyLocations().size()), null);
    return new PdpEngineConfiguration(jaxbPDP, new DefaultEnvironmentProperties());
}
Also used : PdpEngineConfiguration(org.ow2.authzforce.core.pdp.impl.PdpEngineConfiguration) DefaultEnvironmentProperties(org.ow2.authzforce.core.pdp.impl.DefaultEnvironmentProperties) StaticPolicyProvider(org.ow2.authzforce.core.xmlns.pdp.StaticPolicyProvider) AbstractPolicyProvider(org.ow2.authzforce.xmlns.pdp.ext.AbstractPolicyProvider) TestAttributeProviderDescriptor(org.ow2.authzforce.core.pdp.testutil.ext.xmlns.TestAttributeProviderDescriptor) AbstractAttributeProvider(org.ow2.authzforce.xmlns.pdp.ext.AbstractAttributeProvider) InOutProcChain(org.ow2.authzforce.core.xmlns.pdp.InOutProcChain) Pdp(org.ow2.authzforce.core.xmlns.pdp.Pdp)

Example 7 with PdpEngineConfiguration

use of org.ow2.authzforce.core.pdp.impl.PdpEngineConfiguration in project core by authzforce.

the class PdpCommandLineCallable method call.

@Override
public Void call() throws Exception {
    final PdpEngineConfiguration configuration = PdpEngineConfiguration.getInstance(confFile, catalogLocation, extensionXsdLocation);
    switch(requestType) {
        case XACML_JSON:
            final JSONObject jsonRequest;
            try (InputStream inputStream = new FileInputStream(reqFile)) {
                jsonRequest = new JSONObject(new JSONTokener(inputStream));
                if (!jsonRequest.has("Request")) {
                    throw new IllegalArgumentException("Invalid XACML JSON Request file: " + reqFile + ". Expected root key: \"Request\"");
                }
                XacmlJsonUtils.REQUEST_SCHEMA.validate(jsonRequest);
            }
            final DecisionResultPostprocessor<IndividualXacmlJsonRequest, JSONObject> defaultResultPostproc = new BaseXacmlJsonResultPostprocessor(configuration.getClientRequestErrorVerbosityLevel());
            final DecisionRequestPreprocessor<JSONObject, IndividualXacmlJsonRequest> defaultReqPreproc = SingleDecisionXacmlJsonRequestPreprocessor.LaxVariantFactory.INSTANCE.getInstance(configuration.getAttributeValueFactoryRegistry(), configuration.isStrictAttributeIssuerMatchEnabled(), configuration.isXPathEnabled(), defaultResultPostproc.getFeatures());
            final PdpEngineInoutAdapter<JSONObject, JSONObject> jsonPdpEngineAdapter = PdpEngineAdapters.newInoutAdapter(JSONObject.class, JSONObject.class, configuration, defaultReqPreproc, defaultResultPostproc);
            final JSONObject jsonResponse = jsonPdpEngineAdapter.evaluate(jsonRequest);
            System.out.println(jsonResponse.toString(formattedOutput ? 4 : 0));
            break;
        default:
            final XmlnsFilteringParser parser = XacmlJaxbParsingUtils.getXacmlParserFactory(true).getInstance();
            final Object request = parser.parse(reqFile.toURI().toURL());
            if (!(request instanceof Request)) {
                throw new IllegalArgumentException("Invalid XACML/XML Request file (according to XACML 3.0 schema): " + reqFile);
            }
            final PdpEngineInoutAdapter<Request, Response> xmlPdpEngineAdapter = PdpEngineAdapters.newXacmlJaxbInoutAdapter(configuration);
            final Response xmlResponse = xmlPdpEngineAdapter.evaluate((Request) request, parser.getNamespacePrefixUriMap());
            final Marshaller marshaller = Xacml3JaxbHelper.createXacml3Marshaller();
            final Boolean formatted = formattedOutput;
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, formatted);
            marshaller.marshal(xmlResponse, System.out);
            break;
    }
    return null;
}
Also used : XmlnsFilteringParser(org.ow2.authzforce.core.pdp.api.XmlUtils.XmlnsFilteringParser) PdpEngineConfiguration(org.ow2.authzforce.core.pdp.impl.PdpEngineConfiguration) Marshaller(javax.xml.bind.Marshaller) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IndividualXacmlJsonRequest(org.ow2.authzforce.core.pdp.io.xacml.json.IndividualXacmlJsonRequest) Request(oasis.names.tc.xacml._3_0.core.schema.wd_17.Request) IndividualXacmlJsonRequest(org.ow2.authzforce.core.pdp.io.xacml.json.IndividualXacmlJsonRequest) FileInputStream(java.io.FileInputStream) JSONTokener(org.json.JSONTokener) Response(oasis.names.tc.xacml._3_0.core.schema.wd_17.Response) JSONObject(org.json.JSONObject) BaseXacmlJsonResultPostprocessor(org.ow2.authzforce.core.pdp.io.xacml.json.BaseXacmlJsonResultPostprocessor) JSONObject(org.json.JSONObject)

Aggregations

PdpEngineConfiguration (org.ow2.authzforce.core.pdp.impl.PdpEngineConfiguration)7 Request (oasis.names.tc.xacml._3_0.core.schema.wd_17.Request)4 Response (oasis.names.tc.xacml._3_0.core.schema.wd_17.Response)4 Path (java.nio.file.Path)3 Test (org.junit.Test)3 XmlnsFilteringParser (org.ow2.authzforce.core.pdp.api.XmlUtils.XmlnsFilteringParser)3 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 JSONObject (org.json.JSONObject)2 JSONTokener (org.json.JSONTokener)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 JAXBException (javax.xml.bind.JAXBException)1 Marshaller (javax.xml.bind.Marshaller)1 LoggingFeature (org.apache.cxf.ext.logging.LoggingFeature)1 JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)1 SingletonResourceProvider (org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)1 ValidationException (org.everit.json.schema.ValidationException)1 PrimaryPolicyMetadata (org.ow2.authzforce.core.pdp.api.policy.PrimaryPolicyMetadata)1