Solved it :).
from django_auth_ldap.backend import LDAPBackend, _LDAPUser
from django.core.exceptions import ObjectDoesNotExist
from accounts.models import AllowedUsername
class CustomLDAPBackend(LDAPBackend):
def authenticate(self, username, password):
user = super(CustomLDAPBackend, self).authenticate(username, password)
if user is not None:
try:
allowed_user = AllowedUsername.objects.get(username=username)
except ObjectDoesNotExist:
return None
return user