From a0562189509f4d4b67083bd0cda88eaaf65dd134 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 13 Nov 2021 16:49:00 -0800 Subject: [PATCH] GUACAMOLE-957: Use guacamole.properties alone for LDAP configuration if ldap-servers.yml is empty. --- .../auth/ldap/conf/ConfigurationService.java | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/conf/ConfigurationService.java b/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/conf/ConfigurationService.java index 3b08d3332..545c03b85 100644 --- a/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/conf/ConfigurationService.java +++ b/extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/conf/ConfigurationService.java @@ -67,8 +67,11 @@ public class ConfigurationService { /** * The cached copy of the configuration read from {@link #LDAP_SERVERS_YML}. + * If the current set of LDAP servers has not yet been read from the YAML + * configuration file, or if guacamole.properties is being used instead, + * this will be null. */ - private Collection cachedConfigurations = Collections.emptyList(); + private Collection cachedConfigurations = null; /** * The Guacamole server environment. @@ -90,7 +93,7 @@ public class ConfigurationService { */ public Collection getLDAPConfigurations() throws GuacamoleException { - // Read configuration from YAML, if available + // Read/refresh configuration from YAML, if available File ldapServers = new File(environment.getGuacamoleHome(), LDAP_SERVERS_YML); if (ldapServers.exists()) { @@ -105,9 +108,15 @@ public class ConfigurationService { logger.debug("Reading updated LDAP configuration from \"{}\"...", ldapServers); Collection configs = mapper.readValue(ldapServers, new TypeReference>() {}); - logger.debug("Reading LDAP configuration defaults from guacamole.properties..."); - LDAPConfiguration defaultConfig = new EnvironmentLDAPConfiguration(environment); - configs.forEach((config) -> config.setDefaults(defaultConfig)); + if (configs != null) { + logger.debug("Reading LDAP configuration defaults from guacamole.properties..."); + LDAPConfiguration defaultConfig = new EnvironmentLDAPConfiguration(environment); + configs.forEach((config) -> config.setDefaults(defaultConfig)); + } + else + logger.debug("Using only guacamole.properties for " + + "LDAP server definitions as \"{}\" is " + + "empty.", ldapServers); cachedConfigurations = configs; @@ -119,13 +128,15 @@ public class ConfigurationService { else logger.debug("Using cached LDAP configuration from \"{}\".", ldapServers); - return cachedConfigurations; - } // Use guacamole.properties if not using YAML - logger.debug("Reading LDAP configuration from guacamole.properties..."); - return Collections.singletonList(new EnvironmentLDAPConfiguration(environment)); + if (cachedConfigurations == null) { + logger.debug("Reading LDAP configuration from guacamole.properties..."); + return Collections.singletonList(new EnvironmentLDAPConfiguration(environment)); + } + + return cachedConfigurations; }