0

I'm writing a web app with django and an Ldap backend to authenticate users. Authentication is done, and attribute mapping is also done with django-auth-ldap (thanks ...). But in the web interface, users need to update some informations like description, phone etc ...

So i need to retrive the dn attribute to update current user and not another. I try to map the distinguish name with and an attribute but not working... Any ideas ?

Please find below current code.

settings.py :

AUTH_LDAP_USER_ATTR_MAP = {
"dn" : "ldap_user.dn",
    "name": "cn",
    "description": "description",
    "employeeType": "employeeType",
    ... }

but no resutls...

And i try also to write in my view :

def update_description(request):
if request.method == "POST":
    form = DescriptionUpdateForm(request.POST)
    if form.is_valid():
        description = form.cleaned_data['description']
        user = request.user
        old_description = user.description
        user.description = description
        user.save()
        try:
            l = ldap.initialize(settings.AUTH_LDAP_SERVER_URI)
            l.simple_bind_s(settings.AUTH_LDAP_BIND_DN, settings.AUTH_LDAP_BIND_PASSWORD)
            user_ldap_dn = LDAPBackend().django_to_ldap_username(user.email).dn
            l.unbind_s()
        except ldap.LDAPError, e:
            print e
    return HttpResponseRedirect('/user/profile')
else:
    form = DescriptionUpdateForm()

return render(request, 'edit_description.html', {'form': form,})

But no result, i can't retrive the dn entry for this user...

Thanks in advance, Loic.

Loïc Chabert
  • 71
  • 1
  • 5

1 Answers1

0

The distinguished name (or primary key) is always returned from an LDAP search operation for each entry that matches the search parameters. The distinguished name is not an attribute.

Terry Gardner
  • 10,957
  • 2
  • 28
  • 38
  • Yes, for each ldap request, distinguished name has been return, but i use django-auth-ldap to authenticate users. And i need to store distinguished name in one attribute to limit the number of ldap request ... So i would like to store the distinguished name on mysqldb, and then retrive this information like another attributes. – Loïc Chabert Aug 13 '13 at 07:21