Projet

Général

Profil

0007-saml-fix-order-of-NAME_ID_FORMATS-42504.patch

Benjamin Dauvergne, 05 mai 2020 16:08

Télécharger (4,36 ko)

Voir les différences:

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(-)
src/authentic2/saml/migrations/0015_auto_20150915_2032.py
21 21
        migrations.AlterField(
22 22
            model_name='spoptionsidppolicy',
23 23
            name='accepted_name_id_format',
24
            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')]),
25
            preserve_default=True,
24
            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'),
25

  
26 26
        ),
27 27
        migrations.AlterField(
28 28
            model_name='spoptionsidppolicy',
29 29
            name='default_name_id_format',
30
            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')]),
31
            preserve_default=True,
30
            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')]),
31

  
32 32
        ),
33 33
    ]
src/authentic2/saml/models.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
import collections
18

  
17 19
import xml.etree.ElementTree as etree
18 20
import hashlib
19 21

  
......
112 114
DEFAULT_NAME_ID_FORMAT = 'none'
113 115

  
114 116
# Supported name id formats
115
NAME_ID_FORMATS = {
116
    'none': {
117
NAME_ID_FORMATS = collections.OrderedDict([
118
    ('none', {
117 119
        'caption': _('None'),
118 120
        'samlv2': None,
119
    },
120
    'persistent': {
121
    }),
122
    ('persistent', {
121 123
        'caption': _('Persistent'),
122 124
        'samlv2': lasso.SAML2_NAME_IDENTIFIER_FORMAT_PERSISTENT,
123
    },
124
    'transient': {
125
    }),
126
    ('transient', {
125 127
        'caption': _("Transient"),
126 128
        'samlv2': lasso.SAML2_NAME_IDENTIFIER_FORMAT_TRANSIENT,
127
    },
128
    'email': {
129
    }),
130
    ('email', {
129 131
        'caption': _("Email"),
130 132
        'samlv2': lasso.SAML2_NAME_IDENTIFIER_FORMAT_EMAIL,
131
    },
132
    'username': {
133
    }),
134
    ('username', {
133 135
        'caption': _("Username (use with Google Apps)"),
134 136
        'samlv2': lasso.SAML2_NAME_IDENTIFIER_FORMAT_UNSPECIFIED,
135
    },
136
    'uuid': {
137
    }),
138
    ('uuid', {
137 139
        'caption': _("UUID"),
138 140
        'samlv2': lasso.SAML2_NAME_IDENTIFIER_FORMAT_UNSPECIFIED,
139
    },
140
    'edupersontargetedid': {
141
    }),
142
    ('edupersontargetedid', {
141 143
        'caption': _("Use eduPersonTargetedID attribute"),
142 144
        'samlv2': lasso.SAML2_NAME_IDENTIFIER_FORMAT_PERSISTENT,
143
    }
144
}
145
    })
146
])
145 147

  
146
NAME_ID_FORMATS_CHOICES = tuple([(x, y['caption']) for x, y in NAME_ID_FORMATS.items()])
148
NAME_ID_FORMATS_CHOICES = [(force_text(x), y['caption']) for x, y in NAME_ID_FORMATS.items()]
147 149

  
148 150
ACCEPTED_NAME_ID_FORMAT_LENGTH = sum([len(x) for x, y in NAME_ID_FORMATS.items()]) + len(NAME_ID_FORMATS) - 1
149 151

  
150
-