etianen/django-python3-ldap

ldap.has_user() method always return True

darkzq opened this issue · 1 comments

when I run python manage.py ldap_clean_users test001,
the username is not in AD, but has_user() return True, so it can not clean.

my setting:
LDAP_AUTH_SEARCH_BASE = "DC=y,DC=z"

AD Naming contexts:

  • Naming contexts:
    DC=y,DC=z
    CN=a,DC=y,DC=z
    CN=b,CN=c,DC=y,DC=z
    DC=d,DC=y,DC=z
    DC=f,DC=y,DC=z

if search DC=d,DC=y,DC=z,it will return False.
but I want search DC=y,DC=z

so I modify has_user() method , at least it works.

 def has_user(self, **kwargs):
        """
        Returns True if the user with the given identifier exists.

        The user identifier should be keyword arguments matching the fields
        in settings.LDAP_AUTH_USER_LOOKUP_FIELDS.
        """
        # Search the LDAP database.
        response = self._connection.search(
            search_base=settings.LDAP_AUTH_SEARCH_BASE,
            search_filter=format_search_filter(kwargs),
            search_scope=ldap3.SUBTREE,
            attributes=ldap3.ALL_ATTRIBUTES,
            get_operational_attributes=True,
            size_limit=1,
        )
        return True if self._connection.response[0].get("attributes") else False

Can you submit a PR with this change?