GUAC-908: Handle errors during connect/bind/query distinctly. Only rethrow server error if connection or query fails - failure to bind is just an invalid login.

This commit is contained in:
Michael Jumper
2014-10-27 13:26:13 -07:00
parent 6f81584aed
commit 713ecaae2a

View File

@@ -35,6 +35,7 @@ import java.util.TreeMap;
import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.net.auth.Credentials; import org.glyptodon.guacamole.net.auth.Credentials;
import net.sourceforge.guacamole.net.auth.ldap.properties.LDAPGuacamoleProperties; import net.sourceforge.guacamole.net.auth.ldap.properties.LDAPGuacamoleProperties;
import org.glyptodon.guacamole.GuacamoleServerException;
import org.glyptodon.guacamole.net.auth.simple.SimpleAuthenticationProvider; import org.glyptodon.guacamole.net.auth.simple.SimpleAuthenticationProvider;
import org.glyptodon.guacamole.properties.GuacamoleProperties; import org.glyptodon.guacamole.properties.GuacamoleProperties;
import org.glyptodon.guacamole.protocol.GuacamoleConfiguration; import org.glyptodon.guacamole.protocol.GuacamoleConfiguration;
@@ -126,28 +127,34 @@ public class LDAPAuthenticationProvider extends SimpleAuthenticationProvider {
@Override @Override
public Map<String, GuacamoleConfiguration> getAuthorizedConfigurations(Credentials credentials) throws GuacamoleException { public Map<String, GuacamoleConfiguration> getAuthorizedConfigurations(Credentials credentials) throws GuacamoleException {
try {
// Require username // Require username
if (credentials.getUsername() == null) { if (credentials.getUsername() == null) {
logger.info("Anonymous bind is not currently allowed by the LDAP authentication provider."); logger.debug("Anonymous bind is not currently allowed by the LDAP authentication provider.");
return null; return null;
} }
// Require password, and do not allow anonymous binding // Require password, and do not allow anonymous binding
if (credentials.getPassword() == null if (credentials.getPassword() == null
|| credentials.getPassword().length() == 0) { || credentials.getPassword().length() == 0) {
logger.info("Anonymous bind is not currently allowed by the LDAP authentication provider."); logger.debug("Anonymous bind is not currently allowed by the LDAP authentication provider.");
return null; return null;
} }
// Connect to LDAP server // Connect to LDAP server
LDAPConnection ldapConnection = new LDAPConnection(); LDAPConnection ldapConnection;
try {
ldapConnection = new LDAPConnection();
ldapConnection.connect( ldapConnection.connect(
GuacamoleProperties.getRequiredProperty(LDAPGuacamoleProperties.LDAP_HOSTNAME), GuacamoleProperties.getRequiredProperty(LDAPGuacamoleProperties.LDAP_HOSTNAME),
GuacamoleProperties.getRequiredProperty(LDAPGuacamoleProperties.LDAP_PORT) GuacamoleProperties.getRequiredProperty(LDAPGuacamoleProperties.LDAP_PORT)
); );
}
catch (LDAPException e) {
throw new GuacamoleServerException("Unable to connect to LDAP server.", e);
}
// Get username attribute // Get username attribute
String username_attribute = GuacamoleProperties.getRequiredProperty( String username_attribute = GuacamoleProperties.getRequiredProperty(
LDAPGuacamoleProperties.LDAP_USERNAME_ATTRIBUTE LDAPGuacamoleProperties.LDAP_USERNAME_ATTRIBUTE
@@ -163,6 +170,8 @@ public class LDAPAuthenticationProvider extends SimpleAuthenticationProvider {
escapeDN(username_attribute) + "=" + escapeDN(credentials.getUsername()) escapeDN(username_attribute) + "=" + escapeDN(credentials.getUsername())
+ "," + user_base_dn; + "," + user_base_dn;
try {
// Bind as user // Bind as user
try { try {
ldapConnection.bind( ldapConnection.bind(
@@ -175,11 +184,20 @@ public class LDAPAuthenticationProvider extends SimpleAuthenticationProvider {
throw new GuacamoleException(e); throw new GuacamoleException(e);
} }
}
catch (LDAPException e) {
logger.debug("LDAP bind failed.", e);
return null;
}
// Get config base DN // Get config base DN
String config_base_dn = GuacamoleProperties.getRequiredProperty( String config_base_dn = GuacamoleProperties.getRequiredProperty(
LDAPGuacamoleProperties.LDAP_CONFIG_BASE_DN LDAPGuacamoleProperties.LDAP_CONFIG_BASE_DN
); );
// Pull all connections
try {
// Find all guac configs for this user // Find all guac configs for this user
LDAPSearchResults results = ldapConnection.search( LDAPSearchResults results = ldapConnection.search(
config_base_dn, config_base_dn,
@@ -248,7 +266,7 @@ public class LDAPAuthenticationProvider extends SimpleAuthenticationProvider {
} }
catch (LDAPException e) { catch (LDAPException e) {
throw new GuacamoleException(e); throw new GuacamoleServerException("Error while querying for connections.", e);
} }
} }