From 1fadb507f94ee2ada18a9dec074e2f1bdf686191 Mon Sep 17 00:00:00 2001 From: Kendar Date: Fri, 28 May 2021 15:12:17 +0200 Subject: [PATCH] Check for ldap3 existence --- webvirtcloud/ldapbackend.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/webvirtcloud/ldapbackend.py b/webvirtcloud/ldapbackend.py index afae5bb..d926a36 100644 --- a/webvirtcloud/ldapbackend.py +++ b/webvirtcloud/ldapbackend.py @@ -24,15 +24,17 @@ try: '(&({attr}={login})({filter}))'.format( attr=settings.LDAP_USER_UID_PREFIX, login=username, - filter=filterString), attributes=[settings.LDAP_USER_UID_PREFIX]) + filter=filterString), attributes=['*']) if len(connection.response) == 0: print('get_LDAP_user-no response') return None - - return connection.response[0] - except: - print('get_LDAP_user-error') + specificUser = connection.response[0] + userDn = str(specificUser.get('raw_dn'),'utf-8') + with Connection(server, + userDn, + password) as con: + return username return None def authenticate(self, request, username=None, password=None, **kwargs): @@ -44,21 +46,14 @@ try: isStaff = False if self.get_LDAP_user(username, password, settings.LDAP_SEARCH_GROUP_FILTER_ADMINS) is None: - print("authenticate-not admin") if self.get_LDAP_user(username, password, settings.LDAP_SEARCH_GROUP_FILTER_STAFF) is None: - print("authenticate-not staff") if self.get_LDAP_user(username, password, settings.LDAP_SEARCH_GROUP_FILTER_USERS) is None: - print("authenticate-not user") return None - else: - print("authenticate-user") else: isStaff = True - print("authenticate-staff") else: isAdmin = True isStaff = True - print("authenticate-admin") try: user = User.objects.get(username=username)