From 9cccc0a75756336fcc7e1ce6904ed809b4261457 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 9 Dec 2018 23:06:14 +0100 Subject: [PATCH] saml_idp: Add Certificate, Key and other settings to DB --- passbook/saml_idp/base.py | 2 +- passbook/saml_idp/forms.py | 15 ++++++- .../migrations/0004_auto_20181209_2202.py | 41 +++++++++++++++++++ passbook/saml_idp/models.py | 13 +++++- 4 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 passbook/saml_idp/migrations/0004_auto_20181209_2202.py diff --git a/passbook/saml_idp/base.py b/passbook/saml_idp/base.py index 68f9e6c1d..661b9f72e 100644 --- a/passbook/saml_idp/base.py +++ b/passbook/saml_idp/base.py @@ -188,7 +188,7 @@ class Processor: 'acs_url': self._request_params['ACS_URL'], 'saml_response': self._saml_response, 'relay_state': self._relay_state, - 'autosubmit': CONFIG.y('saml_idp.autosubmit', False), + 'autosubmit': False, # TODO: use autosubmit from application } def _parse_request(self): diff --git a/passbook/saml_idp/forms.py b/passbook/saml_idp/forms.py index a350367a4..797c16896 100644 --- a/passbook/saml_idp/forms.py +++ b/passbook/saml_idp/forms.py @@ -2,13 +2,24 @@ from django import forms -from passbook.saml_idp.models import SAMLProvider +from passbook.saml_idp.models import SAMLProvider, get_provider_choices class SAMLProviderForm(forms.ModelForm): """SAML Provider form""" + processor_path = forms.ChoiceField(choices=get_provider_choices(), label='Processor') + class Meta: model = SAMLProvider - fields = ['name', 'acs_url', 'processor_path', ] + fields = ['name', 'acs_url', 'processor_path', 'issuer', + 'assertion_valid_for', 'signing', 'signing_cert', 'signing_key', ] + labels = { + 'acs_url': 'ACS URL', + 'signing_cert': 'Singing Certificate', + } + widgets = { + 'name': forms.TextInput(), + 'issuer': forms.TextInput(), + } diff --git a/passbook/saml_idp/migrations/0004_auto_20181209_2202.py b/passbook/saml_idp/migrations/0004_auto_20181209_2202.py new file mode 100644 index 000000000..698ac6d73 --- /dev/null +++ b/passbook/saml_idp/migrations/0004_auto_20181209_2202.py @@ -0,0 +1,41 @@ +# Generated by Django 2.1.4 on 2018-12-09 22:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('passbook_saml_idp', '0003_auto_20181126_1514'), + ] + + operations = [ + migrations.AddField( + model_name='samlprovider', + name='assertion_valid_for', + field=models.IntegerField(default=86400), + ), + migrations.AddField( + model_name='samlprovider', + name='issuer', + field=models.TextField(default=''), + preserve_default=False, + ), + migrations.AddField( + model_name='samlprovider', + name='signing', + field=models.BooleanField(default=True), + ), + migrations.AddField( + model_name='samlprovider', + name='signing_cert', + field=models.TextField(default=''), + preserve_default=False, + ), + migrations.AddField( + model_name='samlprovider', + name='signing_key', + field=models.TextField(default=''), + preserve_default=False, + ), + ] diff --git a/passbook/saml_idp/models.py b/passbook/saml_idp/models.py index c73c1ca4d..a21617136 100644 --- a/passbook/saml_idp/models.py +++ b/passbook/saml_idp/models.py @@ -14,13 +14,17 @@ class SAMLProvider(Provider): name = models.TextField() acs_url = models.URLField() processor_path = models.CharField(max_length=255, choices=[]) + issuer = models.TextField() + assertion_valid_for = models.IntegerField(default=86400) + signing = models.BooleanField(default=True) + signing_cert = models.TextField() + signing_key = models.TextField() form = 'passbook.saml_idp.forms.SAMLProviderForm' def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - processors = [(class_to_path(x), x.__name__) for x in Processor.__subclasses__()] - self._meta.get_field('processor_path').choices = processors + self._meta.get_field('processor_path').choices = get_provider_choices() def __str__(self): return "SAMLProvider %s (processor=%s)" % (self.name, self.processor_path) @@ -29,3 +33,8 @@ class SAMLProvider(Provider): verbose_name = _('SAML Provider') verbose_name_plural = _('SAML Providers') + + +def get_provider_choices(): + """Return tuple of class_path, class name of all providers.""" + return [(class_to_path(x), x.__name__) for x in Processor.__subclasses__()]