Skip to content

Commit

Permalink
Merge pull request #16 from alandmoore/user-model-bugfix
Browse files Browse the repository at this point in the history
Use get_user_model to determine the user model
  • Loading branch information
sjkingo committed Jan 20, 2016
2 parents 37a4c7d + c139e27 commit 762e1b4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions django_auth_ldap3/backends.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from django_auth_ldap3.conf import settings

from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
from ldap3.core.exceptions import LDAPSocketOpenError
import hashlib
import ldap3
import logging

User = get_user_model()

logger = logging.getLogger('django_auth_ldap3')

class LDAPUser(object):
Expand Down Expand Up @@ -118,7 +120,7 @@ def get_user(self, user_id):
def check_group_membership(self, ldap_user, group_dn):
"""
Check the LDAP user to see if it is a member of the given group.

This is straightforward with OpenLDAP but tricky with AD as due to
the weird way AD handles "primary" group membership, we must test for
a separate attribute as well as the usual 'memberof' as the primary
Expand Down Expand Up @@ -147,7 +149,7 @@ def check_group_membership(self, ldap_user, group_dn):
settings.UID_ATTRIB, str(ldap_user), group_dn)
if pgt:
search_filter = '(|{}(&(cn={})(primaryGroupID={})))'.format(search_filter, ldap_user.cn, pgt)

# Return True if user is a member of group
r = self.search_ldap(ldap_user.connection, search_filter)
return r is not None
Expand Down

0 comments on commit 762e1b4

Please sign in to comment.