400 028 6601

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

通过python-ldap操作管理AD/LDAP用户及组织结构

LDAP/AD是两种应用最广泛的认证服务器,AD是微软基于LDAP开发而成的,应用于Windows平台,而LDAP主要应用于Linux平台(LDAP用在Windows平台比较少)。既然AD是基于LDAP的扩展,则LDAP大部分协议,AD均可原生支持,这位我们操作和管理AD认证服务器提供了大大的便利。

创新互联公司是一家专注于网站制作、做网站与策划设计,宜春网站建设哪家好?创新互联公司做网站,专注于网站建设10余年,网设计领域的专业建站公司;建站业务涵盖:宜春等地区。宜春做网站价格咨询:18982081108

在软件开发过程中,很多公司都采用AD/LDAP用于自己的用户认证体系,本文重点研究通过Python语言提供的Python-Ldap框架,来操作和管理AD/LDAP中的用户,组织结构等,希望对大家有所帮助。

基本概念:

o– organization(组织-公司)
ou – organization unit(组织单元/部门)
c - countryName(国家)
dc - domainComponent(域名组件)
sn – suer name(真实名称)
cn - common name(常用名称)
dn - distinguished name(唯一标识)

AD和LDAP中的字段及含义:


import ldap
def create_ad_user(username, unicode_password, org_dn):
    l = ldap.initialize('ldap://172.16.1.163:636') #use secure port default:636
    l.protocol_version = 3
    l.set_option(ldap.OPT_REFERRALS, 0)
    l.simple_bind_s('Administrator', 'P@ssword')
    user = {}
    user['objectclass'] = ['top', 'person', 'organizationalPerson', 'user']
    user_dn = 'cn=%s,%s' % (username,org_dn)
    user['userPrincipalName'] = '%s@%s' % (username, domain)
    user['userAccountControl'] = '66048' # active user account
    user['unicodePwd'] = unicode_password
    ldif = modlist.addModlist(user)
    ret, _ = l.add_s(user_dn, ldif)
    print ret

注意:AD和LDAP中如:创建用户,查询用户等操作,其使用端口和查询字段均有差异,还请格外注意,另外,代码如有不明确指出,欢迎留言讨论。


分享标题:通过python-ldap操作管理AD/LDAP用户及组织结构
网站地址:http://mbwzsj.com/article/pshdjo.html

其他资讯

让你的专属顾问为你服务