From 263cbf2331685a999819f7215b660fe70eac07d8 Mon Sep 17 00:00:00 2001 From: Carl Harris Date: Thu, 14 Dec 2017 06:14:15 -0500 Subject: [PATCH] GUACAMOLE-464: configuration properties from OS environment --- .../environment/LocalEnvironment.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/environment/LocalEnvironment.java b/guacamole-ext/src/main/java/org/apache/guacamole/environment/LocalEnvironment.java index f45bcaa1a..2d8b0cfd4 100644 --- a/guacamole-ext/src/main/java/org/apache/guacamole/environment/LocalEnvironment.java +++ b/guacamole-ext/src/main/java/org/apache/guacamole/environment/LocalEnvironment.java @@ -304,9 +304,41 @@ public class LocalEnvironment implements Environment { return guacHome; } + /** + * Gets the string value for a property name. + * + * The value may come from either the OS environment or the Properties + * collection that was loaded from guacamole.properties. When checking the + * environment for the named property, the name is first transformed by + * converting all hyphens to underscores and converting the string to + * upper case letter, in accordance with common convention for environment + * strings. + * + * @param name + * The name of the property value to retrieve. + * + * @return + * The corresponding value for the property. If the value is found in + * the OS environment, any corresponding value from the Properties + * collection containing properties from guacamole.properties is + * ignored. + */ + private String getPropertyValue(String name) { + + // transform the name according to common convention + final String envName = name.replace('-', '_').toUpperCase(); + final String envValue = System.getenv(envName); + + if (envValue != null) { + return envValue; + } + + return properties.getProperty(name); + } + @Override public Type getProperty(GuacamoleProperty property) throws GuacamoleException { - return property.parseValue(properties.getProperty(property.getName())); + return property.parseValue(getPropertyValue(property.getName())); } @Override