Exemplo n.º 1
0
# coding:utf-8
#

import ldap
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
from django_auth_ldap.backend import _LDAPUser, LDAPBackend
from django_auth_ldap.config import _LDAPConfig, LDAPSearch, LDAPSearchUnion

logger = _LDAPConfig.get_logger()


class LDAPAuthorizationBackend(LDAPBackend):
    """
    Override this class to override _LDAPUser to LDAPUser
    """

    def authenticate(self, request=None, username=None, password=None, **kwargs):
        if password or self.settings.PERMIT_EMPTY_PASSWORD:
            ldap_user = LDAPUser(self, username=username.strip(), request=request)
            user = self.authenticate_ldap_user(ldap_user, password)
        else:
            logger.debug('Rejecting empty password for {}'.format(username))
            user = None

        return user

    def get_user(self, user_id):
        user = None

        try:
Exemplo n.º 2
0
import ldap

import django
import django.conf
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group, Permission
from django.core.cache import cache
from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
import django.dispatch
from django.utils import six
from django.utils.encoding import force_str

from django_auth_ldap.config import ConfigurationWarning, LDAPGroupQuery, LDAPSearch, _LDAPConfig


logger = _LDAPConfig.get_logger()


# Exported signals

# Allows clients to perform custom user population.
populate_user = django.dispatch.Signal(providing_args=["user", "ldap_user"])

# Allows clients to inspect and perform special handling of LDAPError
# exceptions. Exceptions raised by handlers will be propagated out.
ldap_error = django.dispatch.Signal(providing_args=['context', 'user', 'exception'])


class LDAPBackend(object):
    """
    The main backend class. This implements the auth backend API, although it