2018-11-26 16:18:56 +00:00
|
|
|
"""passbook LDAP Models"""
|
2018-11-11 12:41:48 +00:00
|
|
|
|
2019-10-10 15:36:09 +00:00
|
|
|
from django.core.validators import URLValidator
|
2018-11-26 16:18:56 +00:00
|
|
|
from django.db import models
|
|
|
|
from django.utils.translation import gettext as _
|
2018-11-11 12:41:48 +00:00
|
|
|
|
2019-10-10 15:36:09 +00:00
|
|
|
from passbook.core.models import Group, PropertyMapping, Source
|
2018-11-26 16:18:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
class LDAPSource(Source):
|
|
|
|
"""LDAP Authentication source"""
|
|
|
|
|
2019-10-11 10:53:48 +00:00
|
|
|
server_uri = models.TextField(validators=[URLValidator(schemes=['ldap', 'ldaps'])])
|
2018-11-26 16:18:56 +00:00
|
|
|
bind_cn = models.TextField()
|
|
|
|
bind_password = models.TextField()
|
2019-10-10 15:36:09 +00:00
|
|
|
start_tls = models.BooleanField(default=False)
|
2018-11-26 16:18:56 +00:00
|
|
|
|
|
|
|
base_dn = models.TextField()
|
2019-10-10 15:36:09 +00:00
|
|
|
additional_user_dn = models.TextField(help_text=_('Prepended to Base DN for User-queries.'))
|
|
|
|
additional_group_dn = models.TextField(help_text=_('Prepended to Base DN for Group-queries.'))
|
|
|
|
|
2019-10-11 11:41:12 +00:00
|
|
|
user_object_filter = models.TextField(default="(objectCategory=Person)", help_text=_(
|
|
|
|
'Consider Objects matching this filter to be Users.'))
|
|
|
|
user_group_membership_field = models.TextField(default="memberOf", help_text=_(
|
|
|
|
"Field which contains Groups of user."))
|
|
|
|
group_object_filter = models.TextField(default="(objectCategory=Group)", help_text=_(
|
|
|
|
'Consider Objects matching this filter to be Groups.'))
|
|
|
|
object_uniqueness_field = models.TextField(default="objectSid", help_text=_(
|
|
|
|
'Field which contains a unique Identifier.'))
|
2019-10-10 15:36:09 +00:00
|
|
|
|
|
|
|
sync_groups = models.BooleanField(default=True)
|
2019-10-11 10:53:48 +00:00
|
|
|
sync_parent_group = models.ForeignKey(Group, blank=True, null=True,
|
2019-10-10 15:36:09 +00:00
|
|
|
default=None, on_delete=models.SET_DEFAULT)
|
2018-11-26 16:18:56 +00:00
|
|
|
|
2019-10-13 14:47:05 +00:00
|
|
|
# This field is written to by the sync_* tasks
|
|
|
|
# displayed by additional_info
|
|
|
|
status = models.TextField(default="")
|
|
|
|
|
2019-10-07 14:33:48 +00:00
|
|
|
form = 'passbook.sources.ldap.forms.LDAPSourceForm'
|
2018-11-26 17:22:38 +00:00
|
|
|
|
2018-12-18 12:24:58 +00:00
|
|
|
@property
|
2019-10-13 14:47:05 +00:00
|
|
|
def additional_info(self):
|
|
|
|
return self.status
|
2018-12-18 12:24:58 +00:00
|
|
|
|
2018-11-26 16:18:56 +00:00
|
|
|
class Meta:
|
|
|
|
|
|
|
|
verbose_name = _('LDAP Source')
|
|
|
|
verbose_name_plural = _('LDAP Sources')
|
2018-11-11 12:41:48 +00:00
|
|
|
|
|
|
|
|
2019-10-10 15:36:09 +00:00
|
|
|
class LDAPPropertyMapping(PropertyMapping):
|
2019-10-11 10:53:48 +00:00
|
|
|
"""Map LDAP Property to User or Group object"""
|
2018-11-11 12:41:48 +00:00
|
|
|
|
2019-10-10 15:36:09 +00:00
|
|
|
ldap_property = models.TextField()
|
|
|
|
object_field = models.TextField()
|
2019-10-11 10:53:48 +00:00
|
|
|
|
|
|
|
form = 'passbook.sources.ldap.forms.LDAPPropertyMappingForm'
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return f"LDAP Property Mapping {self.ldap_property} -> {self.object_field}"
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
|
|
|
verbose_name = _('LDAP Property Mapping')
|
|
|
|
verbose_name_plural = _('LDAP Property Mappings')
|