配置 LDAP

Configuring LDAP

我正在构建的应用程序需要 LDAP 身份验证。我通过 apache 托管我的应用程序,我正在使用 ssl...如果有帮助的话

我已经安装了所有库并遵循了基本的配置步骤,但是在尝试了一些 shell 相关测试之后,我什至无法连接到我的 ldap 服务器。

我以前从未这样做过,所以非常感谢您的帮助。

让我知道我是否应该 post 任何额外的 material。

主要教程:https://pythonhosted.org/django-auth-ldap/_static/versions/1.0.19/index.html

到目前为止我使用的测试:Testing authentication in Django

由于 ssl

将 ldap://128.114.119.108:636 更改为 ldaps://128.114.119.108:636
>>> import ldap
>>> server = 'ldaps://xxx.xxx.xxx.xxx:qqq'
>>> user_dn = 'uid=ajanakos,ou=people,dc=ucsc,dc=edu'
>>> password = 'xxxxxxxxx'
>>> con = ldap.initialize(server)
>>> con.simple_bind_s(user_dn, password)
SERVER_DOWN: {'info': 'TLS: hostname does not match CN in peer certificate', 'desc': "Can't contact LDAP server"}

settings.py

import ldap
from django_auth_ldap.config import LDAPSearch

AUTH_LDAP_SERVER_URI = "ldaps://xxx.xxx.xxx.xxx:qqq"

AUTH_LDAP_BIND_DN = ""
AUTH_LDAP_BIND_PASSWORD = ""
AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=people,dc=ucsc,dc=edu", ldap.SCOPE_SUBTREE, "(uid=%(user)s)")

AUTHENTICATION_BACKENDS = (
    'django_auth_ldap.backend.LDAPBackend',
    'django.contrib.auth.backends.ModelBackend',
)

views.py - 登录功能

from django.shortcuts import render
from models import search
from forms import Form
from dmca import settings
from django.contrib.auth import authenticate, login, logout
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth.decorators import login_required
import credentials as c
import base64
import psycopg2
import time
import datetime

# Create your views here.

def Login(request):
    if request.method == "POST":
        username = request.POST['username']
        password = request.POST['password']
        print 'text'
        user = authenticate(username=username, password=password)
        if user is not None:
            if user.is_active:
                login(request, user)
                return HttpResponseRedirect('/lookup')
            else:
                return HttpResponse("Inactive user.")
        else:
            return HttpResponseRedirect(settings.LOGIN_URL)

     return render(request, "dmca_app/login.html", {})

我注意到您正在尝试使用 LDAPS(即基于 TLS 的 LDAP)连接到 LDAP 服务器。这要求您配置的 TrustStore 至少包含用于验证服务器证书的证书。