public Dn deriveUserDN(LDAPConfiguration config, String username)
            throws GuacamoleException {

        // Pull username attributes from properties
        List<String> usernameAttributes = new ArrayList<>(config.getUsernameAttributes());

        // We need exactly one base DN to derive the user DN
        if (usernameAttributes.size() != 1) {
            logger.warn(String.format("Cannot directly derive user DN when "
                      + "multiple username attributes are specified. Please "
                      + "define an LDAP search DN using the \"%s\" property "
                      + "in your \"guacamole.properties\".",
                      LDAPGuacamoleProperties.LDAP_SEARCH_BIND_DN.getName()));
            return null;
        }

        // Derive user DN from base DN
        try {
            return new Dn(new Rdn(usernameAttributes.get(0), username),
                config.getUserBaseDN());
        }
        catch (LdapInvalidAttributeValueException | LdapInvalidDnException e) {
            throw new GuacamoleServerException("Error trying to derive user DN.", e);
        }

    }
Determines the DN which corresponds to the user having the given
username. The DN will either be derived directly from the user base DN,
or queried from the LDAP server, depending on how LDAP authentication
has been configured.

@param config
    The configuration of the LDAP server being queried.

@param username
    The username of the user whose corresponding DN should be returned.

@return
    The DN which corresponds to the user having the given username.

@throws GuacamoleException
    If required properties are missing, and thus the user DN cannot be
    determined.
extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/user/UserService.java