This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
2018-11-11 12:41:48 +00:00
|
|
|
"""passbook LDAP Authentication Backend"""
|
|
|
|
from logging import getLogger
|
|
|
|
|
|
|
|
from django.contrib.auth.backends import ModelBackend
|
|
|
|
|
|
|
|
from passbook.ldap.ldap_connector import LDAPConnector
|
2018-11-26 17:12:04 +00:00
|
|
|
from passbook.ldap.models import LDAPSource
|
2018-11-11 12:41:48 +00:00
|
|
|
|
|
|
|
LOGGER = getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class LDAPBackend(ModelBackend):
|
|
|
|
"""Authenticate users against LDAP Server"""
|
|
|
|
|
|
|
|
def authenticate(self, **kwargs):
|
|
|
|
"""Try to authenticate a user via ldap"""
|
|
|
|
if 'password' not in kwargs:
|
|
|
|
return None
|
2018-11-26 17:12:04 +00:00
|
|
|
for source in LDAPSource.objects.filter(enabled=True):
|
|
|
|
_ldap = LDAPConnector(source)
|
|
|
|
user = _ldap.auth_user(**kwargs)
|
|
|
|
if user:
|
|
|
|
return user
|
|
|
|
return None
|