From 02137ec789a14704d816473e80fca3ee82621b45 Mon Sep 17 00:00:00 2001 From: xiaoc <648844981@qq.com> Date: Fri, 29 May 2026 17:59:02 +0800 Subject: [PATCH] fix: LDAP user login exception --- apps/authentication/backends/ldap.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/apps/authentication/backends/ldap.py b/apps/authentication/backends/ldap.py index 07ed50506..83e5ef8f1 100644 --- a/apps/authentication/backends/ldap.py +++ b/apps/authentication/backends/ldap.py @@ -186,6 +186,19 @@ class LDAPUser(_LDAPUser): else: self._user_dn = self._search_for_user_dn() + def _authenticate_user_dn(self, password): + if self.dn is None: + raise self.AuthenticationFailed("failed to map the username to a DN.") + + self._connection = None + self._connection_bound = False + + try: + sticky = self.settings.BIND_AS_AUTHENTICATING_USER + self._bind_as(self.dn, password, sticky=sticky) + except ldap.INVALID_CREDENTIALS: + raise self.AuthenticationFailed("user DN/password rejected by LDAP server.") + def _search_for_user_dn(self): """ This method was overridden because the AUTH_LDAP_USER_SEARCH