forked from DGNum/gestioCOF
Don't crash on LDAP errors
This commit is contained in:
parent
56f1edebe3
commit
de1bba3695
1 changed files with 18 additions and 10 deletions
|
@ -1,3 +1,4 @@
|
|||
import logging
|
||||
from collections import namedtuple
|
||||
|
||||
from dal import autocomplete
|
||||
|
@ -12,6 +13,9 @@ else:
|
|||
ldap = None
|
||||
|
||||
|
||||
django_logger = logging.getLogger("django.request")
|
||||
|
||||
|
||||
class SearchUnit:
|
||||
"""Base class for all the search utilities.
|
||||
|
||||
|
@ -128,17 +132,21 @@ class LDAPSearch(SearchUnit):
|
|||
if ldap is None or query == "(&)":
|
||||
return []
|
||||
|
||||
ldap_obj = ldap.initialize(self.ldap_server_url)
|
||||
res = ldap_obj.search_s(
|
||||
self.domain_component, ldap.SCOPE_SUBTREE, query, self.search_fields
|
||||
)
|
||||
return [
|
||||
Clipper(
|
||||
clipper=attrs["uid"][0].decode("utf-8"),
|
||||
fullname=attrs["cn"][0].decode("utf-8"),
|
||||
try:
|
||||
ldap_obj = ldap.initialize(self.ldap_server_url)
|
||||
res = ldap_obj.search_s(
|
||||
self.domain_component, ldap.SCOPE_SUBTREE, query, self.search_fields
|
||||
)
|
||||
for (_, attrs) in res
|
||||
]
|
||||
return [
|
||||
Clipper(
|
||||
clipper=attrs["uid"][0].decode("utf-8"),
|
||||
fullname=attrs["cn"][0].decode("utf-8"),
|
||||
)
|
||||
for (_, attrs) in res
|
||||
]
|
||||
except ldap.LDAPError as err:
|
||||
django_logger.error("An LDAP error occurred", exc_info=err)
|
||||
return []
|
||||
|
||||
|
||||
# ---
|
||||
|
|
Loading…
Reference in a new issue