Dan*_*oin 5 python authentication django ldap openldap
我正在开发一个 Django 应用程序,它需要将 LDAP 身份验证直接支持到默认管理页面。
我已经集成了 django-auth-ldap 并按照文档进行操作,直到我能理解它为止。
我已经使用 OpenLDAP 和 php 图形界面配置了本地 LDAP 服务器(我也可以使用 ldif 文件配置)。当我尝试登录管理页面时,Django 会找到本地服务器和其中的用户对象,并且还会识别用户属于哪个组。尽管如此,我还是无法登录。我发现的错误:
[21/Aug/2014 11:06:53] "GET /admin/ HTTP/1.1" 200 1870
search_s('ou=users,dc=whiteqube', 2, '(cn=%(user)s)') 返回1 个对象:cn=sonia,ou=users,dc=whiteqube
DEBUG:django_auth_ldap:search_s('ou=users,dc=whiteqube', 2, '(cn=%(user)s)') 返回 1 个对象:cn= sonia,ou=users,dc=whiteqube sonia
身份验证失败
DEBUG:django_auth_ldap:sonia 身份验证失败
[21/Aug/2014 11:06:56] "POST /admin/ HTTP/1.1" 200 2046
在管理界面,只是登录失败。
我的设置.py:
# - - - - LDAP CONFIGURATION - - - - #
#
# Importing ldap libraries and applications
import ldap
from django_auth_ldap.config import LDAPSearch, GroupOfNamesType, PosixGroupType
# ...connecting to ldap server (local environment uses IP)
AUTH_LDAP_SERVER_URI = "ldap://10.0.2.15"
# ...account to enter into ldap server (anonymous is not always allowed)
#AUTH_LDAP_BIND_DN = "cn=admin,dc=whiteqube"
#AUTH_LDAP_BIND_PASSWORD = "root"
# ...path where to start to search groups
AUTH_LDAP_GROUP_SEARCH = LDAPSearch("ou=groups,dc=whiteqube",
ldap.SCOPE_SUBTREE, # allow searching from current node to all nodes below
"(objectClass=posixGroup)" # type of object
)
AUTH_LDAP_GROUP_TYPE = PosixGroupType() # a posixGroup is identified by the keyword "cn" into ldap server
# ...associations between ldap and django groups
AUTH_LDAP_USER_FLAGS_BY_GROUP = {
"is_active": "cn=active,ou=groups,dc=whiteqube",
"is_staff": "cn=staff,ou=groups,dc=whiteqube",
"is_superuser": "cn=superuser,ou=groups,dc=whiteqube"
}
AUTH_LDAP_PROFILE_FLAGS_BY_GROUPS = {
"is_awesome": ["cn=awesome,ou=groups,dc=whiteqube"]
}
# ...node where to start to search users
AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=users,dc=whiteqube",
ldap.SCOPE_SUBTREE, # allow searching from current node to all nodes below
"(cn=%(user)s)"
#"(objectClass=posixAccount)"
#"(objectClass=inetOrgPerson)"
)
# Keep ModelBackend around for per-user permissions and maybe a local
# superuser.
AUTHENTICATION_BACKENDS = (
'django_auth_ldap.backend.LDAPBackend',
'django.contrib.auth.backends.ModelBackend',
)
# Enable debug for ldap server connection
logger = logging.getLogger('django_auth_ldap')
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)
# - - - - END LDAP CONFIGURATION - - - - #
Run Code Online (Sandbox Code Playgroud)
我的 LDAP 充满了这些对象:
其中“groups”和“users”是OrganizationalUnit,“staff”和“superuser”是posixGroup,“sonia”是posixAccount。
查看图片

我确信 ldap 对象被配置为必须的,因为 Django 调试识别用户的组依赖。
Ps:当我使用 django 本地帐户时,我可以登录管理员。
我哪里错了?我错过了其他任何属性配置吗?
我终于成功了!调试:用户必须属于所有组(活动组、员工组、超级用户)才能登录管理界面,至少已创建一个新的个人组。
我上一篇文章中的 settings.py 和 LDAP 树的配置是正确的,因此您可以保留有关如何创建 LDAP 并在 django 应用程序中实现的信息。请记住:如果您使用默认组,请在所有组中添加用户以允许管理员登录。
谢谢。再见
| 归档时间: |
|
| 查看次数: |
4585 次 |
| 最近记录: |