Testing authentication in Django

后端 未结 1 441
时光说笑
时光说笑 2021-02-05 13:33

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

相关标签:
1条回答
  • 2021-02-05 14:03

    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.

    0 讨论(0)
提交回复
热议问题