django - 配置 LDAP

标签 django ldap server

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

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

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

请告诉我是否应该发布任何额外的 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"}

设置.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。

关于django - 配置 LDAP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34754254/

相关文章:

django - Django |模型where子句

python - django:我如何实际覆盖管理站点模板

java - Apache 目录

java - 是否可以将ldap服务器直接连接到Android手机?

python - for 语句中的动态数组

python - Openshift Django 缩放

java - Liferay 通过 ext 插件对源代码进行的更改没有发生

node.js - Socket.IO:从客户端到服务器的发送是私有(private)的

c - C中的HTTP/1.0服务器,如何向客户端发送大文件?

python - 让python脚本在http简单服务器中运行