Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import org.ow2.authzforce.xacml.Xacml3JaxbHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.ResourceUtils;
import org.ow2.authzforce.core.pdp.impl.ResourceLocationResolver;
import org.wso2.balana.ConfigurationStore;
import org.wso2.balana.PDP;
import org.wso2.balana.PDPConfig;
Expand Down Expand Up @@ -358,7 +358,7 @@ public static Collection<Object[]> params() throws URISyntaxException, IOExcepti
/*
* Each sub-directory of the root directory is data for a specific test. So we configure a test for each directory
*/
final URL testRootDir = ResourceUtils.getURL(TEST_RESOURCES_ROOT_DIRECTORY_LOCATION);
final URL testRootDir = ResourceLocationResolver.getUrl(TEST_RESOURCES_ROOT_DIRECTORY_LOCATION);
final Path testRootPath = Paths.get(testRootDir.toURI());

final PdpEngineInvoker authzforcePdpEngineInvoker = new AuthzForcePdpEngineInvoker(testRootPath.resolve(AUTHZFORCE_CE_PDP_CONF_DIRNAME));
Expand Down
10 changes: 0 additions & 10 deletions pdp-engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,10 @@
<!-- distributionManagement defined in parent POM already -->
<dependencies>
<!-- Third-party dependencies -->
<dependency>
<!-- For redirecting Spring logs to slf4j -->
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.angus</groupId>
<artifactId>jakarta.mail</artifactId>
</dependency>
<dependency>
<!-- Needed for org.springframework.util.ResourceUtils,SystemPropertyUtils,FileCopyUtils, etc. -->
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<!-- For loading XML schemas with OASIS catalog (CatalogManager) -->
<groupId>xml-resolver</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import org.ow2.authzforce.core.pdp.api.EnvironmentProperties;
import org.ow2.authzforce.core.pdp.api.EnvironmentPropertyName;
import org.springframework.util.PropertyPlaceholderHelper;

import java.util.Map;
import java.util.Map.Entry;
Expand All @@ -33,16 +32,11 @@
public final class DefaultEnvironmentProperties implements EnvironmentProperties
{

private static final String PROPERTY_PLACEHOLDER_PREFIX = "${";
private static final String PROPERTY_PLACEHOLDER_SUFFIX = "}";
/*
* We cannot use ':' as default value separator because not valid in XML anyURI
*/
private static final String PROPERTY_PLACEHOLDER_DEFAULT_VALUE_SEPARATOR = "!";

private static final PropertyPlaceholderHelper PROPERTY_PLACEHOLDER_HELPER = new PropertyPlaceholderHelper(PROPERTY_PLACEHOLDER_PREFIX, PROPERTY_PLACEHOLDER_SUFFIX,
PROPERTY_PLACEHOLDER_DEFAULT_VALUE_SEPARATOR, null, false);

private final Properties props = new Properties();

/**
Expand Down Expand Up @@ -85,7 +79,7 @@ public String replacePlaceholders(final String input)
return null;
}

return PROPERTY_PLACEHOLDER_HELPER.replacePlaceholders(input, placeholderName -> {
return PlaceholderResolver.replace(input, PROPERTY_PLACEHOLDER_DEFAULT_VALUE_SEPARATOR, placeholderName -> {

final String userDefinedPropVal = props.getProperty(placeholderName);
if (userDefinedPropVal != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.ow2.authzforce.core.pdp.api.policy.PrimaryPolicyMetadata;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.SystemPropertyUtils;

import java.io.IOException;
import java.util.Collection;
Expand Down Expand Up @@ -56,44 +55,44 @@ public final class PdpBean implements PdpEngine
* Configuration file. Only the 'defaultPDP' configuration will be loaded, i.e. 'pdp' element with 'name' matching the 'defaultPDP' attribute of the root 'config' element
*
* @param filePath
* configuration file path used as argument to {@link org.springframework.core.io.DefaultResourceLoader#getResource(String)} to resolve the resource; any placeholder ${...} in the path
* configuration file path (classpath resource, URL or file-system path); any placeholder ${...} in the path
* will be replaced with the corresponding system property value
* @throws java.lang.IllegalArgumentException
* if there is an unresolvable placeholder in {@code filePath}
*/
public void setConfigFile(final String filePath) throws IllegalArgumentException
{
confLocation = SystemPropertyUtils.resolvePlaceholders(filePath);
confLocation = resolveSystemPropertyPlaceholders(filePath);
init();
}

/**
* Configuration schema file. Used only for validating XML configurations (enclosed with 'xml' tag) of PDP extension modules in PDP configuration file set with {@link #setConfigFile(String)}
*
* @param filePath
* configuration file path used as argument to {@link org.springframework.core.io.DefaultResourceLoader#getResource(String)} to resolve the resource; any placeholder ${...} in the path
* configuration schema path (classpath resource, URL or file-system path); any placeholder ${...} in the path
* will be replaced with the corresponding system property value
* @throws java.lang.IllegalArgumentException
* if there is an unresolvable placeholder in {@code filePath}
*/
public void setSchemaFile(final String filePath) throws IllegalArgumentException
{
extSchemaLocation = SystemPropertyUtils.resolvePlaceholders(filePath);
extSchemaLocation = resolveSystemPropertyPlaceholders(filePath);
init();
}

/**
* Set XML catalog for resolving XML entities used in XML schema
*
* @param filePath
* configuration file path used as argument to {@link org.springframework.core.io.DefaultResourceLoader#getResource(String)} to resolve the resource; any placeholder ${...} in the path
* XML catalog path (classpath resource, URL or file-system path); any placeholder ${...} in the path
* will be replaced with the corresponding system property value
* @throws java.lang.IllegalArgumentException
* if there is an unresolvable placeholder in {@code filePath}
*/
public void setCatalogFile(final String filePath) throws IllegalArgumentException
{
catalogLocation = SystemPropertyUtils.resolvePlaceholders(filePath);
catalogLocation = resolveSystemPropertyPlaceholders(filePath);
init();
}

Expand All @@ -117,6 +116,14 @@ private void init()

}

