Setting up and testing ldap connection

878 views
Skip to first unread message

Bernhard Posselt

unread,
Jan 11, 2011, 7:29:23 PM1/11/11
to django-auth-ldap
Hi i have some problems setting up a connection. This is my current
config:

http://paste.pocoo.org/show/319187/

and i try to print all the Users loginnames like this:

def show_users(request):
users = User.objects.all()
return render_to_response('printer/users.html', {"users": users})

{% for user in users %}
{{ user.first_name }}
{% endfor %}


The thing is i dont get any output at all. Do i even get a connection?
Is there any way to test this if i even got the correct settings (took
over an ldap server for samba auth)?

Peter Sagerson

unread,
Jan 11, 2011, 8:02:41 PM1/11/11
to django-a...@googlegroups.com
You shouldn't expect to see any users in your Django database just by setting up LDAP auth. Every time a user logs in, the backend will look for a matching Django user, creating it if necessary. Until the first time a user logs in, Django will be unaware of them.

If you'd like to populate a user from LDAP without having them log in, you can use the populate_user API[1], which was added by request in 1.0.3. There is currently no way to scan the LDAP directory and pre-populate all possible users, although you should be able to whip something like that up fairly quickly if you'd like.


[1] http://packages.python.org/django-auth-ldap/#django_auth_ldap.backend.LDAPBackend.populate_user

Bernhard Posselt

unread,
Jan 11, 2011, 8:49:31 PM1/11/11
to django-auth-ldap
I basically dont want authorization, just fetching all users from the
ldap server. If I could get auth working it wouldnt be bad either.

Btw, Id be gratefull if anyone could mention how to import the Backend
in the docs and how to use the populate. I figured it out after 30 min
that i had to add the app directory as installed apps (although its
mentioned as not necessary, only because of unittests in the docs).

Im really not fluent with ldap and this interface is just overkill for
me. Can I use django_auth_ldap or do i have to use python-ldap to
fetch all usernames from the group Users?

On Jan 12, 2:02 am, Peter Sagerson <psag...@ignorare.net> wrote:
> You shouldn't expect to see any users in your Django database just by setting up LDAP auth. Every time a user logs in, the backend will look for a matching Django user, creating it if necessary. Until the first time a user logs in, Django will be unaware of them.
>
> If you'd like to populate a user from LDAP without having them log in, you can use the populate_user API[1], which was added by request in 1.0.3. There is currently no way to scan the LDAP directory and pre-populate all possible users, although you should be able to whip something like that up fairly quickly if you'd like.
>
> [1]http://packages.python.org/django-auth-ldap/#django_auth_ldap.backend...

Peter Sagerson

unread,
Jan 11, 2011, 9:12:50 PM1/11/11
to django-a...@googlegroups.com
I tend to agree that this is not the library you're looking for. If you just want to query your LDAP directory for a list of users, I would recommend learning the python-ldap interface; it's pretty simple for this sort of task. In rough terms, a basic LDAP search looks like this:

connection = ldap.initialize(uri)
connection.simple_bind_s(dn, password)
results = connection.search_s(base_dn, scope, filterstr)

Bernhard Posselt

unread,
Jan 11, 2011, 9:14:10 PM1/11/11
to django-auth-ldap
I'll take a look at that then. Thanks so far!

Jeff Schroeder

unread,
Jan 11, 2011, 11:06:11 PM1/11/11
to django-a...@googlegroups.com, django-a...@googlegroups.com
Also, you could use django-ldapdb, which is almost exactly like the django orm, but performs native ldap queries. It will not perform user authentication like django-auth-ldap, but will let you create a models.py where the models are actually entries in ldap.

Sent from my iPhone

Jeff Schroeder

unread,
Jan 11, 2011, 11:08:54 PM1/11/11
to django-a...@googlegroups.com, django-a...@googlegroups.com
django-ldapdb literally treats your ldap tree like django treats your models in a database.

Upstream is very helpful and responsive. I even managed to get a small patch merged in it. Very well written code.

http://opensource.bolloretelecom.eu/projects/django-ldapdb/

Sent from my iPhone

Bernhard Posselt

unread,
Jan 12, 2011, 5:27:00 PM1/12/11
to django-auth-ldap
TY!

I love you :D

That was exactly what ive been looking for!

On Jan 12, 5:08 am, Jeff Schroeder <jeffschr...@gmail.com> wrote:
> django-ldapdb literally treats your ldap tree like django treats your models in a database.
>
> Upstream is very helpful and responsive. I even managed to get a small patch merged in it. Very well written code.
>
> http://opensource.bolloretelecom.eu/projects/django-ldapdb/
>
> Sent from my iPhone
>

Di majo

unread,
May 12, 2024, 3:46:55 PM5/12/24
to django-auth-ldap
MT103/202 DIRECT WIRE TRANSFER
PAYPAL TRANSFER
CASHAPP TRANSFER
ZELLE TRANSFER
LOAN DEAL
TRANSFER WISE
WESTERN UNION TRANSFER
BITCOIN FLASHING
BANK ACCOUNT LOADING/FLASHING
IBAN TO IBAN TRANSFER
MONEYGRAM TRANSFER
IPIP/DTC
SLBC PROVIDER
CREDIT CARD TOP UP
DUMPS/ PINS
SEPA TRANSFER
WIRE TRANSFER
BITCOIN TOP UP
GLOBALPAY INC US
SKRILL USA
UNIONPAY RECEIVER

Thanks.


NOTE; ONLY SERIOUS / RELIABLE RECEIVERS CAN CONTACT.

DM ME ON WHATSAPP
+44 7529 555638
Reply all
Reply to author
Forward
0 new messages