From 1c9be184fd7f50d38fa0d93d7fe42df8c13d31e0 Mon Sep 17 00:00:00 2001 From: Bai Date: Thu, 9 Jan 2020 11:16:13 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E4=BF=AE=E6=94=B9LDAP=E8=AE=A4?= =?UTF-8?q?=E8=AF=81=E9=80=BB=E8=BE=91=EF=BC=8C=E5=AF=86=E7=A0=81=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA=E6=97=B6=E8=AE=A4=E8=AF=81=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/authentication/backends/ldap.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/authentication/backends/ldap.py b/apps/authentication/backends/ldap.py index bd1ce68b8..e01803707 100644 --- a/apps/authentication/backends/ldap.py +++ b/apps/authentication/backends/ldap.py @@ -27,13 +27,16 @@ class LDAPAuthorizationBackend(LDAPBackend): is_valid = getattr(user, 'is_valid', None) return is_valid or is_valid is None - def pre_check(self, username): + def pre_check(self, username, password): if not settings.AUTH_LDAP: return False logger.info('Authentication LDAP backend') if not username: logger.info('Authenticate failed: username is None') return False + if not password: + logger.info('Authenticate failed: password is None') + return False if settings.AUTH_LDAP_USER_LOGIN_ONLY_IN_USERS: user_model = self.get_user_model() exist = user_model.objects.filter(username=username).exists() @@ -44,7 +47,7 @@ class LDAPAuthorizationBackend(LDAPBackend): return True def authenticate(self, request=None, username=None, password=None, **kwargs): - match = self.pre_check(username) + match = self.pre_check(username, password) if not match: return None ldap_user = LDAPUser(self, username=username.strip(), request=request)