Skip to content

Commit 39db66b

Browse files
Merge pull request #548 from mrvanes/fix-friendlyname-mapping
Do not map attribute FriendlyName to attribute Name
2 parents cf529b6 + 55ecd38 commit 39db66b

File tree

2 files changed

+8
-51
lines changed

2 files changed

+8
-51
lines changed

src/saml2/attribute_converter.py

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -118,42 +118,7 @@ def to_local(acs, statement, allow_unknown_attributes=False):
118118
:param allow_unknown_attributes: If unknown attributes are allowed
119119
:return: A key,values dictionary
120120
"""
121-
if not acs:
122-
acs = [AttributeConverter()]
123-
acsd = {"": acs}
124-
else:
125-
acsd = dict([(a.name_format, a) for a in acs])
126-
127-
ava = {}
128-
for attr in statement.attribute:
129-
try:
130-
_func = acsd[attr.name_format].ava_from
131-
except KeyError:
132-
if attr.name_format == NAME_FORMAT_UNSPECIFIED or \
133-
allow_unknown_attributes:
134-
_func = acs[0].lcd_ava_from
135-
else:
136-
logger.info("Unsupported attribute name format: %s",
137-
attr.name_format)
138-
continue
139-
140-
try:
141-
key, val = _func(attr)
142-
except KeyError:
143-
if allow_unknown_attributes:
144-
key, val = acs[0].lcd_ava_from(attr)
145-
else:
146-
logger.info("Unknown attribute name: %s", attr)
147-
continue
148-
except AttributeError:
149-
continue
150-
151-
try:
152-
ava[key].extend(val)
153-
except KeyError:
154-
ava[key] = val
155-
156-
return ava
121+
return list_to_local(acs, statement.attribute, allow_unknown_attributes)
157122

158123

159124
def list_to_local(acs, attrlist, allow_unknown_attributes=False):
@@ -313,23 +278,15 @@ def from_dict(self, mapdict):
313278

314279
def lcd_ava_from(self, attribute):
315280
"""
316-
In nothing else works, this should
281+
If nothing else works, this should
317282
318-
:param attribute: An Attribute Instance
283+
:param attribute: an Attribute instance
319284
:return:
320285
"""
321-
try:
322-
name = attribute.friendly_name.strip()
323-
except AttributeError:
324-
name = attribute.name.strip()
325-
326-
values = []
327-
for value in attribute.attribute_value:
328-
if not value.text:
329-
values.append('')
330-
else:
331-
values.append(value.text.strip())
332-
286+
name = attribute.name.strip()
287+
values = [
288+
(value.text or '').strip()
289+
for value in attribute.attribute_value]
333290
return name, values
334291

335292
def fail_safe_fro(self, statement):

tests/test_19_attribute_converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def test_mixed_attributes_1(self):
192192
ava = to_local(self.acs, ats, True)
193193
assert ava == {'eduPersonAffiliation': ['staff'],
194194
'givenName': ['Roland'], 'sn': ['Hedberg'],
195-
'swissEduPersonHomeOrganizationType': ['others'],
195+
'urn:oid:2.16.756.1.2.5.1.1.5': ['others'],
196196
'uid': ['demouser'], 'urn:example:com:foo': ['Thing'],
197197
'user_id': ['bob']}
198198

0 commit comments

Comments
 (0)