public LDAPAuthenticatedUser authenticateUser(Credentials credentials)
            throws GuacamoleException {
        
        String username = credentials.getUsername();
        String password = credentials.getPassword();
        
        // Username and password are required
        if (username == null
                || username.isEmpty()
                || password == null
                || password.isEmpty()) {
            throw new GuacamoleInvalidCredentialsException(
                    "Anonymous bind is not currently allowed by the LDAP"
                    + " authentication provider.", CredentialsInfo.USERNAME_PASSWORD);
        }

        UserLDAPConfiguration config = getLDAPConfiguration(username, password);
        if (config == null)
            throw new GuacamoleInvalidCredentialsException("Invalid login.",
                    CredentialsInfo.USERNAME_PASSWORD);

        try {

            // Retrieve group membership of the user that just authenticated
            Set<String> effectiveGroups =
                    userGroupService.getParentUserGroupIdentifiers(config, config.getBindDN());

            // Return AuthenticatedUser if bind succeeds
            LDAPAuthenticatedUser authenticatedUser = authenticatedUserProvider.get();

            authenticatedUser.init(config, credentials,
                    getUserTokens(config, credentials), effectiveGroups);

            return authenticatedUser;
        }

        catch (GuacamoleException | RuntimeException | Error e) {
            config.close();
            throw e;
        }

    }
Returns an AuthenticatedUser representing the user authenticated by the
given credentials. Also adds custom LDAP attributes to the
AuthenticatedUser.

@param credentials
    The credentials to use for authentication.

@return
    An AuthenticatedUser representing the user authenticated by the
    given credentials.

@throws GuacamoleException
    If an error occurs while authenticating the user, or if access is
    denied.
extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/AuthenticationProviderService.java