Django Python - Ldap Authentication -
i work on django python . aim authenticate user ldap directory . have python code access ldap directory , retrieve information.
code :
import ldap try: l = ldap.open("ldap.forumsys.com") l.protocol_version = ldap.version2 username = "cn=read-only-admin,dc=example,dc=com" password = "password" l.simple_bind(username,password) except ldap.ldaperror,e: print e
my doubt , how implement in django? . how use these code in django , implement it?
thanks in advance
it same, have code specific search ldap (sam accountname usually) when want it, after submit call coming user´s login.
userdn = "" passworduser = "" base_dn = 'node start seach, ad structure' #attrs = ['description', 'telephonenumber', 'title', 'mail' , 'lastlogon', 'memberof', 'accountexpires',] attrs = [] def myaccount(request): con = ldap.initialize("ldap://ldapserver") con.simple_bind_s( userdn, passworduser ) filter = '(samaccountname=' + "loginname" + ')' user = con.search_s( base_dn, ldap.scope_subtree, filter, attrs ) con.unbind() userinfolist = [] key, value in user[0][1].items(): userinfolist += [userinfo(key, value)] return render_to_response('template.html',{'userinfolist':userinfolist, 'dnuser': user[0][0]}, context_instance = requestcontext(request))
in code below, specific template calling myaccount method, in method use ldap complement doing search on ldap, user authorized in dn doing searches. after recover info obtained search.
hope helps. doubt have, let me know :)
Comments
Post a Comment