11 # |
11 # |
12 |
12 |
13 __docformat__ = 'restructuredtext' |
13 __docformat__ = 'restructuredtext' |
14 |
14 |
15 import logging |
15 import logging |
16 logger = logging.getLogger('PyAMS (ldap)') |
16 import re |
17 |
17 |
18 import ldap3 |
18 import ldap3 |
19 import re |
|
20 |
|
21 from pyams_ldap.interfaces import ILDAPPlugin, ILDAPUserInfo, ILDAPGroupInfo |
|
22 from pyams_mail.interfaces import IPrincipalMailInfo |
|
23 from zope.intid.interfaces import IIntIds |
|
24 |
|
25 from beaker.cache import cache_region |
19 from beaker.cache import cache_region |
|
20 from ldap3.utils.conv import escape_filter_chars |
26 from persistent import Persistent |
21 from persistent import Persistent |
27 from pyams_ldap.query import LDAPQuery |
|
28 from pyams_security.principal import PrincipalInfo |
|
29 from pyams_utils.adapter import adapter_config, ContextAdapter |
|
30 from pyams_utils.registry import query_utility |
|
31 from zope.container.contained import Contained |
22 from zope.container.contained import Contained |
32 from zope.interface import implementer |
23 from zope.interface import implementer |
|
24 from zope.intid.interfaces import IIntIds |
33 from zope.schema.fieldproperty import FieldProperty |
25 from zope.schema.fieldproperty import FieldProperty |
|
26 |
|
27 from pyams_ldap.interfaces import ILDAPGroupInfo, ILDAPPlugin, ILDAPUserInfo |
|
28 from pyams_ldap.query import LDAPQuery |
|
29 from pyams_mail.interfaces import IPrincipalMailInfo |
|
30 from pyams_security.principal import PrincipalInfo |
|
31 from pyams_utils.adapter import ContextAdapter, adapter_config |
|
32 from pyams_utils.registry import query_utility |
|
33 |
|
34 |
|
35 logger = logging.getLogger('PyAMS (ldap)') |
34 |
36 |
35 |
37 |
36 managers = {} |
38 managers = {} |
37 |
39 |
38 FORMAT_ATTRIBUTES = re.compile("\{(\w+)\[?\d*\]?\}") |
40 FORMAT_ATTRIBUTES = re.compile("\{(\w+)\[?\d*\]?\}") |
267 login = attrs.get('login') |
269 login = attrs.get('login') |
268 password = attrs.get('password') |
270 password = attrs.get('password') |
269 conn = self.get_connection() |
271 conn = self.get_connection() |
270 search = LDAPQuery(self.base_dn, self.login_query, self.search_scope, (self.login_attribute, |
272 search = LDAPQuery(self.base_dn, self.login_query, self.search_scope, (self.login_attribute, |
271 self.uid_attribute)) |
273 self.uid_attribute)) |
272 result = search.execute(conn, login=login, password=password) |
274 result = search.execute(conn, login=escape_filter_chars(login)) |
273 if not result or len(result) > 1: |
275 if not result or len(result) > 1: |
274 return None |
276 return None |
275 result = result[0] |
277 result = result[0] |
276 login_dn = result[0] |
278 login_dn = result[0] |
277 try: |
279 try: |