Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
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
9 changes: 5 additions & 4 deletions django_auth_ldap/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,13 +476,14 @@ def _authenticate_user_dn(self, password):
Binds to the LDAP server with the user's DN and password. Raises
AuthenticationFailed on failure.
"""
if self.dn is None:
if not self.settings.BIND_AS_AUTHENTICATING_USER and self.dn is None:
raise self.AuthenticationFailed("failed to map the username to a DN.")

try:
sticky = self.settings.BIND_AS_AUTHENTICATING_USER

self._bind_as(self.dn, password, sticky=sticky)
if self.settings.BIND_AS_AUTHENTICATING_USER:
self._bind_as(self._username, password, sticky=True)
else:
self._bind_as(self.dn, password)
except ldap.INVALID_CREDENTIALS:
raise self.AuthenticationFailed("user DN/password rejected by LDAP server.")

Expand Down