Commit d4ea0444 authored by Daniel Klaffenbach's avatar Daniel Klaffenbach 🐍

fountain.ldap: Rework connection initialization

parent c43de5db
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import ssl
from ldap3 import Server, Connection, RESTARTABLE
from ldap3 import Server, Connection, RESTARTABLE, DSA
from ldap3.core.tls import Tls
from ldap3.utils.uri import parse_uri
from django.conf import settings
......@@ -29,11 +29,21 @@ class Ldap(object):
@cached_property
def connection(self):
server_kwargs = {
'host': self.LDAP_PARAMS['host'],
'use_ssl': False,
'port': self.LDAP_PARAMS['port']
}
if self.LDAP_PARAMS['ssl']:
tls = Tls(ca_certs_file=self.LDAP_CA_CERT, validate=ssl.CERT_REQUIRED)
s=Server(self.LDAP_PARAMS['host'], use_ssl=True, tls=tls)
else:
s=Server(self.LDAP_PARAMS['host'], use_ssl=False)
server_kwargs['use_ssl'] = True
server_kwargs['tls'] = Tls(ca_certs_file=self.LDAP_CA_CERT, validate=ssl.CERT_REQUIRED)
# In case the LDAP server is the local host we assume a testing server.
# "SCHEMA" queries might not be available, so use "DSA" instead.
if self.LDAP_PARAMS['host'] == 'localhost':
server_kwargs['get_info'] = DSA
s=Server(**server_kwargs)
c = Connection(
s,
auto_bind=True,
......
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