0
我是一個非常新的學習者使用活動目錄來獲取用戶數據,但獲取數據很困難。我已經爲此設置了所有環境。但如何獲取用戶數據?請幫幫我 。我需要活動目錄賬戶信息,組織數據如何從LDAP Active Directory獲取用戶數據?
我views.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"
}
將'retrieveAttributes'設置爲'None'應該在實踐中返回所有可用的屬性,但是您是否厭倦了定義一個字符串數組並將其傳入?如果你願意,你可以在構造函數中做到這一點: r = l.search_s(baseDN,searchScope,searchFilter,['cn','mail']) – X3074861X