From 98e10a1ca92ca43cc78d7c15b652b915ad75d5e9 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 26 Nov 2018 17:18:56 +0100 Subject: [PATCH] Move LDAP Source to DB --- passbook/ldap/migrations/0001_initial.py | 35 +++++++++++++++++++ passbook/ldap/migrations/__init__.py | 0 passbook/ldap/models.py | 34 +++++++++++++++--- passbook/oauth_provider/models.py | 2 +- .../migrations/0002_auto_20181126_1509.py | 2 +- passbook/saml_idp/models.py | 2 +- 6 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 passbook/ldap/migrations/0001_initial.py create mode 100644 passbook/ldap/migrations/__init__.py diff --git a/passbook/ldap/migrations/0001_initial.py b/passbook/ldap/migrations/0001_initial.py new file mode 100644 index 000000000..05cc550df --- /dev/null +++ b/passbook/ldap/migrations/0001_initial.py @@ -0,0 +1,35 @@ +# Generated by Django 2.1.3 on 2018-11-26 15:17 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('passbook_core', '0003_rule_order'), + ] + + operations = [ + migrations.CreateModel( + name='LDAPSource', + fields=[ + ('source_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='passbook_core.Source')), + ('server_uri', models.TextField()), + ('bind_cn', models.TextField()), + ('bind_password', models.TextField()), + ('type', models.CharField(choices=[('ad', 'ad'), ('generic', 'generic')], max_length=20)), + ('domain', models.TextField()), + ('base_dn', models.TextField()), + ('create_user', models.BooleanField(default=False)), + ('reset_password', models.BooleanField(default=True)), + ], + options={ + 'verbose_name': 'LDAP Source', + 'verbose_name_plural': 'LDAP Sources', + }, + bases=('passbook_core.source',), + ), + ] diff --git a/passbook/ldap/migrations/__init__.py b/passbook/ldap/migrations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/passbook/ldap/models.py b/passbook/ldap/models.py index 895281763..d8999af85 100644 --- a/passbook/ldap/models.py +++ b/passbook/ldap/models.py @@ -1,11 +1,37 @@ -# """Supervisr mod_ldap Models""" +"""passbook LDAP Models""" -# from django.contrib.auth.models import Group -# from django.db import models +from django.db import models +from django.utils.translation import gettext as _ -# from supervisr.core.fields import JSONField # from passbook.core.models import (CreatedUpdatedModel, ProductExtension, # UUIDModel) +from passbook.core.models import Source + + +class LDAPSource(Source): + """LDAP Authentication source""" + + TYPE_ACTIVE_DIRECTORY = 'ad' + TYPE_GENERIC = 'generic' + TYPES = ( + (TYPE_ACTIVE_DIRECTORY, TYPE_ACTIVE_DIRECTORY), + (TYPE_GENERIC, TYPE_GENERIC), + ) + + 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) + + class Meta: + + verbose_name = _('LDAP Source') + verbose_name_plural = _('LDAP Sources') # class LDAPModification(UUIDModel, CreatedUpdatedModel): diff --git a/passbook/oauth_provider/models.py b/passbook/oauth_provider/models.py index 6cb224beb..1a424ebae 100644 --- a/passbook/oauth_provider/models.py +++ b/passbook/oauth_provider/models.py @@ -1,9 +1,9 @@ """Oauth2 provider product extension""" +from django.utils.translation import gettext as _ from oauth2_provider.models import AbstractApplication from passbook.core.models import Provider -from django.utils.translation import gettext as _ class OAuth2Provider(Provider, AbstractApplication): diff --git a/passbook/saml_idp/migrations/0002_auto_20181126_1509.py b/passbook/saml_idp/migrations/0002_auto_20181126_1509.py index 9e4349ac2..0e73f33de 100644 --- a/passbook/saml_idp/migrations/0002_auto_20181126_1509.py +++ b/passbook/saml_idp/migrations/0002_auto_20181126_1509.py @@ -1,7 +1,7 @@ # Generated by Django 2.1.3 on 2018-11-26 15:09 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/passbook/saml_idp/models.py b/passbook/saml_idp/models.py index 9d3a0b4ae..1cedec787 100644 --- a/passbook/saml_idp/models.py +++ b/passbook/saml_idp/models.py @@ -1,11 +1,11 @@ """passbook saml_idp Models""" from django.db import models +from django.utils.translation import gettext as _ from passbook.core.models import Provider from passbook.lib.utils.reflection import class_to_path from passbook.saml_idp.base import Processor -from django.utils.translation import gettext as _ class SAMLProvider(Provider):