|
39 | 39 | import org.ow2.authzforce.core.xmlns.pdp.Pdp; |
40 | 40 | import org.ow2.authzforce.core.xmlns.pdp.StdEnvAttributeProviderDescriptor; |
41 | 41 | import org.ow2.authzforce.core.xmlns.pdp.TopLevelPolicyElementRef; |
| 42 | +import org.ow2.authzforce.xacml.Xacml3JaxbHelper; |
42 | 43 | import org.ow2.authzforce.xacml.identifiers.XacmlDatatypeId; |
43 | 44 | import org.ow2.authzforce.xmlns.pdp.ext.AbstractAttributeProvider; |
44 | 45 | import org.ow2.authzforce.xmlns.pdp.ext.AbstractDecisionCache; |
|
48 | 49 | import org.springframework.util.ResourceUtils; |
49 | 50 |
|
50 | 51 | import javax.xml.bind.JAXBException; |
| 52 | +import javax.xml.bind.Unmarshaller; |
51 | 53 | import javax.xml.transform.Source; |
52 | 54 | import javax.xml.transform.stream.StreamSource; |
53 | 55 | import java.io.Closeable; |
@@ -214,6 +216,21 @@ public void close() throws IOException |
214 | 216 |
|
215 | 217 | } |
216 | 218 |
|
| 219 | + private static final class XmlnsFilteringParserFactoryWithDefaultXmlnsContext implements XmlnsFilteringParserFactory { |
| 220 | + |
| 221 | + private final ImmutableMap<String, String> defaultXmlnsPrefixToUriMap; |
| 222 | + private XmlnsFilteringParserFactoryWithDefaultXmlnsContext(final Map<String, String> defaultXmlnsPrefixToUriMap) { |
| 223 | + this.defaultXmlnsPrefixToUriMap = ImmutableMap.copyOf(defaultXmlnsPrefixToUriMap); |
| 224 | + } |
| 225 | + |
| 226 | + @Override |
| 227 | + public XmlUtils.XmlnsFilteringParser getInstance() throws JAXBException |
| 228 | + { |
| 229 | + final Unmarshaller unmarshaller = Xacml3JaxbHelper.createXacml3Unmarshaller(); |
| 230 | + return new XmlUtils.SAXBasedXmlnsFilteringParser(unmarshaller, defaultXmlnsPrefixToUriMap); |
| 231 | + } |
| 232 | + } |
| 233 | + |
217 | 234 | private static final IllegalArgumentException ILLEGAL_ROOT_POLICY_REF_CONFIG_EXCEPTION = new IllegalArgumentException( |
218 | 235 | "Configuration parameter 'rootPolicyRef' is undefined and 'policyProvider' does not provide any candidate root policy. Please define 'rootPolicyRef' parameter or modify the Policy Provider to return a candidate root policy."); |
219 | 236 |
|
@@ -304,12 +321,13 @@ private static <JAXB_CONF extends AbstractDecisionCache> DecisionCache newDecisi |
304 | 321 | * (JAXB-bound) PDP configuration |
305 | 322 | * @param envProps |
306 | 323 | * PDP configuration environment properties (e.g. PARENT_DIR) |
| 324 | + * @param xpathNamespaceContexts XPath namespace prefix-to-URI mappings to be used for namespace-aware evaluation of XPath expressions, e.g. AttributeSelectors' Paths. Empty if none or if XPath support is disabled by configuration. |
307 | 325 | * @throws java.lang.IllegalArgumentException |
308 | 326 | * invalid PDP configuration |
309 | 327 | * @throws java.io.IOException |
310 | 328 | * if any error occurred closing already created {@link Closeable} modules (policy Providers, attribute Providers, decision cache) |
311 | 329 | */ |
312 | | - public PdpEngineConfiguration(final Pdp pdpJaxbConf, final EnvironmentProperties envProps) throws IllegalArgumentException, IOException |
| 330 | + public PdpEngineConfiguration(final Pdp pdpJaxbConf, final EnvironmentProperties envProps, final Map<String, String> xpathNamespaceContexts) throws IllegalArgumentException, IOException |
313 | 331 | { |
314 | 332 | /* |
315 | 333 | * Enable support for XPath expressions, XPath functions, etc. |
@@ -434,7 +452,7 @@ public PdpEngineConfiguration(final Pdp pdpJaxbConf, final EnvironmentProperties |
434 | 452 | /* |
435 | 453 | * XACML element (Policies, etc.) parser factory |
436 | 454 | */ |
437 | | - final XmlnsFilteringParserFactory xacmlParserFactory = XacmlJaxbParsingUtils.getXacmlParserFactory(enableXPath); |
| 455 | + final XmlnsFilteringParserFactory xacmlParserFactory = enableXPath && (xpathNamespaceContexts != null && !xpathNamespaceContexts.isEmpty())? new XmlnsFilteringParserFactoryWithDefaultXmlnsContext(xpathNamespaceContexts): XacmlJaxbParsingUtils.getXacmlParserFactory(enableXPath); |
438 | 456 |
|
439 | 457 | /* |
440 | 458 | * Strict Attribute Issuer match |
@@ -632,6 +650,23 @@ else if (mutableCombinedPolicyProvider instanceof CloseableStaticPolicyProvider |
632 | 650 |
|
633 | 651 | } |
634 | 652 |
|
| 653 | + /** |
| 654 | + * Constructs configuration from PDP XML-schema-derived JAXB model (usually 'unmarshaled' from XML configuration file) |
| 655 | + * |
| 656 | + * @param pdpJaxbConf |
| 657 | + * (JAXB-bound) PDP configuration |
| 658 | + * @param envProps |
| 659 | + * PDP configuration environment properties (e.g. PARENT_DIR) |
| 660 | + * @throws java.lang.IllegalArgumentException |
| 661 | + * invalid PDP configuration |
| 662 | + * @throws java.io.IOException |
| 663 | + * if any error occurred closing already created {@link Closeable} modules (policy Providers, attribute Providers, decision cache) |
| 664 | + */ |
| 665 | + public PdpEngineConfiguration(final Pdp pdpJaxbConf, final EnvironmentProperties envProps) throws IllegalArgumentException, IOException |
| 666 | + { |
| 667 | + this(pdpJaxbConf, envProps, Map.of()); |
| 668 | + } |
| 669 | + |
635 | 670 | private static PdpEngineConfiguration getInstance(final Source confXmlSrc, final PdpModelHandler modelHandler, final EnvironmentProperties envProps) throws IOException, IllegalArgumentException |
636 | 671 | { |
637 | 672 | assert confXmlSrc != null && modelHandler != null; |
|
0 commit comments