【发布时间】:2023-03-04 19:28:01
【问题描述】:
我正在使用具有以下设置的 django-auth-ldap,因为 ldap 服务器上没有默认/全局“管理员”用户,它仅用于验证用户,用户自己可能会看到他们的用户信息。
AUTH_LDAP_BIND_AS_AUTHENTICATING_USER=True
在django-ldap-debug.log 中,当(作为登录用户)在视图LDAPBackend().populate_user(request.user.username) 中调用时出现以下错误
search_s('uid=vchrizz,ou=Users,dc=funkfeuer,dc=at', 0, '(objectClass=*)') raised NO_SUCH_OBJECT({'desc': 'No such object'},)
search_s('uid=vchrizz,ou=Users,dc=funkfeuer,dc=at', 0, '(objectClass=*)') returned 0 objects:
仅在登录时(使用来自django.contrib.auth.decorators 的login_required)它似乎返回一个用户对象:
search_s('uid=vchrizz,ou=Users,dc=funkfeuer,dc=at', 0, '(objectClass=*)') returned 1 objects: uid=vchrizz,ou=users,dc=funkfeuer,dc=at
然后我注意到,我需要设置
AUTH_LDAP_BIND_DN
AUTH_LDAP_BIND_PASSWORD
要摆脱错误,但首先我不想指定一个带密码的用户(因为 bind_as_authenticating_user),第二个 populate_user() 仍然返回 NoneType ...
为什么? ldap如何获取返回的用户信息?
我的目标是在我的自定义 /userinfo/ 视图中显示来自 ldap-user 的所有 ldap 用户信息,例如 uidNumber。 http://pastebin.com/VqGiwzFE
谢谢,克里斯
【问题讨论】:
-
我忘了让它工作:
user = auth.authenticate(username="theuser", password="thepass")自然我不想在这里硬编码用户凭据,所以我可以用request.user.username替换“theuser”,但不是密码,因为request.user.password是散列密码。由于密码在 POST 中的 /login/ 视图中,我想最好将(经过身份验证的)用户对象从 /login/ 视图获取到 /userinfo/ 视图中?但是我该怎么做呢? -
来自Django-AttributeError 'User' object has no attribute 'backend' (But…it does?) 我读到需要 auth.authenticate(),我想我需要这个:Re: Modify authentication backend 以某种方式将用户对象从登录视图获取到用户信息视图?
标签: python django ldap django-auth-ldap