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());
}
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;
}
Aggregations