private static String resolveSystemPropertyPlaceholders(final String value)
{
return PlaceholderResolver.replace(value, ":", placeholderName -> {
final String systemProperty = System.getProperty(placeholderName);
return systemProperty == null ? System.getenv(placeholderName) : systemProperty;
});
}

@Override
public DecisionRequestBuilder<?> newRequestBuilder(final int expectedNumOfAttributeCategories, final int expectedTotalNumOfAttributes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.ow2.authzforce.xmlns.pdp.ext.AbstractPolicyProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.ResourceUtils;

import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
Expand Down Expand Up @@ -274,7 +273,7 @@
private static <JAXB_CONF extends AbstractAttributeProvider> CloseableNamedAttributeProvider.DependencyAwareFactory newAttributeProviderProviderFactory(final JAXB_CONF jaxbConf,
final EnvironmentProperties envProps)
{
final CloseableNamedAttributeProvider.FactoryBuilder<JAXB_CONF> attrProviderModBuilder = PdpExtensions.getAttributeProviderFactoryBuilder((Class<JAXB_CONF>) jaxbConf.getClass());

Check warning on line 276 in pdp-engine/src/main/java/org/ow2/authzforce/core/pdp/impl/PdpEngineConfiguration.java

View workflow job for this annotation

GitHub Actions / build

unchecked cast
return attrProviderModBuilder.getInstance(jaxbConf, envProps);
}

Expand All @@ -282,14 +281,14 @@
final int maxPolicySetRefDepth, final ExpressionFactory xacmlExprFactory, final CombiningAlgRegistry combiningAlgRegistry, final EnvironmentProperties envProps,
final Optional<PolicyProvider<?>> otherHelpingPolicyProvider)
{
final CloseablePolicyProvider.Factory<JAXB_CONF> refPolicyProviderModFactory = PdpExtensions.getPolicyProviderFactory((Class<JAXB_CONF>) jaxbConf.getClass());

Check warning on line 284 in pdp-engine/src/main/java/org/ow2/authzforce/core/pdp/impl/PdpEngineConfiguration.java

View workflow job for this annotation

GitHub Actions / build

unchecked cast
return refPolicyProviderModFactory.getInstance(jaxbConf, xacmlParserFactory, maxPolicySetRefDepth, xacmlExprFactory, combiningAlgRegistry, envProps, otherHelpingPolicyProvider);
}

