プロジェクト (Django 1.6、Python 2.7) でDjango-Auth-Ldapを使用しようとしていますが、機能していません。
私の Active Directory スキーマは次のとおりです。
ldap-utils パッケージをインストールして、コマンドラインで接続をテストしました
sudo apt-get install ldap-utils ldapsearch -H ldap://domain.com -D "ou=Resources,ou=Company, dc=domain,dc=com" -U "user_name" -w "user_password" -v -d 1
接続テストは問題なく動作します。
以下のコードを使用して、シェルからの python-ldap 接続をテストしています。
import ldap con = ldap.initialize('ldap://domain.com') con.simple_bind_s('User_mail', 'User_password') results = con.search_s('ou=Users,ou=Resources,ou=Company,dc=domain,dc=com', ldap.SCOPE_SUBTREE, "(cn=User_name)")
python-ldap 接続は正常に機能します。
- 私の問題は、django ログイン インターフェイスから AD ユーザーを認証する方法です。
settings.py:
import ldap
from django_auth_ldap.config import LDAPSearch
# The URL of the LDAP server.
AUTH_LDAP_SERVER_URI = "ldap://domain.com"
AUTH_LDAP_BIND_DN = "cn='User_name',ou=Resources,ou=Company,dc=domain,dc=com"
AUTH_LDAP_BIND_PASSWORD = "User_password"
AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=Users,ou=Resources,ou=Company,dc=domain,dc=com",ldap.SCOPE_SUBTREE, "(cn=%(user)s)")
AUTH_LDAP_GLOBAL_OPTIONS = { ldap.OPT_REFERRALS : False }
AUTHENTICATION_BACKENDS = (
'django_auth_ldap.backend.LDAPBackend',
'django.contrib.auth.backends.ModelBackend',
)
ビュー.py:
from django_auth_ldap.backend import LDAPBackend
auth = LDAPBackend()
user = auth.authenticate(username="User_name", password="User_password")
ファイル django-ldap-debug.log に次のエラーがあります。
Caught LDAPError while authenticating User_name: INVALID_CREDENTIALS({'info': '80090308: LdapErr: DSID-0C0903A9, comment: AcceptSecurityContext error, data 52e, v1db1', 'desc': 'Invalid credentials'},)