implement LDAP group and user classes

- add app ldapentities
- add new settings GROUP_BASE_DN and USER_BASE_DN
- implement ldapentities.models.LdapUser and ldapentities.models.LdapGroup
- implement ldapentities.admin.LdapUserAdmin and
  ldapentities.models.LdapGroupAdmin
This commit is contained in:
Jan Dittberner 2014-05-30 01:07:25 +02:00
parent b736d5c041
commit 3babbc5b3f
5 changed files with 82 additions and 0 deletions

View file

@ -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 += (

View file

View file

@ -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)

View file

@ -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

View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.