我是使用 Active Directory 获取用户数据的新手,但获取数据有困难。我已经为此设置了所有环境。但是如何获取用户数据?请帮我 。我需要来自活动目录的帐户信息和组织数据
我的意见.py
def getLdapData(request):
try:
l = ldap.initialize("ldap://192.100.78.45")
username = "admin"
password = "Hxxxxxxx"
l.simple_bind(username, password)
except ldap.LDAPError, e:
print e
searchScope = ldap.SCOPE_SUBTREE
retrieveAttributes = None
baseDN = "dc=hashed,dc=local"
searchFilter = "dc=hashed,dc=local"
try:
ldap_result_id = l.search(baseDN, searchScope, searchFilter, retrieveAttributes)
print "ldap_result_id : " , ldap_result_id
result_set = []
i=1
while 1:
print i ," ",
i=i+1
result_type, result_data = l.result(ldap_result_id, 0)
schema_entry=l.search_subschemasubentry_s(baseDN)
m=l.get_option( ldap_result_id )
print m
if (result_data ==[]):
break
else:
result_set.append(result_data)
except ldap.LDAPError, e:
print" e---->"
print e
return HttpResponse(content=simplejson.dumps({
"schema_entry" : schema_entry,
"LdapData" : result_set, })
JSON输出:
LdapData: [
[
[
null,
[
"ldap://ForestDnsZones.hashed.local/DC=ForestDnsZones,DC=hashed,DC=local"
]
]
],
[
[
null,
[
"ldap://DomainDnsZones.hashed.local/DC=DomainDnsZones,DC=hashed,DC=local"
]
]
],
[
[
null,
[
"ldap://hashed.local/CN=Configuration,DC=hashed,DC=local"
]
]
]
],
schema_entry: "CN=Aggregate,CN=Schema,CN=Configuration,DC=hashed,DC=local"
}