mirror of
https://github.com/retspen/webvirtcloud
synced 2024-11-01 03:54:15 +00:00
fix indentation error for ldapbackend.py
This commit is contained in:
parent
990b69ac51
commit
18971f01a6
2 changed files with 30 additions and 28 deletions
|
@ -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,
|
||||||
|
'(&({attr}={login})({filter}))'.format(
|
||||||
|
attr=settings.LDAP_USER_UID_PREFIX,
|
||||||
|
login=username,
|
||||||
|
filter=filterString), attributes=['*'])
|
||||||
|
|
||||||
|
if len(connection.response) == 0:
|
||||||
|
print('get_LDAP_user-no response')
|
||||||
|
return None
|
||||||
|
specificUser = connection.response[0]
|
||||||
|
userDn = str(specificUser.get('raw_dn'),'utf-8')
|
||||||
|
with Connection(server,
|
||||||
|
userDn,
|
||||||
|
password) as con:
|
||||||
|
return username
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
return None
|
||||||
|
|
||||||
connection.search(settings.LDAP_ROOT_DN,
|
def authenticate(self, request, username=None, password=None, **kwargs):
|
||||||
'(&({attr}={login})({filter}))'.format(
|
|
||||||
attr=settings.LDAP_USER_UID_PREFIX,
|
|
||||||
login=username,
|
|
||||||
filter=filterString), attributes=['*'])
|
|
||||||
|
|
||||||
if len(connection.response) == 0:
|
|
||||||
print('get_LDAP_user-no response')
|
|
||||||
return None
|
|
||||||
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):
|
|
||||||
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")
|
||||||
|
|
|
@ -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/"
|
||||||
|
|
Loading…
Reference in a new issue