Skip to content

Commit

Permalink
Tweak log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
consideRatio committed Nov 1, 2024
1 parent 00f8af1 commit 0732444
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions ldapauthenticator/ldapauthenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,12 +460,14 @@ def resolve_username(self, username_supplied_by_user):
n_entries = len(conn.entries)
if n_entries == 0:
self.log.warning(
f"Failed to lookup a DN for username '{username_supplied_by_user}'"
f"Login of '{username_supplied_by_user}' denied, failed to lookup a DN"
)
return (None, None)
if n_entries > 1:
self.log.error(
f"Failed to lookup a unique DN for username '{username_supplied_by_user}'"
f"Login of '{username_supplied_by_user}' denied, expected 0 or 1 "
f"search response entries but received {n_entries}. Is lookup_dn_search_filter "
"and user_attribute configured to uniquely match against a DN?"
)
return (None, None)
entry = conn.entries[0]
Expand Down Expand Up @@ -554,11 +556,11 @@ def get_user_attributes(self, conn, userdn):
n_entries = len(conn.entries)
if n_entries == 1:
return conn.entries[0].entry_attributes_as_dict
else:
self.log.warning(
f"Expected 1 but got {n_entries} search response entries for DN '{userdn}' "
"when looking up attributes configured via auth_state_attributes."
)
self.log.error(
f"Expected 1 but got {n_entries} search response entries for DN '{userdn}' "
"when looking up attributes configured via auth_state_attributes. The user's "
"auth state will not include any attributes."
)
return {}

async def authenticate(self, handler, data):
Expand Down Expand Up @@ -645,8 +647,10 @@ async def authenticate(self, handler, data):
n_entries = len(conn.entries)
if n_entries != 1:
self.log.warning(
"Exactly 1 search response entry is required with search_filter configured, "
f"but got {n_entries} for username '{login_username}'."
f"Login of '{login_username}' denied. Configured search_filter "
f"found {n_entries} users associated with "
f"userattr='{self.user_attribute}' and username='{resolved_username}', "
"and a unique match is required."
)
return None

Expand Down

0 comments on commit 0732444

Please sign in to comment.