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

发布时间:2020-06-19 09:40:28 作者:Lee_1985
来源:网络 阅读:4613

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

在软件开发过程中,很多公司都采用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中如:创建用户,查询用户等操作,其使用端口和查询字段均有差异,还请格外注意,另外,代码如有不明确指出,欢迎留言讨论。

推荐阅读:
  1. 【MySQL】数据库闪回工具--binlog2sql
  2. MySQL看这一篇就够了

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

python ldap ad

上一篇:查看linux系统cpu信息的方法

下一篇:java怎么判断使用GET提交时是否乱码

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》