Skip to content

Commit

Permalink
Module is now compatible with ldap3>=2.0.7. (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgroschupp authored and nickw444 committed Oct 31, 2016
1 parent fd37d6d commit 7923897
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions docs/source/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 9 additions & 9 deletions flask_ldap3_login/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
)
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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'))
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions flask_ldap3_login_tests/MockTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7923897

Please sign in to comment.