Properties can start with ENV 45/75945/1
authorPopescu, Serban <serban.popescu@amdocs.com>
Thu, 17 Jan 2019 18:16:09 +0000 (13:16 -0500)
committerSerban Popescu <serban.popescu@amdocs.com>
Thu, 17 Jan 2019 18:19:38 +0000 (13:19 -0500)
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 <serban.popescu@amdocs.com>
sparkybe-onap-application/src/main/java/org/onap/aai/sparky/config/PropertyPasswordConfiguration.java

index b554375..3424454 100644 (file)
@@ -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<ConfigurableApplicationContext> {
+        implements ApplicationContextInitializer<ConfigurableApplicationContext> {
 
   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);
           }
         }
       }