[Fixed]-Testing authentication in Django

23👍

Go to your Django project folder and Start the python interpreter with

python manage.py shell

and then do,

from django_auth_ldap.backend import LDAPBackend

ldapobj = LDAPBackend()
user = ldapobj.populate_user(<LDAP username of an existing user>)
user.is_anonymous()

if the last function call returns false then it your LDAP auth module works as expected.

edit:

Run the Python interpreter as above and,

import ldap
server = 'ldap://<your server ip>'
user_dn = '<dn for a known user>'
password = '<his or her password>'
con = ldap.initialize(server)
con.simple_bind_s(user_dn, password)

This will return SERVER_DOWN: {‘desc’: “Can’t contact LDAP server”} exception, if you can’t connect to the LDAP sever.

👤vim

Leave a comment