From 3a839e6ea9398d353f58718b7dd104aa1798a6f6 Mon Sep 17 00:00:00 2001 From: Rebecka Gulliksson Date: Tue, 17 May 2016 21:11:10 +0200 Subject: [PATCH 1/6] Don't catch KeyError over too broad statement. Previously KeyError in lower level of implementation, MetadataStore.entity_categories(), was caught instead of being propagated. --- src/saml2/assertion.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/saml2/assertion.py b/src/saml2/assertion.py index 35a11dd..adfeecd 100644 --- a/src/saml2/assertion.py +++ b/src/saml2/assertion.py @@ -273,13 +273,8 @@ def post_entity_categories(maps, **kwargs): required = [] if kwargs["mds"]: - try: + if "sp_entity_id" in kwargs: ecs = kwargs["mds"].entity_categories(kwargs["sp_entity_id"]) - except KeyError: - for ec_map in maps: - for attr in ec_map[""]: - restrictions[attr] = None - else: for ec_map in maps: for key, (atlist, only_required) in ec_map.items(): if key == "": # always released @@ -305,6 +300,10 @@ def post_entity_categories(maps, **kwargs): for attr in attrs: restrictions[attr] = None + else: + for ec_map in maps: + for attr in ec_map[""]: + restrictions[attr] = None return restrictions From f4abf8da3b4937f16db227cd8a8a522359754b7e Mon Sep 17 00:00:00 2001 From: Roland Hedberg Date: Wed, 18 May 2016 10:40:44 +0200 Subject: [PATCH 2/6] TO deal with Python3 returning not list but dict_items. --- src/saml2/mdstore.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/saml2/mdstore.py b/src/saml2/mdstore.py index 28d6061..e4a4785 100644 --- a/src/saml2/mdstore.py +++ b/src/saml2/mdstore.py @@ -305,7 +305,7 @@ class MetaData(object): raise NotImplementedError def dumps(self): - return json.dumps(self.items(), indent=2) + return json.dumps(list(self.items()), indent=2) def with_descriptor(self, descriptor): ''' From e1432e0679a683a78f420e0ee6498b15e53c4a11 Mon Sep 17 00:00:00 2001 From: Roland Hedberg Date: Thu, 26 May 2016 20:03:10 +0200 Subject: [PATCH 3/6] Fixed some problems with Discovery Server --- src/saml2/discovery.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/saml2/discovery.py b/src/saml2/discovery.py index cef8ff3..8031b41 100644 --- a/src/saml2/discovery.py +++ b/src/saml2/discovery.py @@ -1,4 +1,7 @@ -from six.moves.urllib.parse import urlencode, parse_qs, urlparse +from future.backports.urllib.parse import parse_qs +from future.backports.urllib.parse import urlencode +from future.backports.urllib.parse import urlparse + from saml2.entity import Entity from saml2.response import VerificationError @@ -9,7 +12,8 @@ IDPDISC_POLICY = "urn:oasis:names:tc:SAML:profiles:SSO:idp-discovery-protocol:si class DiscoveryServer(Entity): def __init__(self, config=None, config_file=""): - Entity.__init__(self, "disco", config, config_file) + if config or config_file: + Entity.__init__(self, "disco", config, config_file) def parse_discovery_service_request(self, url="", query=""): if url: @@ -22,7 +26,8 @@ class DiscoveryServer(Entity): # verify - for key in ["isPassive", "return", "returnIDParam", "policy"]: + for key in ["isPassive", "return", "returnIDParam", "policy", + 'entityID']: try: assert len(dsr[key]) == 1 dsr[key] = dsr[key][0] From e7dfe6b18f27885adc42a2ecaea3ed30a726d711 Mon Sep 17 00:00:00 2001 From: Roland Hedberg Date: Thu, 26 May 2016 20:04:07 +0200 Subject: [PATCH 4/6] A second any method that is faster then the first. --- src/saml2/mdstore.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/saml2/mdstore.py b/src/saml2/mdstore.py index e4a4785..621752b 100644 --- a/src/saml2/mdstore.py +++ b/src/saml2/mdstore.py @@ -269,7 +269,7 @@ class MetaData(object): """ Return any entity that matches the specification - :param typ: + :param typ: Type of entity :param service: :param binding: :return: @@ -282,6 +282,37 @@ class MetaData(object): return res + def any2(self, typ, service, binding=None): + """ + + :param type: + :param service: + :param binding: + :return: + """ + res = {} + for entid, item in self.items(): + hit = False + try: + descr = item['{}sso_descriptor'.format(typ)] + except KeyError: + continue + else: + for desc in descr: + try: + srvs = desc[service] + except KeyError: + continue + else: + for srv in srvs: + if srv['binding'] == binding: + res[entid] = item + hit = True + break + if hit: + break + return res + def bindings(self, entity_id, typ, service): """ Get me all the bindings that are registered for a service entity From 1efe75e48b76e1d1ace921c96a04484d4a848b44 Mon Sep 17 00:00:00 2001 From: Roland Hedberg Date: Thu, 26 May 2016 20:04:35 +0200 Subject: [PATCH 5/6] Fixed imports --- tests/test_37_entity_categories.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/tests/test_37_entity_categories.py b/tests/test_37_entity_categories.py index 5161df2..625caaa 100644 --- a/tests/test_37_entity_categories.py +++ b/tests/test_37_entity_categories.py @@ -1,19 +1,11 @@ from contextlib import closing -from saml2 import saml, sigver -from saml2 import md +from saml2 import sigver from saml2 import config from saml2.assertion import Policy from saml2.attribute_converter import ac_factory -from saml2.extension import mdui -from saml2.extension import idpdisc -from saml2.extension import dri -from saml2.extension import mdattr -from saml2.extension import ui from pathutils import full_path from saml2.mdstore import MetadataStore from saml2.server import Server -from saml2 import xmldsig -from saml2 import xmlenc ATTRCONV = ac_factory(full_path("attributemaps")) From 96170033ecf95aa86d3421f3f2b55233fdab7548 Mon Sep 17 00:00:00 2001 From: Roland Hedberg Date: Thu, 26 May 2016 20:04:57 +0200 Subject: [PATCH 6/6] Fixed imports --- tools/verify_metadata.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/tools/verify_metadata.py b/tools/verify_metadata.py index ac211b9..c13b7ac 100755 --- a/tools/verify_metadata.py +++ b/tools/verify_metadata.py @@ -2,20 +2,8 @@ import argparse -from saml2 import saml -from saml2 import md -from saml2 import xmldsig -from saml2 import xmlenc - from saml2.attribute_converter import ac_factory from saml2.httpbase import HTTPBase -from saml2.extension import dri -from saml2.extension import idpdisc -from saml2.extension import mdattr -from saml2.extension import mdrpi -from saml2.extension import mdui -from saml2.extension import shibmd -from saml2.extension import ui from saml2.sigver import _get_xmlsec_cryptobackend from saml2.sigver import SecurityContext