django-ldapdb
=============
.. image:: https://secure.travis-ci.org/django-ldapdb/django-ldapdb.png?branch=master
:target: http://travis-ci.org/django-ldapdb/django-ldapdb/
.. image:: https://img.shields.io/pypi/v/django-ldapdb.svg
:target: https://pypi.python.org/pypi/django-ldapdb/
:alt: Latest Version
.. image:: https://img.shields.io/pypi/pyversions/django-ldapdb.svg
:target: https://pypi.python.org/pypi/django-ldapdb/
:alt: Supported Python versions
.. image:: https://img.shields.io/pypi/wheel/django-ldapdb.svg
:target: https://pypi.python.org/pypi/django-ldapdb/
:alt: Wheel status
.. image:: https://img.shields.io/pypi/l/django-ldapdb.svg
:target: https://pypi.python.org/pypi/django-ldapdb/
:alt: License
``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 every upstream-supported Django version, based on
the `Django support policy <https://www.djangoproject.com/download/#supported-versions>`_.
For the current version, the following versions are supported:
- Django 2.2 (LTS), under Python 3.6 - 3.8 (Python 3.5 has reached its end of life);
- Django 3.0, under Python 3.6 - 3.8;
- Django 3.1, under Python 3.6 - 3.8.
- Django 4.1, under Python 3.6 - 3.8.
Installing django-ldapdb
------------------------
Linux
~~~~~
Use pip: ``pip install django-ldapdb``
You might also need the usual ``LDAP`` packages from your distribution, usually named ``openldap`` or ``ldap-utils``.
Windows
~~~~~~~
``django-ldapdb`` depends on the `python-ldap <https://pypi.python.org/pypi/python-ldap>` project.
Either follow `its Windows installation guide <https://www.python-ldap.org/en/latest/installing.html>`_,
or install a pre-built version from https://www.lfd.uci.edu/~gohlke/pythonlibs/#python-ldap
(choose the ``.whl`` file matching your Python/Windows combination, and install it with ``pip install python-ldap-3...whl``).
You may then install ``django-ldapdb`` with
``pip install django-ldapdb``
Using django-ldapdb
-------------------
Add the following to your ``settings.py``:
.. code-block:: python
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``:
.. code-block:: python
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``:
.. code-block:: python
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``.
Supported fields
----------------
djanglo-ldapdb provides the following fields, all imported from ``ldapdb.models.fields``:
Similar to Django:
* ``IntegerField``
* ``FloatField``
* ``BooleanField``
* ``CharField``
* ``ImageField``
* ``DateTimeField``
Specific to a LDAP server:
* ``ListField`` (holds a list of text values)
* ``TimestampField`` (Stores a datetime as a posix timestamp, typically for posixAccount)
Legacy:
* ``DateField`` (Stores a date in an arbitrary format. A LDAP server has no notion of ``Date``).
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).
.. note:: This setting applies on individual requests; if a high-level operation requires many
queries (for instance a paginated search yielding thousands of entries),
the timeout will be used on each individual request;
the overall processing time might be much higher.
Developing with a LDAP server
-----------------------------
When developing against a LDAP server, having access to a development LDAP server often proves
useful.
django-ldapdb uses the `volatildap project <https://pypi.org/project/volatildap>`_ for this purpose:
- A LDAP server is instantiated for each TestClass;
- Its content is reset at the start of each test function;
- It can be customized to embark any schemas required by the application;
- Starting with volatildap 1.4.0, the volatildap server can be controlled remotely, avoiding the need
to install a LDAP server on the host.
Applications using django-ldapdb may use the following code snippet when setting up their tests:
.. code-block:: python
# This snippet is released in the Public Domain
from django.conf import settings
from django.test import TestCase
import volatildap
class LdapEnabledTestCase(TestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.ldap = volatildap.LdapServer(
# Load some initial data
initial={'ou=people': {
'ou': ['people'],
'objectClass': ['organizationalUnit'],
}},
# Enable more LDAP schemas
schemas=['core.schema', 'cosine.schema', 'inetorgperson.schema', 'nis.schema'],
)
# The volatildap server uses specific defaults, and listens on an arbitrary port.
# Copy the server-side values to Django settings
settings.DATABASES['ldap']['USER'] = cls.ldap.rootdn
settings.DATABASES['ldap']['PASSWORD'] = cls.ldap.rootpw
settings.DATABASES['ldap']['NAME'] = cls.ldap.uri
def setUp(self):
super().setUp()
# Starting an already-started volatildap server performs a data reset
self.ldap.start()
@classmethod
def tearDownClass(cls):
# Free up resources on teardown.
cls.ldap.stop()
super().tearDownClass()
Raw data
{
"_id": null,
"home_page": "https://github.com/ifrn-oficial/suap-django-ldapdb",
"name": "suap-django-ldapdb",
"maintainer": "Diego Saraiva",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "diegosaraiva@gmail.com",
"keywords": "django, ldap, database, ldapdb",
"author": "Diego Saraiva",
"author_email": "diegosaraiva@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/d2/34/501bba10ea67cb7474993de26cf2029afcd8a228e47319e513bbc419def2/suap_django_ldapdb-1.5.3.dev1.tar.gz",
"platform": null,
"description": "django-ldapdb\n=============\n\n.. image:: https://secure.travis-ci.org/django-ldapdb/django-ldapdb.png?branch=master\n :target: http://travis-ci.org/django-ldapdb/django-ldapdb/\n\n.. image:: https://img.shields.io/pypi/v/django-ldapdb.svg\n :target: https://pypi.python.org/pypi/django-ldapdb/\n :alt: Latest Version\n\n.. image:: https://img.shields.io/pypi/pyversions/django-ldapdb.svg\n :target: https://pypi.python.org/pypi/django-ldapdb/\n :alt: Supported Python versions\n\n.. image:: https://img.shields.io/pypi/wheel/django-ldapdb.svg\n :target: https://pypi.python.org/pypi/django-ldapdb/\n :alt: Wheel status\n\n.. image:: https://img.shields.io/pypi/l/django-ldapdb.svg\n :target: https://pypi.python.org/pypi/django-ldapdb/\n :alt: License\n\n\n``django-ldapdb`` is an LDAP database backend for Django, allowing to manipulate\nLDAP entries through Django models.\n\nIt supports most of the same APIs as a Django model:\n\n* ``MyModel.objects.create()``\n* ``MyModel.objects.filter(x=1, y__contains=2)``\n* Full admin support and browsing\n\n\n``django-ldapdb`` supports every upstream-supported Django version, based on\nthe `Django support policy <https://www.djangoproject.com/download/#supported-versions>`_.\n\nFor the current version, the following versions are supported:\n\n- Django 2.2 (LTS), under Python 3.6 - 3.8 (Python 3.5 has reached its end of life);\n- Django 3.0, under Python 3.6 - 3.8;\n- Django 3.1, under Python 3.6 - 3.8.\n- Django 4.1, under Python 3.6 - 3.8.\n\n\nInstalling django-ldapdb\n------------------------\n\nLinux\n~~~~~\n\nUse pip: ``pip install django-ldapdb``\n\nYou might also need the usual ``LDAP`` packages from your distribution, usually named ``openldap`` or ``ldap-utils``.\n\n\nWindows\n~~~~~~~\n\n``django-ldapdb`` depends on the `python-ldap <https://pypi.python.org/pypi/python-ldap>` project.\nEither follow `its Windows installation guide <https://www.python-ldap.org/en/latest/installing.html>`_,\nor install a pre-built version from https://www.lfd.uci.edu/~gohlke/pythonlibs/#python-ldap\n(choose the ``.whl`` file matching your Python/Windows combination, and install it with ``pip install python-ldap-3...whl``).\n\nYou may then install ``django-ldapdb`` with\n\n``pip install django-ldapdb``\n\n\nUsing django-ldapdb\n-------------------\n\nAdd the following to your ``settings.py``:\n\n.. code-block:: python\n\n DATABASES = {\n 'ldap': {\n 'ENGINE': 'ldapdb.backends.ldap',\n 'NAME': 'ldap://ldap.nodomain.org/',\n 'USER': 'cn=admin,dc=nodomain,dc=org',\n 'PASSWORD': 'some_secret_password',\n },\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),\n },\n }\n DATABASE_ROUTERS = ['ldapdb.router.Router']\n\n\n\nIf you want to access posixGroup entries in your application, you can add\nsomething like this to your ``models.py``:\n\n\n.. code-block:: python\n\n from ldapdb.models.fields import CharField, IntegerField, ListField\n import ldapdb.models\n\n class LdapGroup(ldapdb.models.Model):\n \"\"\"\n Class for representing an LDAP group entry.\n \"\"\"\n # LDAP meta-data\n base_dn = \"ou=groups,dc=nodomain,dc=org\"\n object_classes = ['posixGroup']\n\n # posixGroup attributes\n gid = IntegerField(db_column='gidNumber', unique=True)\n name = CharField(db_column='cn', max_length=200, primary_key=True)\n members = ListField(db_column='memberUid')\n\n def __str__(self):\n return self.name\n\n def __unicode__(self):\n return self.name\n\nand add this to your ``admin.py``:\n\n.. code-block:: python\n\n from django.contrib import admin\n from . import models\n\n class LDAPGroupAdmin(admin.ModelAdmin):\n exclude = ['dn', 'objectClass']\n list_display = ['gid', 'name']\n\n admin.site.register(models.LDAPGroup, LDAPGroupAdmin)\n\n\n**Important note:**\n You **must** declare an attribute to be used as the primary key.\n This attribute will play a special role, as it will be used to build\n the Relative Distinguished Name of the entry.\n \n For instance in the example above, a group whose cn is ``foo``\n will have the DN ``cn=foo,ou=groups,dc=nodomain,dc=org``.\n\n\nSupported fields\n----------------\n\ndjanglo-ldapdb provides the following fields, all imported from ``ldapdb.models.fields``:\n\nSimilar to Django:\n\n * ``IntegerField``\n * ``FloatField``\n * ``BooleanField``\n * ``CharField``\n * ``ImageField``\n * ``DateTimeField``\n\nSpecific to a LDAP server:\n * ``ListField`` (holds a list of text values)\n * ``TimestampField`` (Stores a datetime as a posix timestamp, typically for posixAccount)\n\nLegacy:\n * ``DateField`` (Stores a date in an arbitrary format. A LDAP server has no notion of ``Date``).\n\n\nTuning django-ldapdb\n--------------------\n\nIt is possible to adjust django-ldapdb's behavior by defining a few parameters in the ``DATABASE`` section:\n\n``PAGE_SIZE`` (default: ``1000``)\n Define the maximum size of a results page to be returned by the server\n\n``QUERY_TIMEOUT`` (default: no limit)\n Define the maximum time in seconds we'll wait to get a reply from the server (on a per-query basis).\n\n .. note:: This setting applies on individual requests; if a high-level operation requires many\n queries (for instance a paginated search yielding thousands of entries),\n the timeout will be used on each individual request;\n the overall processing time might be much higher.\n\n\nDeveloping with a LDAP server\n-----------------------------\n\nWhen developing against a LDAP server, having access to a development LDAP server often proves\nuseful.\n\ndjango-ldapdb uses the `volatildap project <https://pypi.org/project/volatildap>`_ for this purpose:\n\n- A LDAP server is instantiated for each TestClass;\n- Its content is reset at the start of each test function;\n- It can be customized to embark any schemas required by the application;\n- Starting with volatildap 1.4.0, the volatildap server can be controlled remotely, avoiding the need\n to install a LDAP server on the host.\n\nApplications using django-ldapdb may use the following code snippet when setting up their tests:\n\n.. code-block:: python\n\n # This snippet is released in the Public Domain\n\n from django.conf import settings\n from django.test import TestCase\n\n import volatildap\n\n class LdapEnabledTestCase(TestCase):\n @classmethod\n def setUpClass(cls):\n super().setUpClass()\n cls.ldap = volatildap.LdapServer(\n # Load some initial data\n initial={'ou=people': {\n 'ou': ['people'],\n 'objectClass': ['organizationalUnit'],\n }},\n # Enable more LDAP schemas\n schemas=['core.schema', 'cosine.schema', 'inetorgperson.schema', 'nis.schema'],\n )\n # The volatildap server uses specific defaults, and listens on an arbitrary port.\n # Copy the server-side values to Django settings\n settings.DATABASES['ldap']['USER'] = cls.ldap.rootdn\n settings.DATABASES['ldap']['PASSWORD'] = cls.ldap.rootpw\n settings.DATABASES['ldap']['NAME'] = cls.ldap.uri\n\n def setUp(self):\n super().setUp()\n # Starting an already-started volatildap server performs a data reset\n self.ldap.start()\n\n @classmethod\n def tearDownClass(cls):\n # Free up resources on teardown.\n cls.ldap.stop()\n super().tearDownClass()\n",
"bugtrack_url": null,
"license": "BSD",
"summary": "A fork from django-ldapdb",
"version": "1.5.3.dev1",
"project_urls": {
"Homepage": "https://github.com/ifrn-oficial/suap-django-ldapdb"
},
"split_keywords": [
"django",
" ldap",
" database",
" ldapdb"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "23c9e2f178bef5da4fc10ae121eba3cfb3b3b0513287469400263485515560d9",
"md5": "ed4aed53f5036cfba3031522c49dbc41",
"sha256": "85114a1c62bcbba4fd4916e63f5dfe2d6883aa35e0b9ec99877073bec786170c"
},
"downloads": -1,
"filename": "suap_django_ldapdb-1.5.3.dev1-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "ed4aed53f5036cfba3031522c49dbc41",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=3.6",
"size": 23521,
"upload_time": "2024-11-11T14:46:59",
"upload_time_iso_8601": "2024-11-11T14:46:59.317280Z",
"url": "https://files.pythonhosted.org/packages/23/c9/e2f178bef5da4fc10ae121eba3cfb3b3b0513287469400263485515560d9/suap_django_ldapdb-1.5.3.dev1-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d234501bba10ea67cb7474993de26cf2029afcd8a228e47319e513bbc419def2",
"md5": "1cf1a03b8d53dce61475e0cfde12bcee",
"sha256": "2760128044ff6e6cc9a06cdf5997a586825a2ff445dd0321cc00c2d037b3a661"
},
"downloads": -1,
"filename": "suap_django_ldapdb-1.5.3.dev1.tar.gz",
"has_sig": false,
"md5_digest": "1cf1a03b8d53dce61475e0cfde12bcee",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 36166,
"upload_time": "2024-11-11T14:47:00",
"upload_time_iso_8601": "2024-11-11T14:47:00.512903Z",
"url": "https://files.pythonhosted.org/packages/d2/34/501bba10ea67cb7474993de26cf2029afcd8a228e47319e513bbc419def2/suap_django_ldapdb-1.5.3.dev1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-11 14:47:00",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ifrn-oficial",
"github_project": "suap-django-ldapdb",
"travis_ci": true,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "suap-django-ldapdb"
}