From 9898634b32ce6bd4d468f399bcc4899054e5ace8 Mon Sep 17 00:00:00 2001 From: "Popescu, Serban" Date: Thu, 17 Jan 2019 13:16:09 -0500 Subject: [PATCH] Properties can start with ENV If an application property value starts with ENV: that value should be inferred from the Java property with the same name after the prefix ENV: is removed Change-Id: I3f05972747e83010dfdaeb08bb65a472dcf1637e Issue-ID: AAI-2089 Signed-off-by: Serban Popescu --- .../onap/aai/sparky/config/PropertyPasswordConfiguration.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sparkybe-onap-application/src/main/java/org/onap/aai/sparky/config/PropertyPasswordConfiguration.java b/sparkybe-onap-application/src/main/java/org/onap/aai/sparky/config/PropertyPasswordConfiguration.java index b554375..3424454 100644 --- a/sparkybe-onap-application/src/main/java/org/onap/aai/sparky/config/PropertyPasswordConfiguration.java +++ b/sparkybe-onap-application/src/main/java/org/onap/aai/sparky/config/PropertyPasswordConfiguration.java @@ -3,6 +3,7 @@ package org.onap.aai.sparky.config; import java.util.LinkedHashMap; import java.util.Map; +import org.apache.commons.lang.StringUtils; import org.eclipse.jetty.util.security.Password; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ConfigurableApplicationContext; @@ -12,9 +13,10 @@ import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.PropertySource; public class PropertyPasswordConfiguration - implements ApplicationContextInitializer { + implements ApplicationContextInitializer { private static final String JETTY_OBFUSCATION_PATTERN = "OBF:"; + private static final String ENV = "ENV:"; @Override public void initialize(ConfigurableApplicationContext applicationContext) { @@ -24,7 +26,7 @@ public class PropertyPasswordConfiguration decodePasswords(propertySource, propertyOverrides); if (!propertyOverrides.isEmpty()) { PropertySource decodedProperties = - new MapPropertySource("decoded " + propertySource.getName(), propertyOverrides); + new MapPropertySource("decoded " + propertySource.getName(), propertyOverrides); environment.getPropertySources().addBefore(propertySource.getName(), decodedProperties); } } @@ -41,6 +43,9 @@ public class PropertyPasswordConfiguration if (rawValueString.startsWith(JETTY_OBFUSCATION_PATTERN)) { String decodedValue = Password.deobfuscate(rawValueString); propertyOverrides.put(key, decodedValue); + } else if(rawValueString.startsWith(ENV)){ + String decodedValue = System.getProperty(StringUtils.removeStart(rawValueString, ENV)); + propertyOverrides.put(key, decodedValue); } } } -- 2.16.6