1313# See the License for the specific language governing permissions and
1414# limitations under the License.
1515
16+ import logging
17+ import ssl
1618from typing import Optional
1719
20+ from pkg_resources import parse_version
1821from twisted .internet import threads
1922
20-
2123import ldap3
2224import ldap3 .core .exceptions
23-
24- import ssl
25-
26- import logging
2725import synapse
2826
29- from pkg_resources import parse_version
30-
31-
3227__version__ = "0.1.4"
3328
34-
35- try :
36- import ldap3
37- import ldap3 .core .exceptions
38-
39- # ldap3 v2 changed ldap3.AUTH_SIMPLE -> ldap3.SIMPLE
40- try :
41- LDAP_AUTH_SIMPLE = ldap3 .AUTH_SIMPLE
42- except AttributeError :
43- LDAP_AUTH_SIMPLE = ldap3 .SIMPLE
44- except ImportError : # pragma: no cover
45- ldap3 = None
46- pass
47-
48-
4929logger = logging .getLogger (__name__ )
5030
5131
@@ -62,18 +42,11 @@ class LDAPMode(object):
6242
6343
6444class LdapAuthProvider (object ):
65- __version__ = "0.1"
6645 _ldap_tls = ldap3 .Tls (validate = ssl .CERT_REQUIRED )
6746
6847 def __init__ (self , config , account_handler ):
6948 self .account_handler = account_handler
7049
71- if not ldap3 : # pragma: no cover
72- raise RuntimeError (
73- 'Missing ldap3 library. '
74- 'This is required for LDAP Authentication.'
75- )
76-
7750 self .ldap_mode = config .mode
7851 self .ldap_uris = [config .uri ] if isinstance (config .uri , str ) else config .uri
7952 self .ldap_start_tls = config .start_tls
@@ -492,7 +465,7 @@ async def _ldap_simple_bind(self, server, bind_dn, password):
492465 conn = await threads .deferToThread (
493466 ldap3 .Connection ,
494467 server , bind_dn , password ,
495- authentication = LDAP_AUTH_SIMPLE ,
468+ authentication = ldap3 . SIMPLE ,
496469 read_only = True ,
497470 )
498471 logger .debug (
0 commit comments