Jan Dittberner
72f5d78c10
- add passlib to requirements/base.txt - implement ldapentities.models.LdapUser.set_password
56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
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
|
|
|
|
from passlib.hash import ldap_salted_sha1
|
|
|
|
|
|
@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
|
|
|
|
def set_password(self, password):
|
|
self.password = ldap_salted_sha1.encrypt(password)
|