繁体   English   中英

将 ldapsearch 命令转换为 flask_ldap3_login 设置的问题

[英]Issue with transform ldapsearch command to flask_ldap3_login settings

我在将ldapsearch命令转换为flask_ldap3_login设置时遇到问题。

要检查从 Linux 服务器到 LDAP 的连接,我使用以下命令

ldapsearch -x -b "ou=intranet,dc=mydreamcorporation,dc=com" -H ldap://ids.mydream-corporation.com -D "myguid=myusername,ou=people,ou=intranet,dc=dreamcorporation,dc=com" -W "uid=myusername" cn uid

来自 LDAP 的回复

扩展的 LDIF
LDAPv3
基础 <ou=intr.net,dc=mydreamcorporation,dc=com> 与 scope 子树
过滤器:uid=我的用户名
请求:cn uid
我的用户名, 人, intr.net, mydreamcorporation.com
dn: myguid=我的用户名,ou=人,ou=intr.net,dc=mydreamcorporation,dc=com
cn: 我的名字
uid:我的用户名
搜索结果
搜索:2
结果:0 成功
numResponses:2
条目数:1

我的 flask_ldap3_login 设置

from flask import Flask, url_for
from flask_ldap3_login import LDAP3LoginManager
from flask_login import LoginManager, login_user, UserMixin, current_user
from flask import render_template_string, redirect
from flask_ldap3_login.forms import LDAPLoginForm

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret'
app.config['DEBUG'] = True

my_login = "myusername"
my_password = "password"

# Hostname of your LDAP Server
app.config['LDAP_HOST'] = 'ldap://ids.mydream-corporation.com'

# Port number of your LDAP server
app.config['LDAP_PORT'] = 389

# Base DN of your directory
app.config['LDAP_BASE_DN'] = "dc=mydreamcorporation,dc=com"

# Users DN to be prepended to the Base DN
app.config['LDAP_USER_DN'] = "ou=intranet"

# Groups DN to be prepended to the Base DN
app.config['LDAP_GROUP_DN'] = 'ou=people'

# The RDN attribute for your user schema on LDAP 
app.config['LDAP_USER_RDN_ATTR'] = 'dn' 

# The Attribute you want users to authenticate to LDAP with. 
app.config['LDAP_USER_LOGIN_ATTR'] = 'myguid' 

# The Username to bind to LDAP with 
app.config['LDAP_BIND_USER_DN'] = "myguid=myusername,ou=people,ou=intranet,dc=mydreamcorporation,dc=com"

# The Password to bind to LDAP with 
app.config['LDAP_BIND_USER_PASSWORD'] = my_password 

login_manager = LoginManager(app)              # Setup a Flask-Login Manager
ldap_manager = LDAP3LoginManager(app)          # Setup a LDAP3 Login Manager

@app.route('/', methods=['POST','GET'])
def manual_login(my_login=my_login, my_password=my_password):
    result = app.ldap3_login_manager.authenticate(my_login, my_password)
    return str(result.status)

不幸的是我有一个脚本结果

AuthenticationResponseStatus.失败

我认为问题出在错误的配置上,但我找不到哪里:(

我试图添加:

app.config['LDAP_USER_SEARCH_SCOPE'] = 'SUBTREE'
app.config['LDAP_ALWAYS_SEARCH_BIND'] = 1

但它没有帮助,我有一条消息:

objectClass 属性中的无效 class:组

在 Gabriel Luci 发表评论后,我将设置更改为:

app.config['LDAP_BASE_DN'] = "ou=intranet"
app.config['LDAP_USER_DN'] = "myguid=myusername,ou=people,ou=intranet,dc=mydreamcorporation,dc=com"
#app.config['LDAP_GROUP_DN'] = 'ou=people'
app.config['LDAP_USER_RDN_ATTR'] = 'cn' 
app.config['LDAP_USER_LOGIN_ATTR'] = 'uid' 
app.config['LDAP_BIND_USER_DN'] = "myguid=myusername"

现在我有同样的

AuthenticationResponseStatus.失败

在控制台中:

LDAPInvalidCredentialsResult - 49 - invalidCredentials - 无 - 无 - bindResponse - 无

我有问题的答案。 问题通过添加解决: app.config['LDAP_SEARCH_FOR_GROUPS'] = False

最终配置:

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret'
app.config['DEBUG'] = True

my_login = "myusername"
my_password = "password"

app.config['LDAP_HOST'] = 'ldaps://ids.mydream-corporation.com'
app.config['LDAP_PORT'] = 636
app.config['LDAP_BASE_DN'] = "dc=mydreamcorporation,dc=com"
app.config['LDAP_USER_DN'] = "ou=people,ou=intranet"
app.config['LDAP_USER_LOGIN_ATTR'] = 'myguid'
app.config['LDAP_BIND_USER_DN'] = "myguid=myusername,ou=people,ou=intranet,dc=mydreamcorporation,dc=com"
app.config['LDAP_BIND_USER_PASSWORD'] = my_password
app.config['LDAP_USER_SEARCH_SCOPE'] = 'SUBTREE'
app.config['LDAP_SEARCH_FOR_GROUPS'] = False

login_manager = LoginManager(app)              # Setup a Flask-Login Manager
ldap_manager = LDAP3LoginManager(app)          # Setup a LDAP3 Login Manager

@app.route('/', methods=['POST','GET'])
def manual_login(my_login=my_login, my_password=my_password):
    result = app.ldap3_login_manager.authenticate(my_login, my_password)
    return str(result.status)

最后我有一个脚本结果

AuthenticationResponseStatus.成功

您标记active-directory ,但我怀疑您可能没有使用 AD,因为您使用的是uid ,而 AD 中没有使用它。

LDAP_HOSTLDAP_PORT看起来正确。

您已将LDAP_BASE_DN设置为域的根目录,但在ldapsearch命令中,将其设置为intranet OU。 为什么有区别?

您设置LDAP_USER_DN的方式告诉它您所有的用户对象都在ou=intranet,dc=mydreamcorporation,dc=com中。 那是你的意图吗?

您设置LDAP_GROUP_DN的方式告诉它所有组对象都在ou=people,dc=mydreamcorporation,dc=com中。 这看起来很可疑。 我不认为这是你想要的。

您已将LDAP_USER_RDN_ATTR设置为dn ,但如果您使用的是 Active Directory,则根据 Microsoft应该是cn

您已将LDAP_USER_LOGIN_ATTR设置为myguid ,但这看起来很可疑。 这应该是代表用户将用于登录的用户名的属性。 在 AD 中,这将是sAMAccountNameuserPrincipalName 如果您使用其他一些 LDAP 服务器,它可能是uid

暂无
暂无

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

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