python flask_simpleldap无法绑定

2024-09-28 22:31:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用flask_simpleldap并正在努力获得一个绑定连接来执行任何有用的操作。在

我的LDAP服务器是active directory。在

精简后的代码如下所示,与the example几乎相同:

from flask import Flask
from flask_simpleldap import LDAP

app = Flask(__name__)
app.secret_key = 'super secret key'
app.debug = True

app.config['LDAP_HOST'] = 'my-ldap-host.example.com'
app.config['LDAP_REALM_NAME'] = 'LDAP Authentication'
app.config['LDAP_SCHEMA'] = 'ldaps'
app.config['LDAP_PORT'] = 636
app.config['LDAP_BASE_DN'] = 'dc=example,dc=com'
app.config['LDAP_USERNAME'] = 'binduser@example.com'
app.config['LDAP_PASSWORD'] = 'binduser_pw'

app.config['LDAP_OBJECTS_DN'] = 'distinguishedName'
app.config['LDAP_OPENLDAP'] = False

ldap = LDAP(app)


@app.route('/ldap')
@ldap.basic_auth_required
def ldap_protected():
    return 'Welcome, {0}!'.format(g.ldap_username)

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8080, debug=True)

当这个应用程序运行时,我会得到这样一个错误:

^{pr2}$

在尝试故障排除时,我修改了flask_simpleldap__init__.py文件,在line 274上显示info以及错误的{};现在我得到了有关该错误的更多信息:

LDAPException: 000004DC: LdapErr: DSID-0C090752, 
comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v2580

所以,我想我需要理解的是为什么我的初始绑定不起作用。。。我的app.config有什么问题吗?在

不知道问题是什么。。。ldapsearch似乎在shell中工作:

ldapsearch -x -LLL -E pr=200/noprompt -h my-ldap-host.example.com -D "binduser@example.com" -w 'binduser_pw' -b "dc=example, dc=com" -s sub  "(sAMAccountName=binduser)"    | grep distinguishedName


distinguishedName: CN=Bind User,OU=Some_OU,DC=example,DC=com

其他详细信息

  • 我试过python2.7和3.5,同样的问题
  • Centos 7.2公司
  • Active Directory是我的LDAP服务器

感谢任何帮助,谢谢。在


Tags: the服务器comconfigapphostflaskexample
2条回答

不确定这是否有用,但我已经设置了flask_simpleldap来处理我们的测试活动目录实例。唯一相关的区别是我必须使用:

app.config['LDAP_USE_SSL'] = True

我想我也看到了“操作错误”当我有无效的DN或用户名格式。在

您的用户名必须是完全限定的。在

app.config['LDAP_USERNAME'] = 'uid=binduser,dc=example,dc=com'

相关问题 更多 >