Merge pull request #3614 from jumpserver/dev_ldap

[Update] 修改LDAP认证逻辑,密码为空时认证失败
pull/3618/head
BaiJiangJie 2020-01-09 11:18:12 +08:00 committed by GitHub
commit 84e5177ce2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -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)