saml_idp: Add Certificate, Key and other settings to DB

This commit is contained in:
Jens Langhammer 2018-12-09 23:06:14 +01:00
parent dae5fc6265
commit 9cccc0a757
No known key found for this signature in database
GPG key ID: BEBC05297D92821B
4 changed files with 66 additions and 5 deletions

View file

@ -188,7 +188,7 @@ class Processor:
'acs_url': self._request_params['ACS_URL'], 'acs_url': self._request_params['ACS_URL'],
'saml_response': self._saml_response, 'saml_response': self._saml_response,
'relay_state': self._relay_state, 'relay_state': self._relay_state,
'autosubmit': CONFIG.y('saml_idp.autosubmit', False), 'autosubmit': False, # TODO: use autosubmit from application
} }
def _parse_request(self): def _parse_request(self):

View file

@ -2,13 +2,24 @@
from django import forms 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): class SAMLProviderForm(forms.ModelForm):
"""SAML Provider form""" """SAML Provider form"""
processor_path = forms.ChoiceField(choices=get_provider_choices(), label='Processor')
class Meta: class Meta:
model = SAMLProvider 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(),
}

View file

@ -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,
),
]

View file

@ -14,13 +14,17 @@ class SAMLProvider(Provider):
name = models.TextField() name = models.TextField()
acs_url = models.URLField() acs_url = models.URLField()
processor_path = models.CharField(max_length=255, choices=[]) 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' form = 'passbook.saml_idp.forms.SAMLProviderForm'
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*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 = get_provider_choices()
self._meta.get_field('processor_path').choices = processors
def __str__(self): def __str__(self):
return "SAMLProvider %s (processor=%s)" % (self.name, self.processor_path) return "SAMLProvider %s (processor=%s)" % (self.name, self.processor_path)
@ -29,3 +33,8 @@ class SAMLProvider(Provider):
verbose_name = _('SAML Provider') verbose_name = _('SAML Provider')
verbose_name_plural = _('SAML Providers') 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__()]