public LDAPConnection bindAs(String userDN,String password) throws GuacamoleException {
  LDAPConnection ldapConnection=createLDAPConnection();
  try {
    ldapConnection.connect(confService.getServerHostname(),confService.getServerPort());
    if (confService.getEncryptionMethod() == EncryptionMethod.STARTTLS)     ldapConnection.startTLS();
  }
 catch (  LDAPException e) {
    logger.error("Unable to connect to LDAP server: {}",e.getMessage());
    logger.debug("Failed to connect to LDAP server.",e);
    return null;
  }
  try {
    byte[] passwordBytes;
    try {
      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;
    }
    ldapConnection.bind(LDAPConnection.LDAP_V3,userDN,passwordBytes);
  }
 catch (  LDAPException e) {
    logger.debug("LDAP bind failed.",e);
    disconnect(ldapConnection);
    return null;
  }
  return ldapConnection;
}

public LDAPConnection bindAs ( String userDN , String password ) throws GuacamoleException { LDAPConnection ldapConnection = createLDAPConnection ( ) ; try { ldapConnection . connect ( confService . getServerHostname ( ) , confService . getServerPort ( ) ) ; if ( confService . getEncryptionMethod ( ) == EncryptionMethod . STARTTLS ) ldapConnection . startTLS ( ) ; } catch ( LDAPException e ) { logger . error ( "Unable to connect to LDAP server: {}" , e . getMessage ( ) ) ; logger . debug ( "Failed to connect to LDAP server." , e ) ; return null ; } try { byte [ ] passwordBytes ; try { 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 ; } ldapConnection . bind ( LDAPConnection . LDAP_V3 , userDN , passwordBytes ) ; } catch ( LDAPException e ) { logger . debug ( "LDAP bind failed." , e ) ; disconnect ( ldapConnection ) ; return null ; } return ldapConnection ; }
binds to the ldap server using the provided user dn and password .
