Github user necouchman commented on a diff in the pull request:

    https://github.com/apache/guacamole-client/pull/345#discussion_r241928420
  
    --- Diff: 
extensions/guacamole-auth-ldap/src/main/java/org/apache/guacamole/auth/ldap/LDAPConnectionService.java
 ---
    @@ -156,38 +146,84 @@ public LDAPConnection bindAs(String userDN, String 
password)
             // Bind using provided credentials
             try {
     
    -            byte[] passwordBytes;
    -            try {
    -
    -                // Convert password into corresponding byte array
    -                if (password != null)
    -                    passwordBytes = password.getBytes("UTF-8");
    -                else
    -                    passwordBytes = null;
    -
    -            }
    -            catch (UnsupportedEncodingException e) {
    -                logger.error("Unexpected lack of support for UTF-8: {}", 
e.getMessage());
    -                logger.debug("Support for UTF-8 (as required by Java spec) 
not found.", e);
    -                disconnect(ldapConnection);
    -                return null;
    -            }
    -
    -            // Bind as user
    -            ldapConnection.bind(LDAPConnection.LDAP_V3, userDN, 
passwordBytes);
    +            BindRequest bindRequest = new BindRequestImpl();
    +            bindRequest.setDn(userDN);
    +            bindRequest.setCredentials(password);
    +            ldapConnection.bind(bindRequest);
     
             }
     
             // Disconnect if an error occurs during bind
    -        catch (LDAPException e) {
    -            logger.debug("LDAP bind failed.", e);
    +        catch (LdapException e) {
    +            logger.debug("Unable to bind to LDAP server.", e);
                 disconnect(ldapConnection);
                 return null;
             }
     
             return ldapConnection;
     
         }
    +    
    +    /**
    +     * Generate a new LdapConnection object for following a referral
    +     * with the given LdapUrl, and copy the username and password
    +     * from the original connection.
    +     * 
    +     * @param referralUrl
    +     *     The LDAP URL to follow.
    +     * 
    +     * @param ldapConfig
    +     *     The connection configuration to use to retrieve username and
    +     *     password.
    +     * 
    +     * @param hop
    +     *     The current hop number of this referral - once the configured
    +     *     limit is reached, this method will throw an exception.
    +     * 
    +     * @return
    +     *     A LdapConnection object that points at the location
    +     *     specified in the referralUrl.
    +     *     
    +     * @throws GuacamoleException
    +     *     If an error occurs parsing out the LdapUrl object or the
    +     *     maximum number of referral hops is reached.
    +     */
    +    public LdapConnection referralConnection(LdapUrl referralUrl,
    +            LdapConnectionConfig ldapConfig, Integer hop) 
    --- End diff --
    
    Fixed.


---

Reply via email to