Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Following two options are not added in common initialization as they
# need to follow a sequence in PythonLDAPHandler code.
if alias_dereferencing is not None:
self.set_option(ldap.OPT_DEREF, alias_dereferencing)
if chase_referrals is not None:
self.set_option(ldap.OPT_REFERRALS, int(chase_referrals))
if self.use_auth_pool: # separate pool when use_auth_pool enabled
pool_url = self.auth_pool_prefix + url
else:
pool_url = url
try:
self.conn_pool = self.connection_pools[pool_url]
except KeyError:
self.conn_pool = ldappool.ConnectionManager(
url,
size=pool_size,
retry_max=pool_retry_max,
retry_delay=pool_retry_delay,
timeout=pool_conn_timeout,
connector_cls=self.Connector,
use_tls=use_tls,
max_lifetime=pool_conn_lifetime)
self.connection_pools[pool_url] = self.conn_pool
from django.utils.dateformat import format
from django.core.exceptions import ObjectDoesNotExist
import logging, json, time, copy
import ldap
from ldap import modlist
from datetime import datetime
from pprint import pprint as pp
from fum.common.util import to_json, ldap_log
log = logging.getLogger(__name__)
TOTAL_CONNECTIONS = 0
from ldappool import ConnectionManager
cm = ConnectionManager(
uri=settings.LDAP_CONNECTION.get('uri'),
use_tls=settings.USE_TLS,
)
def open_ldap(bind_dn=None, bind_pwd=None):
return LDAPBridge(parent=None, BIND_DN=bind_dn, BIND_PASSWORD=bind_pwd)
def fetch(self, dn, filters='', attrs=[], scope=ldap.SCOPE_BASE, connection=None):
specials = []
normals = []
for a in attrs:
if isinstance(a, tuple):
specials.append(a)
else:
normals.append(a)
def pool(self):
# This is a property to allow lazy loading.
if self._pool is None:
ldap_uri, bind_user, bind_password = decode_ldap_uri(self.ldap_uri)
self._pool = ConnectionManager(ldap_uri, bind_user, bind_password)
return self._pool