# LDAP Configuration.
import ldap
from django_auth_ldap.config import LDAPSearch
AUTHENTICATION_BACKENDS = (
'django_auth_ldap.backend.LDAPBackend',
'django.contrib.auth.backends.ModelBackend',
)
# Binding and connection options.
# Address (by IP or Hostname) of LDAP Server (Directory Active)
AUTH_LDAP_SERVER_URI = "ldap://xxx.xxx.x.xxx"
# DN of user through we bind to LDAP Server.
AUTH_LDAP_BIND_DN = "CN=xxx, CN=xxx, DC=xxx, DC=xxx"
# Password of user through we bind to LDAP Server.
AUTH_LDAP_BIND_PASSWORD = "xxxxxx"
# Node where we start to search users. Use to be DN (of random user) without the last one parameter.
AUTH_LDAP_USER_SEARCH = LDAPSearch("CN=xxx, DC=xxx, DC=xxx", ldap.SCOPE_SUBTREE, "(samAccountName=%(user)s)")
您可以避免使用Django LDAP特性在模型中存储用户。你应该向你的LDAP服务器“询问”该用户的凭据是否正确,然后你就可以做你的事情:将用户名存储在一个可变会话中,重定向到特定的页面,在每个页面中,你可以检查带有用户名的变量会话是否正确,等等,。。。在
在设置.PY在
然后可以在视图中使用它,以检查是否存在特定用户:
在PY.PY视图在
^{pr2}$看看这个包裹: https://pythonhosted.org/django-auth-ldap/
在这个老岗位上: https://www.djm.org.uk/posts/using-django-auth-ldap-active-directory-ldaps/
相关问题 更多 >
编程相关推荐