LDAP sometimes has multiple records for a user
This commit is contained in:
parent
efab02ae47
commit
07b4fb9105
1 changed files with 9 additions and 5 deletions
|
@ -69,17 +69,21 @@ class LDAPUsers(object):
|
||||||
|
|
||||||
logger.debug('Conducting user search: %s under %s', query, user_search_dn)
|
logger.debug('Conducting user search: %s under %s', query, user_search_dn)
|
||||||
try:
|
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:
|
except ldap.LDAPError:
|
||||||
logger.exception('LDAP search exception')
|
logger.exception('LDAP search exception')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
logger.debug('Found user data: %s', user)
|
logger.debug('Found matching pairs: %s', pairs)
|
||||||
if len(user) != 1:
|
if len(pairs) < 1:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
logger.debug('Found user: %s', user[0])
|
for pair in pairs:
|
||||||
return user[0]
|
if pair[0] is not None:
|
||||||
|
logger.debug('Found user: %s', pair)
|
||||||
|
return pair
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
def verify_user(self, username_or_email, password):
|
def verify_user(self, username_or_email, password):
|
||||||
""" Verify the credentials with LDAP and if they are valid, create or update the user
|
""" Verify the credentials with LDAP and if they are valid, create or update the user
|
||||||
|
|
Reference in a new issue