LDAP sometimes has multiple records for a user

This commit is contained in:
Joseph Schorr 2015-05-12 12:02:09 -04:00
parent efab02ae47
commit 07b4fb9105

View file

@ -69,17 +69,21 @@ class LDAPUsers(object):
logger.debug('Conducting user search: %s under %s', query, user_search_dn)
try:
user = conn.search_s(user_search_dn, ldap.SCOPE_SUBTREE, query.encode('utf-8'))
pairs = conn.search_s(user_search_dn, ldap.SCOPE_SUBTREE, query.encode('utf-8'))
except ldap.LDAPError:
logger.exception('LDAP search exception')
return None
logger.debug('Found user data: %s', user)
if len(user) != 1:
logger.debug('Found matching pairs: %s', pairs)
if len(pairs) < 1:
return None
logger.debug('Found user: %s', user[0])
return user[0]
for pair in pairs:
if pair[0] is not None:
logger.debug('Found user: %s', pair)
return pair
return None
def verify_user(self, username_or_email, password):
""" Verify the credentials with LDAP and if they are valid, create or update the user