mirror of
https://github.com/retspen/webvirtcloud
synced 2026-03-22 02:24:56 +00:00
Check for ldap3 existence
This commit is contained in:
parent
fea2015153
commit
1fadb507f9
1 changed files with 7 additions and 12 deletions
|
|
@ -24,15 +24,17 @@ try:
|
||||||
'(&({attr}={login})({filter}))'.format(
|
'(&({attr}={login})({filter}))'.format(
|
||||||
attr=settings.LDAP_USER_UID_PREFIX,
|
attr=settings.LDAP_USER_UID_PREFIX,
|
||||||
login=username,
|
login=username,
|
||||||
filter=filterString), attributes=[settings.LDAP_USER_UID_PREFIX])
|
filter=filterString), attributes=['*'])
|
||||||
|
|
||||||
if len(connection.response) == 0:
|
if len(connection.response) == 0:
|
||||||
print('get_LDAP_user-no response')
|
print('get_LDAP_user-no response')
|
||||||
return None
|
return None
|
||||||
|
specificUser = connection.response[0]
|
||||||
return connection.response[0]
|
userDn = str(specificUser.get('raw_dn'),'utf-8')
|
||||||
except:
|
with Connection(server,
|
||||||
print('get_LDAP_user-error')
|
userDn,
|
||||||
|
password) as con:
|
||||||
|
return username
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def authenticate(self, request, username=None, password=None, **kwargs):
|
def authenticate(self, request, username=None, password=None, **kwargs):
|
||||||
|
|
@ -44,21 +46,14 @@ try:
|
||||||
isStaff = False
|
isStaff = False
|
||||||
|
|
||||||
if self.get_LDAP_user(username, password, settings.LDAP_SEARCH_GROUP_FILTER_ADMINS) is None:
|
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:
|
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:
|
if self.get_LDAP_user(username, password, settings.LDAP_SEARCH_GROUP_FILTER_USERS) is None:
|
||||||
print("authenticate-not user")
|
|
||||||
return None
|
return None
|
||||||
else:
|
|
||||||
print("authenticate-user")
|
|
||||||
else:
|
else:
|
||||||
isStaff = True
|
isStaff = True
|
||||||
print("authenticate-staff")
|
|
||||||
else:
|
else:
|
||||||
isAdmin = True
|
isAdmin = True
|
||||||
isStaff = True
|
isStaff = True
|
||||||
print("authenticate-admin")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
user = User.objects.get(username=username)
|
user = User.objects.get(username=username)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue