This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/passbook/ldap/models.py

56 lines
1.5 KiB
Python
Raw Normal View History

2018-11-26 16:18:56 +00:00
"""passbook LDAP Models"""
2018-11-11 12:41:48 +00:00
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-03-10 18:45:16 +00:00
from passbook.core.models import Policy, Source, User
2018-11-26 16:18:56 +00:00
class LDAPSource(Source):
"""LDAP Authentication source"""
TYPE_ACTIVE_DIRECTORY = 'ad'
TYPE_GENERIC = 'generic'
TYPES = (
2018-11-26 21:09:04 +00:00
(TYPE_ACTIVE_DIRECTORY, _('Active Directory')),
(TYPE_GENERIC, _('Generic')),
2018-11-26 16:18:56 +00:00
)
server_uri = models.TextField()
bind_cn = models.TextField()
bind_password = models.TextField()
type = models.CharField(max_length=20, choices=TYPES)
domain = models.TextField()
base_dn = models.TextField()
create_user = models.BooleanField(default=False)
reset_password = models.BooleanField(default=True)
2018-11-26 17:22:38 +00:00
form = 'passbook.ldap.forms.LDAPSourceForm'
@property
def get_login_button(self):
raise NotImplementedError()
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-03-10 18:45:16 +00:00
class LDAPGroupMembershipPolicy(Policy):
"""Policy to check if a user is in a certain LDAP Group"""
2018-11-11 12:41:48 +00:00
2019-03-10 18:45:16 +00:00
dn = models.TextField()
source = models.ForeignKey('LDAPSource', on_delete=models.CASCADE)
2018-11-11 12:41:48 +00:00
2019-03-10 18:45:16 +00:00
form = 'passbook.ldap.forms.LDAPGroupMembershipPolicyForm'
2018-11-11 12:41:48 +00:00
2019-03-10 18:45:16 +00:00
def passes(self, user: User):
"""Check if user instance passes this policy"""
raise NotImplementedError()
2018-11-11 12:41:48 +00:00
2019-03-10 18:45:16 +00:00
class Meta:
2018-11-11 12:41:48 +00:00
2019-03-10 18:45:16 +00:00
verbose_name = _('LDAP Group Membership Policy')
verbose_name_plural = _('LDAP Group Membership Policys')