简体   繁体   中英

Testing authentication in Django

I'm trying to implement LDAP authentication in a test Django project. I think I've done all the configuration correctly (I'm using the django_ldap_auth package) and I want to test the authentication without having to create a whole site with log in etc. Is that possible? FYI, I'm only doing this as a part of making LDAP the main authentication method at my company, and have to plug the functionality into a large project.

I've tried running the server on localhost and ssh-ing through the terminal, but apparently that only logs me onto my own computer, I think:) (not an experienced Linux user).

Any suggestions?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM