diff --git a/docs/source/configuration.rst b/docs/source/configuration.rst index 278b3fd..3bf3447 100644 --- a/docs/source/configuration.rst +++ b/docs/source/configuration.rst @@ -98,7 +98,7 @@ Filters/Searching ==================================== ================================================ ``LDAP_USER_SEARCH_SCOPE`` Specifies what scope to search in when searching for a specific user. Defaults to - ``'SEARCH_SCOPE_SINGLE_LEVEL'``. + ``'LEVEL'``. ``LDAP_USER_OBJECT_FILTER`` Specifies what object filter to apply when searching for users. Defaults to @@ -119,7 +119,7 @@ Filters/Searching ``LDAP_GROUP_SEARCH_SCOPE`` Specifies what scope to search in when searching for a specific group. Defaults to - ``'SEARCH_SCOPE_SINGLE_LEVEL'``. + ``'LEVEL'``. ``LDAP_GROUP_OBJECT_FILTER`` Specifies what object filter to apply when searching for groups. Defaults to diff --git a/flask_ldap3_login/__init__.py b/flask_ldap3_login/__init__.py index 5433602..943f299 100755 --- a/flask_ldap3_login/__init__.py +++ b/flask_ldap3_login/__init__.py @@ -52,7 +52,7 @@ def __init__(self, app=None): self.config = {} self._server_pool = ldap3.ServerPool( [], - ldap3.POOLING_STRATEGY_FIRST, + ldap3.FIRST, active=1, # Loop through all servers once. exhaust=10, # Remove unreachable servers for 10 seconds. ) @@ -115,11 +115,11 @@ def init_config(self, config): self.config.setdefault('LDAP_USER_DN', '') self.config.setdefault('LDAP_GROUP_DN', '') - self.config.setdefault('LDAP_BIND_AUTHENTICATION_TYPE', 'AUTH_SIMPLE') + self.config.setdefault('LDAP_BIND_AUTHENTICATION_TYPE', 'SIMPLE') # Ldap Filters self.config.setdefault('LDAP_USER_SEARCH_SCOPE', - 'SEARCH_SCOPE_SINGLE_LEVEL') + 'LEVEL') self.config.setdefault('LDAP_USER_OBJECT_FILTER', '(objectclass=person)') self.config.setdefault('LDAP_USER_LOGIN_ATTR', 'uid') @@ -128,7 +128,7 @@ def init_config(self, config): 'LDAP_GET_USER_ATTRIBUTES', ldap3.ALL_ATTRIBUTES) self.config.setdefault('LDAP_GROUP_SEARCH_SCOPE', - 'SEARCH_SCOPE_SINGLE_LEVEL') + 'LEVEL') self.config.setdefault( 'LDAP_GROUP_OBJECT_FILTER', '(objectclass=group)') self.config.setdefault('LDAP_GROUP_MEMBERS_ATTR', 'uniqueMember') @@ -325,7 +325,7 @@ def authenticate_direct_credentials(self, username, password): response.user_info = user['attributes'] response.user_dn = user['dn'] - except ldap3.LDAPInvalidCredentialsResult as e: + except ldap3.core.exceptions.LDAPInvalidCredentialsResult as e: log.debug( "Authentication was not successful for user '{0}'".format(username)) response.status = AuthenticationResponseStatus.fail @@ -380,7 +380,7 @@ def authenticate_direct_bind(self, username, password): response.user_groups = self.get_user_groups( dn=bind_user, _connection=connection) - except ldap3.LDAPInvalidCredentialsResult as e: + except ldap3.core.exceptions.LDAPInvalidCredentialsResult as e: log.debug( "Authentication was not successful for user '{0}'".format(username)) response.status = AuthenticationResponseStatus.fail @@ -491,7 +491,7 @@ def authenticate_search_bind(self, username, password): self.destroy_connection(user_connection) break - except ldap3.LDAPInvalidCredentialsResult as e: + except ldap3.core.exceptions.LDAPInvalidCredentialsResult as e: log.debug( "Authentication was not successful for " "user '{0}'".format(username)) @@ -751,7 +751,7 @@ def _make_connection(self, bind_user=None, bind_password=None, upon bind if you use this internal method. """ - authentication = ldap3.AUTH_ANONYMOUS + authentication = ldap3.ANONYMOUS if bind_user: authentication = getattr(ldap3, self.config.get( 'LDAP_BIND_AUTHENTICATION_TYPE')) @@ -763,7 +763,7 @@ def _make_connection(self, bind_user=None, bind_password=None, read_only=self.config.get('LDAP_READONLY'), user=bind_user, password=bind_password, - client_strategy=ldap3.STRATEGY_SYNC, + client_strategy=ldap3.SYNC, authentication=authentication, check_names=True, raise_exceptions=True, diff --git a/flask_ldap3_login_tests/MockTypes.py b/flask_ldap3_login_tests/MockTypes.py index a16079d..fae4063 100644 --- a/flask_ldap3_login_tests/MockTypes.py +++ b/flask_ldap3_login_tests/MockTypes.py @@ -75,7 +75,7 @@ def __init__(self, user=None, password=None, server=None, **kwargs): def bind(self): if not self.server or self.server.servers[0].host != 'ad.mydomain.com': - raise ldap3.LDAPBindError + raise ldap3.core.exceptions.LDAPBindError if self.user: # Validate the bind user. @@ -84,7 +84,7 @@ def bind(self): if bind_user and self.password == bind_user['password']: return True - raise ldap3.LDAPInvalidCredentialsResult + raise ldap3.core.exceptions.LDAPInvalidCredentialsResult else: return True diff --git a/setup.py b/setup.py index a9b48c2..cd5346b 100755 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ def get_version(): except Exception as e: version = '0.0.0-dev' -requires = ['ldap3', 'Flask', 'Flask-wtf'] +requires = ['ldap3>=2.0.7', 'Flask', 'Flask-wtf'] try: import enum # noqa