1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-11-01 12:04:15 +00:00

fix indentation error for ldapbackend.py

This commit is contained in:
catborise 2021-06-15 13:44:05 +03:00
parent 990b69ac51
commit 18971f01a6
2 changed files with 30 additions and 28 deletions

View file

@ -11,33 +11,35 @@ try:
#/srv/webvirtcloud/ldap/ldapbackend.py #/srv/webvirtcloud/ldap/ldapbackend.py
class LdapAuthenticationBackend(ModelBackend): class LdapAuthenticationBackend(ModelBackend):
def get_LDAP_user(self, username, password, filterString): def get_LDAP_user(self, username, password, filterString):
print('get_LDAP_user') print('get_LDAP_user')
try: try:
server = Server(settings.LDAP_URL, port=settings.LDAP_PORT, server = Server(settings.LDAP_URL, port=settings.LDAP_PORT,
use_ssl=settings.USE_SSL,get_info=ALL) use_ssl=settings.USE_SSL,get_info=ALL)
connection = Connection(server, connection = Connection(server,
settings.LDAP_MASTER_DN, settings.LDAP_MASTER_DN,
settings.LDAP_MASTER_PW, auto_bind=True) settings.LDAP_MASTER_PW, auto_bind=True)
connection.search(settings.LDAP_ROOT_DN, connection.search(settings.LDAP_ROOT_DN,
'(&({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=['*']) 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] specificUser = connection.response[0]
userDn = str(specificUser.get('raw_dn'),'utf-8') userDn = str(specificUser.get('raw_dn'),'utf-8')
with Connection(server, with Connection(server,
userDn, userDn,
password) as con: password) as con:
return username return username
return None except:
return None
return None
def authenticate(self, request, username=None, password=None, **kwargs): def authenticate(self, request, username=None, password=None, **kwargs):
if not settings.LDAP_ENABLED: if not settings.LDAP_ENABLED:
return None return None
print("authenticate_ldap") print("authenticate_ldap")
@ -96,7 +98,7 @@ try:
print("authenticate-user created") print("authenticate-user created")
return user return user
def get_user(self, user_id): def get_user(self, user_id):
if not settings.LDAP_ENABLED: if not settings.LDAP_ENABLED:
return None return None
print("get_user_ldap") print("get_user_ldap")

View file

@ -110,7 +110,7 @@ DATABASES = {
AUTHENTICATION_BACKENDS = [ AUTHENTICATION_BACKENDS = [
"django.contrib.auth.backends.ModelBackend", "django.contrib.auth.backends.ModelBackend",
#"webvirtcloud.ldapbackend.LdapAuthenticationBackend", "webvirtcloud.ldapbackend.LdapAuthenticationBackend",
] ]
LOGIN_URL = "/accounts/login/" LOGIN_URL = "/accounts/login/"