--- a/src/pyams_ldap/plugin.py Fri Apr 27 10:36:33 2018 +0200
+++ b/src/pyams_ldap/plugin.py Mon Nov 05 16:34:09 2018 +0100
@@ -12,20 +12,16 @@
__docformat__ = 'restructuredtext'
-
-# import standard library
-import ldap3
import logging
logger = logging.getLogger('PyAMS (ldap)')
+import ldap3
import re
-# import interfaces
from pyams_ldap.interfaces import ILDAPPlugin, ILDAPUserInfo, ILDAPGroupInfo
from pyams_mail.interfaces import IPrincipalMailInfo
from zope.intid.interfaces import IIntIds
-# import packages
from beaker.cache import cache_region
from persistent import Persistent
from pyams_ldap.query import LDAPQuery
@@ -39,7 +35,6 @@
managers = {}
-
FORMAT_ATTRIBUTES = re.compile("\{(\w+)\[?\d*\]?\}")
@@ -53,31 +48,24 @@
tls=plugin.use_tls)
self.bind_dn = plugin.bind_dn
self.password = plugin.bind_password
- if plugin.use_pool:
- self.strategy = ldap3.REUSABLE
- self.pool_name = 'pyams_ldap:{prefix}'.format(prefix=plugin.prefix)
- self.pool_size = plugin.pool_size
- self.pool_lifetime = plugin.pool_lifetime
- else:
- self.strategy = ldap3.ASYNC
- self.pool_name = None
- self.pool_size = None
- self.pool_lifetime = None
- def get_connection(self, user=None, password=None):
+ def get_connection(self, user=None, password=None, read_only=True):
if user:
conn = ldap3.Connection(self.server,
user=user, password=password,
- client_strategy=ldap3.SYNC,
- auto_bind=True, lazy=False, read_only=True)
+ client_strategy=ldap3.ASYNC,
+ auto_bind=ldap3.AUTO_BIND_DEFAULT,
+ lazy=True,
+ read_only=read_only)
else:
conn = ldap3.Connection(self.server,
user=self.bind_dn, password=self.password,
- client_strategy=self.strategy,
- pool_name=self.pool_name,
- pool_size=self.pool_size,
- pool_lifetime=self.pool_lifetime,
- auto_bind=True, lazy=False, read_only=True)
+ client_strategy=ldap3.REUSABLE,
+ auto_bind=ldap3.AUTO_BIND_DEFAULT if self.bind_dn else ldap3.AUTO_BIND_NONE,
+ lazy=True,
+ read_only=read_only)
+ if conn.auto_bind == ldap3.AUTO_BIND_NONE:
+ conn.open(read_server_info=False)
return conn
@@ -178,12 +166,10 @@
_use_ssl = False
_server_uri = FieldProperty(ILDAPPlugin['server_uri'])
+ use_tls = FieldProperty(ILDAPPlugin['use_tls'])
bind_dn = FieldProperty(ILDAPPlugin['bind_dn'])
bind_password = FieldProperty(ILDAPPlugin['bind_password'])
- use_tls = FieldProperty(ILDAPPlugin['use_tls'])
- use_pool = FieldProperty(ILDAPPlugin['use_pool'])
- pool_size = FieldProperty(ILDAPPlugin['pool_size'])
- pool_lifetime = FieldProperty(ILDAPPlugin['pool_lifetime'])
+
base_dn = FieldProperty(ILDAPPlugin['base_dn'])
search_scope = FieldProperty(ILDAPPlugin['search_scope'])