당신은 장고 LDAP 기능을 사용하여 모델에서 사용자를 저장 피할 수 있습니다. 해당 사용자의 자격 증명이 올 바르고 올바른 작업을 수행 할 수 있다면 LDAP 서버에 "요청"해야합니다. 사용자 이름을 변수 세션에 저장하고 모든 페이지의 특정 페이지로 리디렉션하고 사용자 이름과의 가변 세션
--SETTINGS.PY--
# 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)")
그럼 당신은 귀하의 의견에서 사용할 수 ..., 등등 정확하고, 검사를위한 특정 사용자가 존재 :
- -VIEWS.PY--
con = ldap.initialize("ldap://ldapserver")
con.simple_bind_s(userDN, passwordUser)
filter = '(sAMAccountName=' + "loginName" + ')'
user = con.search_s(base_dn, ldap.SCOPE_SUBTREE, filter, attrs)
con.unbind()