Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore username returned by resolve_username, use_lookup_dn_username configuration option added #105

Merged
merged 1 commit into from
Nov 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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