An LDAP database backend for Django
Project description
django-ldapdb is an LDAP database backend for Django, allowing to manipulate LDAP entries through Django models.
It supports most of the same APIs as a Django model:
MyModel.objects.create()
MyModel.objects.filter(x=1, y__contains=2)
Full admin support and browsing
django-ldapdb supports Django versions 1.8, 1.10 and 1.11, and Python 2.7/3.4/3.5.
Installing django-ldapdb
Use pip: pip install django-ldapdb
You might also need the usual LDAP packages from your distribution, usually named openldap or ldap-utils.
Using django-ldapdb
Add the following to your settings.py:
DATABASES = {
'ldap': {
'ENGINE': 'ldapdb.backends.ldap',
'NAME': 'ldap://ldap.nodomain.org/',
'USER': 'cn=admin,dc=nodomain,dc=org',
'PASSWORD': 'some_secret_password',
},
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
}
DATABASE_ROUTERS = ['ldapdb.router.Router']
If you want to access posixGroup entries in your application, you can add something like this to your models.py:
from ldapdb.models.fields import CharField, IntegerField, ListField
import ldapdb.models
class LdapGroup(ldapdb.models.Model):
"""
Class for representing an LDAP group entry.
"""
# LDAP meta-data
base_dn = "ou=groups,dc=nodomain,dc=org"
object_classes = ['posixGroup']
# posixGroup attributes
gid = IntegerField(db_column='gidNumber', unique=True)
name = CharField(db_column='cn', max_length=200, primary_key=True)
members = ListField(db_column='memberUid')
def __str__(self):
return self.name
def __unicode__(self):
return self.name
and add this to your admin.py:
from django.contrib import admin
from . import models
class LDAPGroupAdmin(admin.ModelAdmin):
exclude = ['dn', 'objectClass']
list_display = ['gid', 'name']
admin.site.register(models.LDAPGroup, LDAPGroupAdmin)
- Important note:
You must declare an attribute to be used as the primary key. This attribute will play a special role, as it will be used to build the Relative Distinguished Name of the entry.
For instance in the example above, a group whose cn is foo will have the DN cn=foo,ou=groups,dc=nodomain,dc=org.
Tuning django-ldapdb
It is possible to adjust django-ldapdb’s behavior by defining a few parameters in the DATABASE section:
- PAGE_SIZE (default: 1000)
Define the maximum size of a results page to be returned by the server
- QUERY_TIMEOUT (default: no limit)
Define the maximum time in seconds we’ll wait to get a reply from the server (on a per-query basis).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-ldapdb-0.9.0.tar.gz
.
File metadata
- Download URL: django-ldapdb-0.9.0.tar.gz
- Upload date:
- Size: 16.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fafa5f557aa12b99d3e14ce0f8d2a2c21259a38e70aeb0ed3f3d0d42cb9f6496 |
|
MD5 | 5d88258725106903fef51cd739212473 |
|
BLAKE2b-256 | 0847c2f0dbae74f6b7892fdfbd082cd3cf5c9ac8c2d6b29c4001574df291a6e2 |
File details
Details for the file django_ldapdb-0.9.0-py3-none-any.whl
.
File metadata
- Download URL: django_ldapdb-0.9.0-py3-none-any.whl
- Upload date:
- Size: 19.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4cc4ea5d74b398ad17abd679341d13bd468f246b254d19be3f1a22a968783983 |
|
MD5 | fc5b7eea88db22ff0dc7b1d7c28fbe3c |
|
BLAKE2b-256 | 147c59762db9d55a966aa6543d1ae5a5ee17e8691533fa02aec31906de0ecfd8 |