From ff053cc3c333b4e44fb0123c3bbdf1f947e72462 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Tue, 5 May 2020 15:27:58 +0200 Subject: [PATCH 07/10] saml: fix order of NAME_ID_FORMATS (#42504) --- .../migrations/0015_auto_20150915_2032.py | 8 ++--- src/authentic2/saml/models.py | 36 ++++++++++--------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git src/authentic2/saml/migrations/0015_auto_20150915_2032.py src/authentic2/saml/migrations/0015_auto_20150915_2032.py index d150fb0b..34c156d7 100644 --- src/authentic2/saml/migrations/0015_auto_20150915_2032.py +++ src/authentic2/saml/migrations/0015_auto_20150915_2032.py @@ -21,13 +21,13 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='spoptionsidppolicy', name='accepted_name_id_format', - field=authentic2.saml.fields.MultiSelectField(blank=True, max_length=1024, verbose_name='NameID formats accepted', choices=[('username', 'Username (use with Google Apps)'), ('none', 'None'), ('uuid', 'UUID'), ('persistent', 'Persistent'), ('transient', 'Transient'), ('edupersontargetedid', 'Use eduPersonTargetedID attribute'), ('email', 'Email')]), - preserve_default=True, + field=authentic2.saml.fields.MultiSelectField(blank=True, choices=[('none', 'None'), ('persistent', 'Persistent'), ('transient', 'Transient'), ('email', 'Email'), ('username', 'Username (use with Google Apps)'), ('uuid', 'UUID'), ('edupersontargetedid', 'Use eduPersonTargetedID attribute')], max_length=1024, verbose_name='NameID formats accepted'), + ), migrations.AlterField( model_name='spoptionsidppolicy', name='default_name_id_format', - field=models.CharField(default='none', max_length=256, choices=[('username', 'Username (use with Google Apps)'), ('none', 'None'), ('uuid', 'UUID'), ('persistent', 'Persistent'), ('transient', 'Transient'), ('edupersontargetedid', 'Use eduPersonTargetedID attribute'), ('email', 'Email')]), - preserve_default=True, + field=models.CharField(default='none', max_length=256, choices=[('none', 'None'), ('persistent', 'Persistent'), ('transient', 'Transient'), ('email', 'Email'), ('username', 'Username (use with Google Apps)'), ('uuid', 'UUID'), ('edupersontargetedid', 'Use eduPersonTargetedID attribute')]), + ), ] diff --git src/authentic2/saml/models.py src/authentic2/saml/models.py index ef979363..f399b91f 100644 --- src/authentic2/saml/models.py +++ src/authentic2/saml/models.py @@ -14,6 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import collections + import xml.etree.ElementTree as etree import hashlib @@ -112,38 +114,38 @@ ASSERTION_CONSUMER_PROFILES = ( DEFAULT_NAME_ID_FORMAT = 'none' # Supported name id formats -NAME_ID_FORMATS = { - 'none': { +NAME_ID_FORMATS = collections.OrderedDict([ + ('none', { 'caption': _('None'), 'samlv2': None, - }, - 'persistent': { + }), + ('persistent', { 'caption': _('Persistent'), 'samlv2': lasso.SAML2_NAME_IDENTIFIER_FORMAT_PERSISTENT, - }, - 'transient': { + }), + ('transient', { 'caption': _("Transient"), 'samlv2': lasso.SAML2_NAME_IDENTIFIER_FORMAT_TRANSIENT, - }, - 'email': { + }), + ('email', { 'caption': _("Email"), 'samlv2': lasso.SAML2_NAME_IDENTIFIER_FORMAT_EMAIL, - }, - 'username': { + }), + ('username', { 'caption': _("Username (use with Google Apps)"), 'samlv2': lasso.SAML2_NAME_IDENTIFIER_FORMAT_UNSPECIFIED, - }, - 'uuid': { + }), + ('uuid', { 'caption': _("UUID"), 'samlv2': lasso.SAML2_NAME_IDENTIFIER_FORMAT_UNSPECIFIED, - }, - 'edupersontargetedid': { + }), + ('edupersontargetedid', { 'caption': _("Use eduPersonTargetedID attribute"), 'samlv2': lasso.SAML2_NAME_IDENTIFIER_FORMAT_PERSISTENT, - } -} + }) +]) -NAME_ID_FORMATS_CHOICES = tuple([(x, y['caption']) for x, y in NAME_ID_FORMATS.items()]) +NAME_ID_FORMATS_CHOICES = [(force_text(x), y['caption']) for x, y in NAME_ID_FORMATS.items()] ACCEPTED_NAME_ID_FORMAT_LENGTH = sum([len(x) for x, y in NAME_ID_FORMATS.items()]) + len(NAME_ID_FORMATS) - 1 -- 2.26.0