mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
GUACAMOLE-464: explicitly enable property overrides from environment
This commit is contained in:
@@ -27,6 +27,8 @@ import java.io.InputStream;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.apache.guacamole.properties.BooleanGuacamoleProperty;
|
||||||
import org.codehaus.jackson.map.ObjectMapper;
|
import org.codehaus.jackson.map.ObjectMapper;
|
||||||
import org.apache.guacamole.GuacamoleException;
|
import org.apache.guacamole.GuacamoleException;
|
||||||
import org.apache.guacamole.GuacamoleServerException;
|
import org.apache.guacamole.GuacamoleServerException;
|
||||||
@@ -72,6 +74,18 @@ public class LocalEnvironment implements Environment {
|
|||||||
*/
|
*/
|
||||||
private static final boolean DEFAULT_GUACD_SSL = false;
|
private static final boolean DEFAULT_GUACD_SSL = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A property that determines whether environment variables are evaluated
|
||||||
|
* to override properties specified in guacamole.properties.
|
||||||
|
*/
|
||||||
|
private static final BooleanGuacamoleProperty ENVIRONMENT_PROPERTY_OVERRIDE =
|
||||||
|
new BooleanGuacamoleProperty() {
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "enable-environment-overrides";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All properties read from guacamole.properties.
|
* All properties read from guacamole.properties.
|
||||||
*/
|
*/
|
||||||
@@ -87,6 +101,11 @@ public class LocalEnvironment implements Environment {
|
|||||||
*/
|
*/
|
||||||
private final Map<String, ProtocolInfo> availableProtocols;
|
private final Map<String, ProtocolInfo> availableProtocols;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flag indicating whether environment variables can override properties.
|
||||||
|
*/
|
||||||
|
private final boolean environmentPropertyOverride;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Jackson parser for parsing JSON files.
|
* The Jackson parser for parsing JSON files.
|
||||||
*/
|
*/
|
||||||
@@ -141,6 +160,8 @@ public class LocalEnvironment implements Environment {
|
|||||||
// Read all protocols
|
// Read all protocols
|
||||||
availableProtocols = readProtocols();
|
availableProtocols = readProtocols();
|
||||||
|
|
||||||
|
// Should environment variables override configuration properties?
|
||||||
|
environmentPropertyOverride = propertyOverrideEnabled(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -299,6 +320,30 @@ public class LocalEnvironment implements Environment {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks for the presence of the {@link #ENVIRONMENT_PROPERTY_OVERRIDE}
|
||||||
|
* property in the given properties collection.
|
||||||
|
*
|
||||||
|
* @param properties
|
||||||
|
* The properties collection to check.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* true if the property is present in the given properties collection
|
||||||
|
* and its parsed value is true
|
||||||
|
*
|
||||||
|
* @throws GuacamoleException If the value specified for the property
|
||||||
|
* cannot be successfully parsed as a Boolean
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static boolean propertyOverrideEnabled(Properties properties)
|
||||||
|
throws GuacamoleException {
|
||||||
|
|
||||||
|
final Boolean enableOverrides = ENVIRONMENT_PROPERTY_OVERRIDE.parseValue(
|
||||||
|
properties.getProperty(ENVIRONMENT_PROPERTY_OVERRIDE.getName()));
|
||||||
|
|
||||||
|
return enableOverrides != null && enableOverrides;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getGuacamoleHome() {
|
public File getGuacamoleHome() {
|
||||||
return guacHome;
|
return guacHome;
|
||||||
@@ -307,30 +352,34 @@ public class LocalEnvironment implements Environment {
|
|||||||
/**
|
/**
|
||||||
* Gets the string value for a property name.
|
* Gets the string value for a property name.
|
||||||
*
|
*
|
||||||
* The value may come from either the OS environment or the Properties
|
* The value may come from either the OS environment (if property override
|
||||||
* collection that was loaded from guacamole.properties. When checking the
|
* is enabled) or the Properties collection that was loaded from
|
||||||
* environment for the named property, the name is first transformed by
|
* guacamole.properties. When checking the environment for the named
|
||||||
* converting all hyphens to underscores and converting the string to
|
* property, the name is first transformed by converting all hyphens to
|
||||||
* upper case letter, in accordance with common convention for environment
|
* underscores and converting the string to upper case letter, in accordance
|
||||||
* strings.
|
* with common convention for environment strings.
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* The name of the property value to retrieve.
|
* The name of the property value to retrieve.
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
* The corresponding value for the property. If the value is found in
|
* The corresponding value for the property. If property override
|
||||||
* the OS environment, any corresponding value from the Properties
|
* is enabled and the value is found in the OS environment, the value
|
||||||
* collection containing properties from guacamole.properties is
|
* from the environment is returned. Otherwise, the value from
|
||||||
* ignored.
|
* guacamole.properties, if any, is returned.
|
||||||
*/
|
*/
|
||||||
private String getPropertyValue(String name) {
|
private String getPropertyValue(String name) {
|
||||||
|
|
||||||
// transform the name according to common convention
|
// Check for corresponding environment variable if overrides enabled
|
||||||
final String envName = name.replace('-', '_').toUpperCase();
|
if (environmentPropertyOverride) {
|
||||||
final String envValue = System.getenv(envName);
|
|
||||||
|
|
||||||
if (envValue != null) {
|
// Transform the name according to common convention
|
||||||
return envValue;
|
final String envName = name.replace('-', '_').toUpperCase();
|
||||||
|
final String envValue = System.getenv(envName);
|
||||||
|
|
||||||
|
if (envValue != null) {
|
||||||
|
return envValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return properties.getProperty(name);
|
return properties.getProperty(name);
|
||||||
|
Reference in New Issue
Block a user