Projet

Général

Profil

0001-idp-saml-collapse-attribute-values.patch

Benjamin Dauvergne, 31 mars 2015 09:31

Télécharger (2,07 ko)

Voir les différences:

Subject: [PATCH] idp/saml: collapse attribute values

If two AttributeValue for the same value, name and name format would be
created, we skip its creation. It allows to configure attributes for
django_user_username and LDAP uid at the same without getting two times
the same value, as LDAP users also expose the Django user attributes.
 src/authentic2/idp/saml/saml2_endpoints.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
src/authentic2/idp/saml/saml2_endpoints.py
202 202
        'user': request.user,
203 203
        'service': provider.entity_id,
204 204
        '__wanted_attributes': wanted_attributes,
205 205
    })
206 206
    if not assertion.attributeStatement:
207 207
        assertion.attributeStatement = [lasso.Saml2AttributeStatement()]
208 208
    attribute_statement = assertion.attributeStatement[0]
209 209
    saml_attributes = list(attribute_statement.attribute)
210
    seen = set()
210 211
    for definition in qs:
212
        value = ctx.get(definition.attribute_name)
213
        key = (definition.name, definition.name_format, value)
214
        if key in seen:
215
            continue
216
        seen.add(key)
211 217
        saml_attribute = definition.to_lasso_attribute(ctx)
212 218
        if not saml_attribute:
213 219
            continue
214
        logger.debug('adding attribute %r with value %r',
215
                definition.name, ctx.get(definition.attribute_name))
220
        logger.debug('adding attribute %r with value %r', definition.name,
221
                value)
216 222
        saml_attributes.append(saml_attribute)
217 223
    attribute_statement.attribute = saml_attributes
218 224

  
219 225

  
220 226
def saml2_add_attribute_values(assertion, attributes):
221 227
    if not attributes:
222 228
        logger.info("\
223 229
            there are no attributes to add")
224
-