Looking at the documentation for django_auth_ldap , it looks like the module does not actually browse LDAP users and does not load them into the database. Instead, it authenticates the user against LDAP, and then adds or updates them to auth_users with the information that it receives from LDAP when the user logs on.
If you want to pre-populate the database with all users in Active Directory, then it looks like you need to write a script that directly requests AD and inserts users.
Something like this should start:
import ldap l = ldap.initialize('ldap://your_ldap_server') # or ldaps:// l.simple_bind_s("cn=a_user,dc=example,dc=fr") users = l.search_ext_s("memberOf=YourUserGroup",\ ldap.SCOPE_SUBTREE, \ "(sAMAccountName=a_user)", \ attrlist=["sAMAccountName", "displayName","mail"]) # users is now an array of members who match your search criteria. # *Each* user will look something like this: # [["Firstname"],["LastName"],["some@email.address"]] # Note that each field is in an array, even if there is only one value. # If you only want the first value from each, you can transform the results: # users = [[field[0] for field in user] for user in users] # That will transform each row into something like this: # ["Firstname", "Lastname", "some@email.address"] # TODO -- add to the database.
I left you a database update, since I have no information about your setup.
If you need more information on LDAP queries, check out LDAP questions here at Stackoverflow - and I also found this article for help .
Sean vieira
source share