Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9247413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:43:14+00:00 2026-06-18T09:43:14+00:00

I am using OpenLDAP and I would like to connect it to Django using

  • 0

I am using OpenLDAP and I would like to connect it to Django using django_auth_ldap. Whatever option I am trying to follow, it never works properly and I can’t find the correct solution.

Here are the versions of the various softwares used:

  • OpenLDAP 20423 (LDAPv3)
  • Django 1.4.1 or 1.4.3 (I tried with both)
  • django_auth_ldap 1.1.3

My LDAP directory has a user called noc.noc that I am using to do the test.

I updated my settings.py file with the following lines:

import ldap, logging
from django_auth_ldap.config import LDAPSearch, PosixGroupType

.
.
.

logger = logging.getLogger('django_auth_ldap')
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG) 

AUTHENTICATION_BACKENDS = (
    'django_auth_ldap.backend.LDAPBackend',
    'django.contrib.auth.backends.ModelBackend',
)

AUTH_LDAP_SERVER_URI = "ldap://ldap.XXX.XX"
AUTH_LDAP_BIND_DN = "cn=<LDAPUSER>,dc=XXX,dc=XX"
AUTH_LDAP_BIND_PASSWORD = "<LDAPPASSWORD>"

AUTH_LDAP_USER_SEARCH = LDAPSearch("dc=XXX,dc=XX",
    ldap.SCOPE_SUBTREE, "(uid=%(user)s)")

AUTH_LDAP_GROUP_TYPE = PosixGroupType(name_attr='cn')
AUTH_LDAP_REQUIRE_GROUP = "cn=<USERGROUP>,ou=Groups,dc=XXX,dc=XX"

AUTH_LDAP_GROUP_SEARCH = LDAPSearch("ou=Groups,dc=XXX,dc=XX",
    ldap.SCOPE_SUBTREE, "(objectClass=posixGroup)"
)

AUTH_LDAP_USER_ATTR_MAP = {
    'first_name': 'givenName',
    'last_name': 'sn',
    'email': 'mail',
}

And I have the following log message when I try to connect with the noc.noc user on my Django interface:

search_s('dc=XXX,dc=XX', 2, '(uid=%(user)s)') returned 1 objects: 
cn=noc.noc,ou=users,dc=XXX,dc=XX
cn=noc.noc,ou=users,dc=XXX,dc=XX is not a member of cn=<USERGROUP>,ou=groups,dc=XXX,dc=XX
Authentication failed for noc.noc

If I remove the line:

AUTH_LDAP_REQUIRE_GROUP = "cn=<USERGROUP>,ou=Groups,dc=XXX,dc=XX"

The connection to the interface works, but it also work with any user in the LDAP database, which is not what I am looking for.

I also checked that the user is well in the ldap database and in the correct group with the following command:

ldapsearch -h 'ldap.XXX.XX' -D 'cn=<LDAPUSER>,dc=XXX,dc=XX' -w '<LDAPPASSWORD>' -b 'cn=<USERGROUP>,ou=Groups,dc=XXX,dc=XX'

And the result is:

# extended LDIF
#
# LDAPv3
# base <cn=<USERGROUP>,ou=Groups,dc=XXX,dc=XX> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#

# <USERGROUP>, Groups, XXX.XX
dn: cn=<USERGROUP>,ou=Groups,dc=XXX,dc=XX
cn: <USERGROUP>
gidNumber: 501
memberUid: cn=user1,ou=Users,dc=XXX,dc=XX
memberUid: cn=noc.noc,ou=Users,dc=XXX,dc=XX
objectClass: posixGroup

# search result
search: 2
result: 0 Success

# numResponses: 2
# numEntries: 1

I tried other parameters in settings.py and look for similar problem on the web but no solution I read solved my problem.

Thanks a lot for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:43:15+00:00Added an answer on June 18, 2026 at 9:43 am

    Django-auth-ldap is using the CN to identify a group member instead of the DN. For this reason, the solution is to replace:

    cn=noc.noc,ou=Users,dc=XXX,dc=XX
    

    in the memberUid field of the group in LDAP by:

    noc.noc
    

    This solves the issue.

    Another solution would be to modify the sources of django-auth-ldap. To do so you have to edit the file config.py (found in /usr/local/lib/python2.6/dist-packages/django-auth-ldap on my installation) and find the function called:

    def user_groups(self, ldap_user, group_search):
    

    of the class:

    class PosixGroupType(LDAPGroupType):
    

    then replace the line:

    user_uid = ldap_user.attrs['uid'][0]
    

    by:

    user_uid = ldap_user.dn
    

    This should also do the trick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to pull an LDAP jpegPhoto attribute from an openLDAP server using
I am trying to test a connection to AD using OpenLDAP and this is
I am trying to update user details like firstName, lastName, emailAddress especially using Seam's
I am using spring ldap to connect to OpenLdap. Wondering if there is any
I am trying to use LDAP for authentication. I am using the OpenLDAP library
I am using Openldap 2.4.11 in Fedora Core 13. I am trying to create
I'm trying to cross compile openldap-2.4.23 on my Ubuntu 10.10 development machine using the
I'm using Ubuntu 10.4 server and I'm trying to configure OpenLDAP as a protocol
I am using the System.DirectoryServices.Protocols functions to query an openldap directory. The openldap directory
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.