diff --git a/gvaldap/gvaldap/settings/base.py b/gvaldap/gvaldap/settings/base.py index 6a5573d..17ddf14 100644 --- a/gvaldap/gvaldap/settings/base.py +++ b/gvaldap/gvaldap/settings/base.py @@ -216,6 +216,7 @@ DJANGO_APPS = ( # Apps specific for this project go here. LOCAL_APPS = ( + 'ldapentities', ) # See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps @@ -262,6 +263,12 @@ WSGI_APPLICATION = '%s.wsgi.application' % SITE_NAME ########## END WSGI CONFIGURATION +########## LDAP SETTINGS +GROUP_BASE_DN = get_env_setting('GVALDAP_BASEDN_GROUP') +USER_BASE_DN = get_env_setting('GVALDAP_BASEDN_USER') +########## END LDAP SETTINGS + + ########## SOUTH CONFIGURATION # See: http://south.readthedocs.org/en/latest/installation.html#configuring-your-django-installation INSTALLED_APPS += ( diff --git a/gvaldap/ldapentities/__init__.py b/gvaldap/ldapentities/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/gvaldap/ldapentities/admin.py b/gvaldap/ldapentities/admin.py new file mode 100644 index 0000000..8d46d8a --- /dev/null +++ b/gvaldap/ldapentities/admin.py @@ -0,0 +1,22 @@ +from django.contrib import admin + +from .models import ( + LdapGroup, + LdapUser, +) + + +class LdapGroupAdmin(admin.ModelAdmin): + exclude = ['dn', 'members'] + list_display = ['name', 'gid'] + search_fields = ['name'] + + +class LdapUserAdmin(admin.ModelAdmin): + exclude = ['dn', 'password'] + list_display = ['username', 'uid'] + search_fields = ['username'] + + +admin.site.register(LdapGroup, LdapGroupAdmin) +admin.site.register(LdapUser, LdapUserAdmin) diff --git a/gvaldap/ldapentities/models.py b/gvaldap/ldapentities/models.py new file mode 100644 index 0000000..21867b1 --- /dev/null +++ b/gvaldap/ldapentities/models.py @@ -0,0 +1,50 @@ +from django.conf import settings +from django.utils.encoding import python_2_unicode_compatible +from ldapdb.models.fields import ( + CharField, + IntegerField, + ListField, +) +import ldapdb.models as ldapmodels + + +@python_2_unicode_compatible +class LdapGroup(ldapmodels.Model): + """ + Class for representing an LDAP group entity. + + """ + # LDAP meta-data + base_dn = settings.GROUP_BASE_DN + 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', blank=True) + + def __str__(self): + return self.name + + +@python_2_unicode_compatible +class LdapUser(ldapmodels.Model): + """ + Class for representing an LDAP user entity. + + """ + base_dn = settings.USER_BASE_DN + object_classes = ['account', 'posixAccount'] + + # posixAccount + uid = IntegerField(db_column='uidNumber', unique=True) + group = IntegerField(db_column='gidNumber') + gecos = CharField(db_column='gecos') + home_directory = CharField(db_column='homeDirectory') + login_shell = CharField(db_column='loginShell', default='/bin/bash') + username = CharField(db_column='uid', primary_key=True) + password = CharField(db_column='userPassword') + common_name = CharField(db_column='cn') + + def __str__(self): + return self.username diff --git a/gvaldap/ldapentities/tests.py b/gvaldap/ldapentities/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/gvaldap/ldapentities/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here.