private static <JAXB_CONF extends AbstractDecisionCache> DecisionCache newDecisionCache(final JAXB_CONF jaxbConf, final AttributeValueFactoryRegistry attValFactories,
final EnvironmentProperties envProps)
{
final DecisionCache.Factory<JAXB_CONF> decisionCacheFactory = PdpExtensions.getDecisionCacheFactory((Class<JAXB_CONF>) jaxbConf.getClass());

Check warning on line 291 in pdp-engine/src/main/java/org/ow2/authzforce/core/pdp/impl/PdpEngineConfiguration.java

View workflow job for this annotation

GitHub Actions / build

unchecked cast
return decisionCacheFactory.getInstance(jaxbConf, attValFactories, envProps);
}

Expand Down Expand Up @@ -434,7 +433,7 @@
final AttributeValueFactory<?> intValFactory = attValFactoryRegistry.getExtension(StandardDatatypes.INTEGER.getId());
assert intValFactory != null && intValFactory.getDatatype() == StandardDatatypes.INTEGER && intValFactory instanceof StringParseableValue.Factory;

final FunctionRegistry stdRegistry = StandardFunction.getRegistry(enableXPath, (StringParseableValue.Factory<IntegerValue>) intValFactory);

Check warning on line 436 in pdp-engine/src/main/java/org/ow2/authzforce/core/pdp/impl/PdpEngineConfiguration.java

View workflow job for this annotation

GitHub Actions / build

unchecked cast
if (nonGenericFunctionExtensionIdentifiers.isEmpty())
{
functionRegistry = stdRegistry;
Expand Down Expand Up @@ -748,8 +747,7 @@
}

