Skip to content

Commit bbe6260

Browse files
author
Roland Hedberg
committed
Handled possible exception in the entity_categories method and add a supported_entity_categories method.
1 parent 4f767b9 commit bbe6260

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

src/saml2/mdstore.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class ToOld(Exception):
5656

5757

5858
ENTITYATTRIBUTES = "urn:oasis:names:tc:SAML:metadata:attribute&EntityAttributes"
59+
ENTITY_CATEGORY = "http://macedir.org/entity-category"
60+
ENTITY_CATEGORY_SUPPORT = "http://macedir.org/entity-category-support"
5961

6062
# ---------------------------------------------------
6163

@@ -598,30 +600,30 @@ def single_sign_on_service(self, entity_id, binding=None, typ="idpsso"):
598600
if binding is None:
599601
binding = BINDING_HTTP_REDIRECT
600602
return self.service(entity_id, "idpsso_descriptor",
601-
"single_sign_on_service", binding)
603+
"single_sign_on_service", binding)
602604

603605
def name_id_mapping_service(self, entity_id, binding=None, typ="idpsso"):
604606
# IDP
605607
if binding is None:
606608
binding = BINDING_HTTP_REDIRECT
607609
return self.service(entity_id, "idpsso_descriptor",
608-
"name_id_mapping_service", binding)
610+
"name_id_mapping_service", binding)
609611

610612
def authn_query_service(self, entity_id, binding=None,
611613
typ="authn_authority"):
612614
# AuthnAuthority
613615
if binding is None:
614616
binding = BINDING_SOAP
615617
return self.service(entity_id, "authn_authority_descriptor",
616-
"authn_query_service", binding)
618+
"authn_query_service", binding)
617619

618620
def attribute_service(self, entity_id, binding=None,
619621
typ="attribute_authority"):
620622
# AttributeAuthority
621623
if binding is None:
622624
binding = BINDING_HTTP_REDIRECT
623625
return self.service(entity_id, "attribute_authority_descriptor",
624-
"attribute_service", binding)
626+
"attribute_service", binding)
625627

626628
def authz_service(self, entity_id, binding=None, typ="pdp"):
627629
# PDP
@@ -774,13 +776,35 @@ def vo_members(self, entity_id):
774776

775777
def entity_categories(self, entity_id):
776778
ent = self.__getitem__(entity_id)
777-
ext = ent["extensions"]
778779
res = []
779-
for elem in ext["extension_elements"]:
780-
if elem["__class__"] == ENTITYATTRIBUTES:
781-
for attr in elem["attribute"]:
782-
if attr["name"] == "http://macedir.org/entity-category":
783-
res.extend([v["text"] for v in attr["attribute_value"]])
780+
try:
781+
ext = ent["extensions"]
782+
except KeyError:
783+
pass
784+
else:
785+
for elem in ext["extension_elements"]:
786+
if elem["__class__"] == ENTITYATTRIBUTES:
787+
for attr in elem["attribute"]:
788+
if attr["name"] == ENTITY_CATEGORY:
789+
res.extend([v["text"] for v in
790+
attr["attribute_value"]])
791+
792+
return res
793+
794+
def supported_entity_categories(self, entity_id):
795+
ent = self.__getitem__(entity_id)
796+
res = []
797+
try:
798+
ext = ent["extensions"]
799+
except KeyError:
800+
pass
801+
else:
802+
for elem in ext["extension_elements"]:
803+
if elem["__class__"] == ENTITYATTRIBUTES:
804+
for attr in elem["attribute"]:
805+
if attr["name"] == ENTITY_CATEGORY_SUPPORT:
806+
res.extend([v["text"] for v in
807+
attr["attribute_value"]])
784808

785809
return res
786810

0 commit comments

Comments
 (0)