简体   繁体   English

使用ldap库的python中的LDAP身份验证问题

[英]LDAP authentication issue in python using ldap library

I am trying to connect to LDAP server for authentication. 我正在尝试连接到LDAP服务器进行身份验证。 Our LDAP server use SSL but we don't use any SSL certificate. 我们的LDAP服务器使用SSL,但是我们不使用任何SSL证书。

Following is my code: 以下是我的代码:

I have two url provided by system admin. 我有两个由系统管理员提供的网址。 There are as follows: 内容如下:

url1 = "ldap://100.x.x.x:389"
url2 = "ldaps://10.x.x.x:636"

My first questionis which url I should use ? 我的第一个问题是我应该使用哪个网址? what is difference between ldap:// and ldaps:// ldap://和ldaps://有什么区别

LDAP authentication code is as follows, I have tried to use both(url1 and url2): LDAP身份验证代码如下,我尝试同时使用(url1和url2):

conn = ldap.initialize(url)

ldap.TLS_AVAIL
1

conn.simple_bind_s(
        'CN={0},ou=users,DC=compnay,DC=com'.format(myemail),
        mypassword
    )

conn.simple_bind(
        'CN={0},ou=users,DC=compnay,DC=com'.format(myemail),
        mypassword
    )

if i used first url (url1) with simple_bind_s, then following is error: 如果我将第一个URL(url1)与simple_bind_s一起使用,则以下是错误:

INVALID_CREDENTIALS: {'info': u'80090308: LdapErr: DSID-0C0903D9, comment: AcceptSecurityContext error, data 52e, v2580', 'desc': u'Invalid credentials'} INVALID_CREDENTIALS:{'信息':u'80090308:LdapErr:DSID-0C0903D9,评论:AcceptSecurityContext错误,数据52e,v2580,'desc':u'无效的凭据'}

but when I use with simple_bind, it gives me int even though password or username is wrong. 但是当我与simple_bind一起使用时,即使密码或用户名错误,它也会为我提供int。

What is difference between simple_bind_s and simple_bind. simple_bind_s和simple_bind之间有什么区别。 How can I use simple_bind for authentication? 如何使用simple_bind进行身份验证?

The difference between simple_bind() and simple_bind_s() is that simple_bind() is asynchronous and simple_bind_s() is synchronous . 之间的差simple_bind()simple_bind_s()simple_bind()异步的simple_bind_s()同步的

The synchronous version makes your program wait until it is finished and then returns the results, where the asynchronous version returns an id code immediately and continues working in the background, and then later you call result() with the id code to get the results. 同步版本使您的程序等待其完成,然后返回结果,异步版本使程序立即返回ID代码,并在后台继续工作,然后,您稍后使用ID代码调用result()以获取结果。

So your call to simple_bind() likely did fail; 因此,您对simple_bind()调用可能确实失败了; you just don't know it because you haven't fetched the result yet. 您只是不知道,因为您尚未获取结果。

Most ldap functions have asynchronous and synchronous versions, such as add() and add_s() , delete() and delete_s() , search() and search_s() , etc. Some ldap operations (especially searching) can take a long time to complete, so you'd use the asynchronous versions if you don't want to your program to have long pauses. 大多数ldap函数具有异步和同步版本,例如add()add_s()delete()delete_s()search()search_s()等。某些ldap操作(尤其是搜索)可能需要很长时间才能完成完整,因此如果您不想让程序长时间停顿,则可以使用异步版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM