Skip to content

Commit

Permalink
refactor: reduce use of temporary variables
Browse files Browse the repository at this point in the history
  • Loading branch information
consideRatio committed Sep 16, 2024
1 parent f990420 commit 65a91de
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions ldapauthenticator/ldapauthenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,13 @@ async def authenticate(self, handler, data):
return None

if self.search_filter:
search_filter = self.search_filter.format(
userattr=self.user_attribute, username=escape_filter_chars(username)
)
conn.search(
search_base=self.user_search_base,
search_scope=ldap3.SUBTREE,
search_filter=search_filter,
search_filter=self.search_filter.format(
userattr=self.user_attribute,
username=escape_filter_chars(username),
),
attributes=self.attributes,
)
n_users = len(conn.response)
Expand All @@ -437,17 +437,14 @@ async def authenticate(self, handler, data):
self.log.debug("username:%s Using dn %s", username, userdn)
found = False
for group in self.allowed_groups:
group_search_filter = self.group_search_filter
group_search_filter = group_search_filter.format(
userdn=escape_filter_chars(userdn),
uid=escape_filter_chars(username),
)
group_attributes = self.group_attributes
found = conn.search(
group,
search_scope=ldap3.BASE,
search_filter=group_search_filter,
attributes=group_attributes,
search_filter=self.group_search_filter.format(
userdn=escape_filter_chars(userdn),
uid=escape_filter_chars(username),
),
attributes=self.group_attributes,
)
if found:
break
Expand Down

0 comments on commit 65a91de

Please sign in to comment.