Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use get_user_model to determine the user model #16

Merged
merged 1 commit into from
Jan 20, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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