Skip to content

Commit

Permalink
Merge pull request #105 from behrmann/nondn_username
Browse files Browse the repository at this point in the history
Ignore username returned by resolve_username
  • Loading branch information
minrk authored Nov 29, 2018
2 parents 145fc55 + 15a546e commit 455432a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ If set to True, escape special chars in userdn when authenticating in LDAP.
On some LDAP servers, when userdn contains chars like '(', ')', '\' authentication may fail when those chars
are not escaped.

#### `LDAPAuthenticator.use_lookup_dn_username` ####

If set to True (the default) the username used to build the DN string is returned as the username when `lookup_dn` is True.

When authenticating on a Linux machine against an AD server this might return something different from the supplied UNIX username. In this case setting this option to False might be a solution.

## Compatibility ##

This has been tested against an OpenLDAP server, with the client
Expand Down
15 changes: 14 additions & 1 deletion ldapauthenticator/ldapauthenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,16 @@ def _server_port_default(self):
help="List of attributes to be searched"
)

use_lookup_dn_username = Bool(
True,
config=True,
help="""
If set to true uses the `lookup_dn_user_dn_attribute` attribute as username instead of the supplied one.
This can be useful in an heterogeneous environment, when supplying a UNIX username to authenticate against AD.
"""
)

def resolve_username(self, username_supplied_by_user):
search_dn = self.lookup_dn_search_user
if self.escape_userdn:
Expand Down Expand Up @@ -410,7 +420,10 @@ def authenticate(self, handler, data):
self.log.warn(msg.format(username=username))
return None

return username
if self.use_lookup_dn_username:
return username
else:
return data['username']


if __name__ == "__main__":
Expand Down

0 comments on commit 455432a

Please sign in to comment.