开发者

Check multiple organizational units (ou) with django_auth_ldap

开发者 https://www.devze.com 2023-03-27 23:17 出处:网络
Our ldap is set up so that we have multiple different organizational units (ou). I currently have a django project using django_auth_ldap to connect to our ldap server so people can login with their l

Our ldap is set up so that we have multiple different organizational units (ou). I currently have a django project using django_auth_ldap to connect to our ldap server so people can login with their ldap credentials. However I can only get it to work for one ou when I need it to work with multiple ones. I currently have it set up as thus

import ldap
from django_auth_ldap.config import LDAPSearch

AUTH_LDAP_SERVER_URI = "ldap://ldap.example.net"
AUTH_LDAP_BIND_DN = ""
AUTH_LDAP_BIND_PASSWORD = ""
AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=people_1,dc=example,dc=net",
   ldap.SCOPE_SUBTREE, "(uid=%(user)s)")
AUTH_LDAP_USER_ATTR_MAP = {"first_name": "givenName",
                           "last_name": "sn",
                           "email": "email",
                           }

This works to get people from the people_1 group. How can I set it up so that it will also select from another container such as p开发者_如何转开发eople_2? I have tried just adding "ou=people_1,ou=people_2" which doesn't seem to work. I am still fairly new to understanding ldap so I apologize if this may be in fact something trivial to fix and just haven't been searching properly to find the answer. Took me awhile to just get django_auth_ldap just to work for me (extremely happy when I did!).


Change the base object to dc=example,dc=net: then the search scope of subtree you have specified will search all subtrees under dc=example,dc=net. For more information about the LDAP search request and response operations, see my blog entry "Using ldapsearch". Even though the examples use command-line tools, the concepts will assist you.

Also, as a good programming practice, you should supply a size limit and a time limit. The defaults for these parameters differ based on your API and may not suit your needs.

0

精彩评论

暂无评论...
验证码 换一张
取 消