ldap: add representation of LDAP exceptions to log (#32768)

This commit is contained in:
Benjamin Dauvergne 2019-05-03 15:29:03 +02:00
parent 895131ea62
commit a5cc143ee4
1 changed files with 9 additions and 9 deletions

View File

@ -317,7 +317,7 @@ class LDAPUser(get_user_model()):
except ldap.INVALID_CREDENTIALS:
return False
except ldap.LDAPError as e:
log.error('LDAPUser.check_password() failed: %s', e)
log.error('LDAPUser.check_password() failed: %r', e)
return False
self._current_password = raw_password
return True
@ -565,13 +565,12 @@ class LDAPBackend(object):
else:
raise NotImplementedError
except ldap.NO_SUCH_OBJECT:
log.error('user lookup failed: basedn %s not found', user_basedn)
log.error('user lookup failed, basedn %s not found', user_basedn)
if block['replicas']:
break
continue
except ldap.LDAPError as e:
log.error('user lookup failed: with query %r got error %s: %s', username,
query, e)
log.error('user lookup failed, with query %r: %r', query, e)
continue
if not authz_ids:
continue
@ -934,8 +933,8 @@ class LDAPBackend(object):
mandatory_attributes_values = map_text(block['mandatory_attributes_values'])
try:
results = conn.search_s(dn, ldap.SCOPE_BASE, u'(objectclass=*)', attributes)
except ldap.LDAPError:
log.exception('unable to retrieve attributes of dn %r', dn)
except ldap.LDAPError as e:
log.error('unable to retrieve attributes of dn %r: %r', dn, e)
return None
attribute_map = cls.normalize_ldap_results(results[0][1])
# add mandatory attributes
@ -1391,11 +1390,12 @@ class LDAPBackendPasswordLost(LDAPBackend):
user, external_id)
continue
dn = results[0][0]
except ldap.LDAPError:
except ldap.LDAPError as e:
log.warning(
u'unable to find user %r based on external id %s',
u'unable to find user %r based on external id %s: %r',
user,
external_id)
external_id,
e)
continue
return self._return_user(dn, None, conn, block)