/**
* Create PDP instance. Locations here can be any resource string supported by Spring ResourceLoader. More info: <a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/html">Spring documentation</a>
* /resources.html.
* Create PDP instance. Locations may be classpath resources, URLs or file-system paths.
* <p>
* To allow using file paths relative to the parent folder of the configuration file (located at confLocation) anywhere in this configuration file (including in PDP extensions'), we define a
* property 'PARENT_DIR', so that the placeholder ${PARENT_DIR} can be used as prefix for file paths in the configuration file. E.g. if confLocation = 'file:///path/to/configurationfile', then
Expand All @@ -775,7 +773,7 @@

try
{
final File confFile = ResourceUtils.getFile(confLocation);
final File confFile = ResourceLocationResolver.getFile(confLocation);
return getInstance(confFile, modelHandler);
}
catch (final FileNotFoundException e)
Expand All @@ -794,7 +792,7 @@
final URL confUrl;
try
{
confUrl = ResourceUtils.getURL(confLocation);
confUrl = ResourceLocationResolver.getUrl(confLocation);
}
catch (final FileNotFoundException e)
{
Expand All @@ -811,8 +809,7 @@

/**
* <p>
* Create PDP instance. Locations here can be any resource string supported by Spring ResourceLoader. More info: <a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/html">Spring documentation</a>
* /resources.html
* Create PDP instance. Locations may be classpath resources, URLs or file-system paths.
*</p>
* <p>
* For example: <code>classpath:com/myapp/aaa.xsd</code>, <code>file:///data/bbb.xsd</code>, <code>http://myserver/ccc.xsd</code>...
Expand Down Expand Up @@ -867,8 +864,7 @@

/**
* <p>
* Create PDP instance. Locations here may be any resource string supported by Spring ResourceLoader. More info: <a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/html">Spring documentation</a>
* /resources.html
* Create PDP instance. Locations may be classpath resources, URLs or file-system paths.
*</p>
* <p>
* For example: <code>classpath:com/myapp/aaa.xsd</code>, <code>file:///data/bbb.xsd</code>, <code>http://myserver/ccc.xsd</code>...
Expand Down Expand Up @@ -923,8 +919,8 @@
* Create PDP instance.
*
* @param confLocation
* location of PDP configuration XML file, compliant with the PDP XML schema (pdp.xsd). This location may be any resource string supported by Spring ResourceLoader. For example:
* <code>classpath:com/myapp/aaa.xsd</code>, <code>file:///data/bbb.xsd</code>, <code>http://myserver/ccc.xsd</code>... More info: <a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/html/resources.html">Spring documentation</a>
* location of PDP configuration XML file, compliant with the PDP XML schema (pdp.xsd). It may be a classpath resource, URL or file-system path. For example:
* <code>classpath:com/myapp/aaa.xsd</code>, <code>file:///data/bbb.xsd</code>, <code>http://myserver/ccc.xsd</code>.
* @return PDP instance
* @throws IOException
* I/O error reading from {@code confLocation}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ public final class PdpModelHandler
private final JAXBContext confJaxbCtx;

/**
* Load Configuration model handler. Parameters here are locations to XSD files. Locations can be any resource string supported by Spring ResourceLoader.
* <a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/html/resources.html">More info</a>.
* Load Configuration model handler. Parameters here are locations to XSD files. Locations may be classpath resources, URLs or file-system paths.
* <p>
* For example: <code>classpath:com/myapp/aaa.xsd</code>, <code>file:///data/bbb.xsd</code>, <code>http://myserver/ccc.xsd</code>...
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Copyright 2012-2026 THALES.
*
* This file is part of AuthzForce CE.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.ow2.authzforce.core.pdp.impl;

import java.util.HashSet;
import java.util.Set;
import java.util.function.Function;

/** Internal placeholder expansion support. */
final class PlaceholderResolver
{
private static final String PREFIX = "${";
private static final char SUFFIX = '}';

private PlaceholderResolver()
{
// Utility class.
}

static String replace(final String input, final String defaultValueSeparator, final Function<String, String> valueResolver)
{
return replace(input, defaultValueSeparator, valueResolver, new HashSet<>());
}

private static String replace(final String input, final String defaultValueSeparator, final Function<String, String> valueResolver, final Set<String> activePlaceholders)
{
final StringBuilder output = new StringBuilder(input);
int startIndex = output.indexOf(PREFIX);
while (startIndex >= 0)
{
final int endIndex = findEndIndex(output, startIndex + PREFIX.length());
if (endIndex < 0)
{
break;
}

final String originalPlaceholder = output.substring(startIndex + PREFIX.length(), endIndex);
if (!activePlaceholders.add(originalPlaceholder))
{
throw new IllegalArgumentException("Circular placeholder reference '" + originalPlaceholder + "'");
}

final String placeholder = replace(originalPlaceholder, defaultValueSeparator, valueResolver, activePlaceholders);
String value = valueResolver.apply(placeholder);
if (value == null && defaultValueSeparator != null)
{
final int separatorIndex = placeholder.indexOf(defaultValueSeparator);
if (separatorIndex >= 0)
{
value = valueResolver.apply(placeholder.substring(0, separatorIndex));
if (value == null)
{
value = placeholder.substring(separatorIndex + defaultValueSeparator.length());
}
}
}

if (value == null)
{
throw new IllegalArgumentException("Could not resolve placeholder '" + placeholder + "'");
}

value = replace(value, defaultValueSeparator, valueResolver, activePlaceholders);
output.replace(startIndex, endIndex + 1, value);
activePlaceholders.remove(originalPlaceholder);
startIndex = output.indexOf(PREFIX, startIndex + value.length());
}

return output.toString();
}

private static int findEndIndex(final CharSequence input, final int contentStartIndex)
{
int nested = 0;
for (int index = contentStartIndex; index < input.length(); index++)
{
if (index + 1 < input.length() && input.charAt(index) == '$' && input.charAt(index + 1) == '{')
{
nested++;
index++;
}
else if (input.charAt(index) == SUFFIX)
{
if (nested == 0)
{
return index;
}
nested--;
}
}
return -1;
}
}
Loading
Loading