Skip to content

Commit 3e2d2e7

Browse files
committed
fix ldap filter import
1 parent 2e0a46d commit 3e2d2e7

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

docs/index.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ History
114114

115115
Changes:
116116

117+
- 1.0.1 June 5, 2016
118+
119+
- Fix ldap filter import.
120+
117121
- 1.0.0 June 4, 2016
118122

119123
- Python 3.x support. Switched from python-ldap to pyldap which is a fork with Python 3.x support.

flask_simpleldap/__init__.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import re
33
from functools import wraps
44
import ldap
5-
from ldap import filter
5+
from ldap import filter as ldap_filter
66
from flask import abort, current_app, g, make_response, redirect, url_for, \
77
request
88

@@ -93,7 +93,7 @@ def initialize(self):
9393
conn.start_tls_s()
9494
return conn
9595
except ldap.LDAPError as e:
96-
raise LDAPException(self.error(e))
96+
raise LDAPException(self.error(e.args))
9797

9898
@property
9999
def bind(self):
@@ -111,7 +111,7 @@ def bind(self):
111111
current_app.config['LDAP_PASSWORD'])
112112
return conn
113113
except ldap.LDAPError as e:
114-
raise LDAPException(self.error(e))
114+
raise LDAPException(self.error(e.args))
115115

116116
def bind_user(self, username, password):
117117
"""Attempts to bind a user to the LDAP server using the credentials
@@ -158,12 +158,12 @@ def get_object_details(self, user=None, group=None, dn_only=False):
158158
if user is not None:
159159
if not dn_only:
160160
fields = current_app.config['LDAP_USER_FIELDS']
161-
query = filter.filter_format(
161+
query = ldap_filter.filter_format(
162162
current_app.config['LDAP_USER_OBJECT_FILTER'], (user,))
163163
elif group is not None:
164164
if not dn_only:
165165
fields = current_app.config['LDAP_GROUP_FIELDS']
166-
query = filter.filter_format(
166+
query = ldap_filter.filter_format(
167167
current_app.config['LDAP_GROUP_OBJECT_FILTER'], (group,))
168168
conn = self.bind
169169
try:
@@ -187,7 +187,7 @@ def get_object_details(self, user=None, group=None, dn_only=False):
187187
result[k] = v
188188
return result
189189
except ldap.LDAPError as e:
190-
raise LDAPException(self.error(e))
190+
raise LDAPException(self.error(e.args))
191191

192192
def get_user_groups(self, user):
193193
"""Returns a ``list`` with the user's groups or ``None`` if
@@ -203,14 +203,14 @@ def get_user_groups(self, user):
203203
[str(current_app.config['LDAP_GROUP_MEMBER_FILTER_FIELD'])]
204204
records = conn.search_s(
205205
current_app.config['LDAP_BASE_DN'], ldap.SCOPE_SUBTREE,
206-
ldap.filter.filter_format(
206+
ldap_filter.filter_format(
207207
current_app.config['LDAP_GROUP_MEMBER_FILTER'],
208208
(self.get_object_details(user, dn_only=True),)),
209209
fields)
210210
else:
211211
records = conn.search_s(
212212
current_app.config['LDAP_BASE_DN'], ldap.SCOPE_SUBTREE,
213-
ldap.filter.filter_format(
213+
ldap_filter.filter_format(
214214
current_app.config['LDAP_USER_OBJECT_FILTER'],
215215
(user,)),
216216
[current_app.config['LDAP_USER_GROUPS_FIELD']])
@@ -228,11 +228,11 @@ def get_user_groups(self, user):
228228
records[0][1]:
229229
groups = records[0][1][
230230
current_app.config['LDAP_USER_GROUPS_FIELD']]
231-
result = [re.findall(b'(?:cn=|CN=)(.*?),', group)[0] for
232-
group in groups]
231+
result = [re.findall(b'(?:cn=|CN=)(.*?),', group)[0]
232+
for group in groups]
233233
return result
234234
except ldap.LDAPError as e:
235-
raise LDAPException(self.error(e))
235+
raise LDAPException(self.error(e.args))
236236

237237
def get_group_members(self, group):
238238
"""Returns a ``list`` with the group's members or ``None`` if
@@ -245,7 +245,7 @@ def get_group_members(self, group):
245245
try:
246246
records = conn.search_s(
247247
current_app.config['LDAP_BASE_DN'], ldap.SCOPE_SUBTREE,
248-
ldap.filter.filter_format(
248+
ldap_filter.filter_format(
249249
current_app.config['LDAP_GROUP_OBJECT_FILTER'], (group,)),
250250
[current_app.config['LDAP_GROUP_MEMBERS_FIELD']])
251251
conn.unbind_s()
@@ -256,15 +256,15 @@ def get_group_members(self, group):
256256
current_app.config['LDAP_GROUP_MEMBERS_FIELD']]
257257
return members
258258
except ldap.LDAPError as e:
259-
raise LDAPException(self.error(e))
259+
raise LDAPException(self.error(e.args))
260260

261261
@staticmethod
262262
def error(e):
263-
e = e.args[0]
263+
e = e[0]
264264
if 'desc' in e:
265265
return e['desc']
266266
else:
267-
return e[0]
267+
return e
268268

269269
@staticmethod
270270
def login_required(func):

0 commit comments

Comments
 (0)