diff --git a/web/pgadmin/authenticate/ldap.py b/web/pgadmin/authenticate/ldap.py index 5aadda642..3f98a98b1 100644 --- a/web/pgadmin/authenticate/ldap.py +++ b/web/pgadmin/authenticate/ldap.py @@ -28,9 +28,7 @@ except ImportError: from urlparse import urlparse -ERROR_SEARCHING_LDAP_DIRECTORY = gettext( - "Error searching the LDAP directory: %s" -) +ERROR_SEARCHING_LDAP_DIRECTORY = "Error searching the LDAP directory: %s" class LDAPAuthentication(BaseAuthentication): @@ -162,7 +160,10 @@ class LDAPAuthentication(BaseAuthentication): """Get a list of users from the LDAP server based on config search criteria.""" try: - self.conn.search(search_base=config.LDAP_SEARCH_BASE_DN, + search_base_dn = config.LDAP_SEARCH_BASE_DN + if search_base_dn is None or search_base_dn == '': + search_base_dn = config.LDAP_BASE_DN + self.conn.search(search_base=search_base_dn, search_filter=config.LDAP_SEARCH_FILTER, search_scope=config.LDAP_SEARCH_SCOPE, attributes=ALL_ATTRIBUTES @@ -170,19 +171,19 @@ class LDAPAuthentication(BaseAuthentication): except LDAPInvalidScopeError as e: current_app.logger.exception( - gettext(ERROR_SEARCHING_LDAP_DIRECTORY) % e + ERROR_SEARCHING_LDAP_DIRECTORY % e ) - return False, gettext(ERROR_SEARCHING_LDAP_DIRECTORY) % e.args[0] + return False, ERROR_SEARCHING_LDAP_DIRECTORY % e.args[0] except LDAPAttributeError as e: current_app.logger.exception( - gettext(ERROR_SEARCHING_LDAP_DIRECTORY) % e + ERROR_SEARCHING_LDAP_DIRECTORY % e ) - return False, gettext(ERROR_SEARCHING_LDAP_DIRECTORY) % e.args[0] + return False, ERROR_SEARCHING_LDAP_DIRECTORY % e.args[0] except LDAPInvalidFilterError as e: current_app.logger.exception( - gettext(ERROR_SEARCHING_LDAP_DIRECTORY) % e + ERROR_SEARCHING_LDAP_DIRECTORY % e ) - return False, gettext(ERROR_SEARCHING_LDAP_DIRECTORY) % e.args[0] + return False, ERROR_SEARCHING_LDAP_DIRECTORY % e.args[0] for entry in self.conn.entries: user_email = None @@ -191,4 +192,4 @@ class LDAPAuthentication(BaseAuthentication): if 'mail' in entry: user_email = entry['mail'].value return True, user_email - return False, None + return False, ERROR_SEARCHING_LDAP_DIRECTORY % "Could not find the specified user."