private UserLDAPConfiguration getLDAPConfiguration(String username,
            String password) throws GuacamoleException {

        // Get all LDAP server configurations
        Collection<? extends LDAPConfiguration> configs = confService.getLDAPConfigurations();
        if (configs.isEmpty()) {
            logger.info("Skipping LDAP authentication as no LDAP servers are configured.");
            return null;
        }

        // Try each possible LDAP configuration until the TCP connection and
        // authentication are successful
        for (LDAPConfiguration config : configs) {

            // Attempt connection only if username matches
            String translatedUsername = config.appliesTo(username);
            if (translatedUsername == null) {
                logger.debug("LDAP server \"{}\" does not match username \"{}\".", config.getServerHostname(), username);
                continue;
            }

            logger.debug("LDAP server \"{}\" matched username \"{}\" as \"{}\".",
                    config.getServerHostname(), username, translatedUsername);

            // Derive DN of user within this LDAP server
            Dn bindDn = getUserBindDN(config, translatedUsername);
            if (bindDn == null || bindDn.isEmpty()) {
                logger.info("Unable to determine DN of user \"{}\" using LDAP "
                        + "server \"{}\". Proceeding with next server...",
                        username, config.getServerHostname());
                continue;
            }

            // Attempt bind (authentication)
            LdapNetworkConnection ldapConnection = ldapService.bindAs(config, bindDn.getName(), password);
            if (ldapConnection == null) {
                logger.info("Unable to bind as user \"{}\" against LDAP "
                        + "server \"{}\". Proceeding with next server...",
                        username, config.getServerHostname());
                continue;
            }

            // Connection and bind were successful
            logger.info("User \"{}\" was successfully authenticated by LDAP server \"{}\".", username, config.getServerHostname());
            return new UserLDAPConfiguration(config, translatedUsername, bindDn, ldapConnection);

        }

        // No LDAP connection/authentication attempt succeeded
        logger.info("User \"{}\" did not successfully authenticate against any LDAP server.", username);
        return null;

    }
Returns a new UserLDAPConfiguration that is connected to an LDAP server
associated with the Guacamole user having the given username and bound
using the provided password. All LDAP servers associated with the given
user are tried until the connection and authentication attempt succeeds.
If no LDAP servers are available, or no LDAP servers are associated with
the given user, null is returned. The Guacamole username will be
internally translated to a fully-qualified LDAP DN according to the
configuration of the LDAP server that is ultimately chosen.

@param username
     The username of the Guacamole user to bind as.

@param password
     The password of the user to bind as.

@return
     A new UserLDAPConfiguration which is bound to an LDAP server using
     the provided credentials, or null if no LDAP servers are available
     for the given user or connecting/authenticating has failed.

@throws GuacamoleException
     If configuration information for the user's LDAP server(s) cannot
     be retrieved.
extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/AuthenticationProviderService.java