============LICENSE_START=======================================================
ONAP Policy Engine - Drools PDP
================================================================================
- Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ Copyright (C) 2017, 2019 AT&T Intellectual Property. All rights reserved.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
============LICENSE_END=========================================================
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
- <artifactId>policy-utils</artifactId>
+ <artifactId>policy-utils</artifactId>
- <parent>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>drools-pdp</artifactId>
- <version>1.4.0-SNAPSHOT</version>
- </parent>
+ <parent>
+ <groupId>org.onap.policy.drools-pdp</groupId>
+ <artifactId>drools-pdp</artifactId>
+ <version>1.4.0-SNAPSHOT</version>
+ </parent>
- <dependencies>
+ <dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
- </dependency>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.onap.policy.common</groupId>
<artifactId>utils</artifactId>
<version>${policy.common.version}</version>
- </dependency>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-configuration2</artifactId>
+ <version>2.4</version>
+ </dependency>
</dependencies>
<build>
<plugins>
* ============LICENSE_START=======================================================
* policy-utils
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import java.util.Timer;
import java.util.TimerTask;
+import org.apache.commons.configuration2.ConfigurationConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger logger = LoggerFactory.getLogger(PropertyUtil.class.getName());
/**
- * Read in a properties file.
- *
+ * Read in a properties file. Variable interpolation is performed by using
+ * apache commons configuration2 library. This allows for embedding system properties,
+ * constants, and environment variables in property files.
+ *
* @param file the properties file
* @return a Properties object, containing the associated properties
* @throws IOException - subclass 'FileNotFoundException' if the file
*/
public static Properties getProperties(File file) throws IOException {
// create an InputStream (may throw a FileNotFoundException)
+ Properties rval = new Properties();
try (FileInputStream fis = new FileInputStream(file)) {
// create the properties instance
- Properties rval = new Properties();
// load properties (may throw an IOException)
rval.load(fis);
- return rval;
}
+
+ /*
+ * Return properties file with environment variables interpolated.
+ * It is necessary to construct the object in this fashion and avoid
+ * builders since they use the commons-beanutils (optional) library that has been
+ * flagged as insecured.
+ */
+ return ConfigurationConverter.getProperties(ConfigurationConverter.getConfiguration(rval));
}
/**
* ============LICENSE_START=======================================================
* policy-utils
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.onap.policy.drools.utils.logging.LoggerUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class PropertyUtilTest {
+
private static final Logger logger = LoggerFactory.getLogger(PropertyUtilTest.class);
+ private static final String INTERPOLATION_PROPERTIES = "src/test/resources/interpolation.properties";
+ private static final String INTERPOLATION_NO = "interpolation.no";
+ private static final String INTERPOLATION_ENV = "interpolation.env";
+ private static final String INTERPOLATION_CONST = "interpolation.const";
+ private static final String INTERPOLATION_SYS = "interpolation.sys";
private static File directory = null;
// they should match
assertEquals(prop1, prop2);
+
+ Properties prop3 = PropertyUtil.getProperties(INTERPOLATION_PROPERTIES);
+ assertEquals("no", prop3.getProperty(INTERPOLATION_NO));
+ assertEquals(System.getenv("HOME"), prop3.getProperty(INTERPOLATION_ENV));
+ assertEquals(LoggerUtil.ROOT_LOGGER, prop3.getProperty(INTERPOLATION_CONST));
+ assertEquals(System.getProperty("user.home"), prop3.getProperty(INTERPOLATION_SYS));
}
/**
--- /dev/null
+interpolation.no=no
+interpolation.env=${env:HOME}
+interpolation.const=${const:org.onap.policy.drools.utils.logging.LoggerUtil.ROOT_LOGGER}
+interpolation.sys=${sys:user.home}