Commit 42e4ee53 authored by Daniel Klaffenbach's avatar Daniel Klaffenbach 🐍

ldap: Make `LDAP_TIMEOUT` configurable

parent 1d8c72b0
Pipeline #5761 passed with stage
in 50 seconds
......@@ -8,6 +8,7 @@ from ldap3.utils.uri import parse_uri
from django.conf import settings
from django.utils.functional import cached_property
DEFAULT_LDAP_TIMEOUT = 3
DEFAULT_LDAP_SYNC_URI = 'ldaps://ldap.tu-chemnitz.de/ou=Users,dc=tu-chemnitz,dc=de'
DEFAULT_LDAP_SYNC_USER_ATTRIBUTES = {
......@@ -27,13 +28,15 @@ class Ldap(object):
self.LDAP_SYNC_BASE_PASS = getattr(settings, 'LDAP_SYNC_BASE_PASS', None)
self.LDAP_SYNC_USER_ATTRIBUTES = getattr(settings, 'LDAP_SYNC_USER_ATTRIBUTES', DEFAULT_LDAP_SYNC_USER_ATTRIBUTES)
self.LDAP_CA_CERT = getattr(settings, 'LDAP_CA_CERT', DEFAULT_CA_CERT)
self.LDAP_TIMEOUT = getattr(settings, 'LDAP_TIMEOUT', DEFAULT_LDAP_TIMEOUT)
@cached_property
def connection(self):
server_kwargs = {
'host': self.LDAP_PARAMS['host'],
'use_ssl': False,
'port': self.LDAP_PARAMS['port']
'port': self.LDAP_PARAMS['port'],
'connect_timeout': self.LDAP_TIMEOUT,
}
if self.LDAP_PARAMS['ssl']:
server_kwargs['use_ssl'] = True
......@@ -78,7 +81,6 @@ class Ldap(object):
conn.bind()
result = conn.search(**search_kwargs)
if result:
for attr in self.LDAP_SYNC_USER_ATTRIBUTES:
if attr in conn.response[0]['attributes'] and conn.response[0]['attributes'][attr]:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment