Search code examples
djangoldapdjango-authenticationpython-ldap

django_auth_ldap raises OPERATIONS_ERROR


I'm trying to build user authentication against our LDAP:

settings.py:

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

AUTH_LDAP_SERVER_URI = "ldap://********-dc01.*******.ru"

import ldap
from django_auth_ldap.config import LDAPSearch

AUTH_LDAP_BIND_DN = ""
AUTH_LDAP_BIND_PASSWORD = ""
AUTH_LDAP_USER_SEARCH = LDAPSearch("cn=users,dc=*********,dc=ru",ldap.SCOPE_SUBTREE,"(uid=%(user)s)")

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

import logging

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

views.py:

@login_required
def project_list(request):
...

urls.py:

(r'^accounts/login/$', 'django.contrib.auth.views.login',{'template_name':'login.html'}),

and the template is from this example.

It will take me to auth form and I get the following debug output:

search_s('cn=users,dc=********,dc=ru', 2, '(uid=bolotnov)') raised OPERATIONS_ERROR({'info': '000004DC: LdapErr: DSID-0C0906DC, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v1db0', 'desc': 'Operations error'},)
search_s('cn=users,dc=**********,dc=ru', 2, '(uid=bolotnov)') raised OPERATIONS_ERROR({'info': '000004DC: LdapErr: DSID-0C0906DC, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v1db0', 'desc': 'Operations error'},)
Authentication failed for bolotnov
Authentication failed for bolotnov

I tried googling but haven't found anything that could help me moth further, perhaps a hint from community - maybe there is something simple I'm missing or a check to do? I seem able to anonym bind to our ldap via Softerra LDAP browser maybe ldap_auth_user_search should be somewhat different?


Solution

  • although ldap_simple_bind_s() would return a successful bind, it's about referrals option that I had to disable to get that to work:

    ldap.set_option(ldap.OPT_REFERRALS, 0)