diff options
author | Ivan Kanakarakis <ivan.kanak@gmail.com> | 2019-06-17 01:27:56 +0300 |
---|---|---|
committer | Ivan Kanakarakis <ivan.kanak@gmail.com> | 2019-06-17 01:27:56 +0300 |
commit | 1432950d86c1941da0b6465804b94a3ca75075f8 (patch) | |
tree | 424ba1084ca5dd79182278b24946632f8e8ab942 /src/saml2 | |
parent | 634644e94c33faafe1eaf008a3ed3eaca99aa5d6 (diff) | |
download | pysaml2-1432950d86c1941da0b6465804b94a3ca75075f8.tar.gz |
Restructure to_eptid_value function
Use "text" instead of "value" as the key that denotes the text-value of the
NameID node.
Signed-off-by: Ivan Kanakarakis <ivan.kanak@gmail.com>
Diffstat (limited to 'src/saml2')
-rw-r--r-- | src/saml2/attribute_converter.py | 58 |
1 files changed, 30 insertions, 28 deletions
diff --git a/src/saml2/attribute_converter.py b/src/saml2/attribute_converter.py index cd40fe79..bc937702 100644 --- a/src/saml2/attribute_converter.py +++ b/src/saml2/attribute_converter.py @@ -447,39 +447,41 @@ class AttributeConverter(object): return attributes - def to_eptid_value(self, value): + def to_eptid_value(self, values): """ - Special handling for the attribute with name - urn:oid:1.3.6.1.4.1.5923.1.1.1.10, usually known by the friendly - name eduPersonTargetedID. Create the AttributeValue instance(s) - for the attribute. + Create AttributeValue instances of NameID from the given values. - value is either a string or a dictionary with keys 'value', - 'NameQualifier', and 'SPNameQualifier'. + Special handling for the "eptid" attribute + Name=urn:oid:1.3.6.1.4.1.5923.1.1.1.10 + FriendlyName=eduPersonTargetedID - Returns a list of AttributeValue instances. - """ - attribute_values = [] - - for v in value: - if isinstance(v, dict): - element_attributes = { - 'Format': NAMEID_FORMAT_PERSISTENT, - 'NameQualifier': v['NameQualifier'], - 'SPNameQualifier': v['SPNameQualifier'] - } - text = v['value'] - else: - element_attributes = {'Format': NAMEID_FORMAT_PERSISTENT} - text = v - - element = ExtensionElement("NameID", NAMESPACE, element_attributes, - text=text) + values is a list of items of type str or dict. When an item is a + dictionary it has the keys: "NameQualifier", "SPNameQualifier", and + "text". - attrval = saml.AttributeValue(extension_elements=[element]) - - attribute_values.append(attrval) + Returns a list of AttributeValue instances of NameID elements. + """ + def _create_nameid_ext_el(value): + text = value["text"] if isinstance(value, dict) else value + attributes = ( + { + "Format": NAMEID_FORMAT_PERSISTENT, + "NameQualifier": value["NameQualifier"], + "SPNameQualifier": value["SPNameQualifier"], + } + if isinstance(value, dict) + else {"Format": NAMEID_FORMAT_PERSISTENT} + ) + element = ExtensionElement( + "NameID", NAMESPACE, attributes=attributes, text=text + ) + return element + + attribute_values = [ + saml.AttributeValue(extension_elements=[_create_nameid_ext_el(v)]) + for v in values + ] return attribute_values |