GUACAMOLE-957: Use guacamole.properties alone for LDAP configuration if ldap-servers.yml is empty.

This commit is contained in:
Michael Jumper
2021-11-13 16:49:00 -08:00
parent 62b26fb594
commit a056218950

View File

@@ -67,8 +67,11 @@ public class ConfigurationService {
/** /**
* The cached copy of the configuration read from {@link #LDAP_SERVERS_YML}. * 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<JacksonLDAPConfiguration> cachedConfigurations = Collections.emptyList(); private Collection<JacksonLDAPConfiguration> cachedConfigurations = null;
/** /**
* The Guacamole server environment. * The Guacamole server environment.
@@ -90,7 +93,7 @@ public class ConfigurationService {
*/ */
public Collection<? extends LDAPConfiguration> getLDAPConfigurations() throws GuacamoleException { public Collection<? extends LDAPConfiguration> 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); File ldapServers = new File(environment.getGuacamoleHome(), LDAP_SERVERS_YML);
if (ldapServers.exists()) { if (ldapServers.exists()) {
@@ -105,9 +108,15 @@ public class ConfigurationService {
logger.debug("Reading updated LDAP configuration from \"{}\"...", ldapServers); logger.debug("Reading updated LDAP configuration from \"{}\"...", ldapServers);
Collection<JacksonLDAPConfiguration> configs = mapper.readValue(ldapServers, new TypeReference<Collection<JacksonLDAPConfiguration>>() {}); Collection<JacksonLDAPConfiguration> configs = mapper.readValue(ldapServers, new TypeReference<Collection<JacksonLDAPConfiguration>>() {});
if (configs != null) {
logger.debug("Reading LDAP configuration defaults from guacamole.properties..."); logger.debug("Reading LDAP configuration defaults from guacamole.properties...");
LDAPConfiguration defaultConfig = new EnvironmentLDAPConfiguration(environment); LDAPConfiguration defaultConfig = new EnvironmentLDAPConfiguration(environment);
configs.forEach((config) -> config.setDefaults(defaultConfig)); configs.forEach((config) -> config.setDefaults(defaultConfig));
}
else
logger.debug("Using only guacamole.properties for "
+ "LDAP server definitions as \"{}\" is "
+ "empty.", ldapServers);
cachedConfigurations = configs; cachedConfigurations = configs;
@@ -119,14 +128,16 @@ public class ConfigurationService {
else else
logger.debug("Using cached LDAP configuration from \"{}\".", ldapServers); logger.debug("Using cached LDAP configuration from \"{}\".", ldapServers);
}
// Use guacamole.properties if not using YAML
if (cachedConfigurations == null) {
logger.debug("Reading LDAP configuration from guacamole.properties...");
return Collections.singletonList(new EnvironmentLDAPConfiguration(environment));
}
return cachedConfigurations; return cachedConfigurations;
} }
// Use guacamole.properties if not using YAML
logger.debug("Reading LDAP configuration from guacamole.properties...");
return Collections.singletonList(new EnvironmentLDAPConfiguration(environment));
}
} }