Skip to content

Commit eeb4b5d

Browse files
author
Roland Hedberg
committed
Fixed a problem with filtering assertion by required/optional attributes.
1 parent e28cf61 commit eeb4b5d

File tree

5 files changed

+36
-16
lines changed

5 files changed

+36
-16
lines changed

src/saml2/assertion.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from saml2 import saml
2525

2626
from saml2.time_util import instant, in_a_while
27-
from saml2.attribute_converter import from_local
27+
from saml2.attribute_converter import from_local, get_local_name
2828
from saml2.s_utils import sid, MissingValue
2929
from saml2.s_utils import factory
3030
from saml2.s_utils import assertion_factory
@@ -78,7 +78,7 @@ def _match(attr, ava):
7878
return None
7979

8080

81-
def filter_on_attributes(ava, required=None, optional=None):
81+
def filter_on_attributes(ava, required=None, optional=None, acs=None):
8282
""" Filter
8383
8484
:param ava: An attribute value assertion as a dictionary
@@ -98,18 +98,23 @@ def filter_on_attributes(ava, required=None, optional=None):
9898
nform = ""
9999
for nform in ["friendly_name", "name"]:
100100
try:
101-
_fn = _match(attr[nform], ava)
101+
_name = attr[nform]
102102
except KeyError:
103-
pass
104-
else:
105-
if _fn:
106-
try:
107-
values = [av["text"] for av in attr["attribute_value"]]
108-
except KeyError:
109-
values = []
110-
res[_fn] = _filter_values(ava[_fn], values, True)
111-
found = True
112-
break
103+
if nform == "friendly_name":
104+
_name = get_local_name(acs, attr["name"],
105+
attr["name_format"])
106+
else:
107+
continue
108+
109+
_fn = _match(_name, ava)
110+
if _fn:
111+
try:
112+
values = [av["text"] for av in attr["attribute_value"]]
113+
except KeyError:
114+
values = []
115+
res[_fn] = _filter_values(ava[_fn], values, True)
116+
found = True
117+
break
113118

114119
if not found:
115120
raise MissingValue("Required attribute missing: '%s'" % (
@@ -311,7 +316,8 @@ def __init__(self, restrictions=None):
311316
self.compile(restrictions)
312317
else:
313318
self._restrictions = None
314-
319+
self.acs = []
320+
315321
def compile(self, restrictions):
316322
""" This is only for IdPs or AAs, and it's about limiting what
317323
is returned to the SP.
@@ -484,7 +490,8 @@ def filter(self, ava, sp_entity_id, mdstore, required=None, optional=None):
484490
ava = filter_attribute_value_assertions(ava, _rest)
485491

486492
if required or optional:
487-
ava = filter_on_attributes(ava, required, optional)
493+
logger.debug("required: %s, optional: %s" % (required, optional))
494+
ava = filter_on_attributes(ava, required, optional, self.acs)
488495

489496
return ava
490497

@@ -540,7 +547,8 @@ class Assertion(dict):
540547

541548
def __init__(self, dic=None):
542549
dict.__init__(self, dic)
543-
550+
self.acs = []
551+
544552
@staticmethod
545553
def _authn_context_decl(decl, authn_auth=None):
546554
"""
@@ -727,6 +735,8 @@ def apply_policy(self, sp_entity_id, policy, metadata=None):
727735
:param metadata: Metadata to use
728736
:return: The resulting AVA after the policy is applied
729737
"""
738+
739+
policy.acs = self.acs
730740
ava = policy.restrict(self, sp_entity_id, metadata)
731741
self.update(ava)
732742
return ava

src/saml2/attribute_converter.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,13 @@ def to_local_name(acs, attr):
255255
return attr.friendly_name
256256

257257

258+
def get_local_name(acs, attr, name_format):
259+
for aconv in acs:
260+
#print ac.format, name_format
261+
if aconv.name_format == name_format:
262+
return aconv._fro[attr]
263+
264+
258265
def d_to_local_name(acs, attr):
259266
"""
260267
:param acs: List of AttributeConverter instances

src/saml2/attributemaps/saml_uri.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
'edupersonaffiliation': EDUPERSON_OID+'1',
178178
'eduPersonPrincipalName': EDUPERSON_OID+'6',
179179
'edupersonprincipalname': EDUPERSON_OID+'6',
180+
'eppn': EDUPERSON_OID+'6',
180181
'localityName': X500ATTR_OID+'7',
181182
'owner': X500ATTR_OID+'32',
182183
'norEduOrgUnitUniqueNumber': NOREDUPERSON_OID+'2',

src/saml2/server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ def _authn_response(self, in_response_to, consumer_url,
308308
#if identity:
309309
_issuer = self._issuer(issuer)
310310
ast = Assertion(identity)
311+
ast.acs = self.config.getattr("attribute_converters", "idp")
311312
if policy is None:
312313
policy = Policy()
313314
try:

tools/update_metadata.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
#!/bin/sh
12
curl -O -G http://md.swamid.se/md/swamid-2.0.xml
23
mdexport.py -t local -o swamid2.md swamid-2.0.xml

0 commit comments

Comments
 (0)