Skip to content

Commit b1986e2

Browse files
committed
Generate class names for metadata elements
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent b224a02 commit b1986e2

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/saml2/mdstore.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,20 @@
3535
from saml2.time_util import valid
3636
from saml2.validate import NotValid
3737
from saml2.sigver import security_context
38+
from saml2.extension.mdattr import NAMESPACE as NS_MDATTR
39+
from saml2.extension.mdattr import EntityAttributes
3840

39-
__author__ = 'rolandh'
4041

4142
logger = logging.getLogger(__name__)
4243

44+
classnames = {
45+
"mdattr_entityattributes": "{ns}&{tag}".format(
46+
ns=NS_MDATTR, tag=EntityAttributes.c_tag
47+
),
48+
}
4349

44-
class ToOld(Exception):
45-
pass
46-
47-
48-
class SourceNotFound(Exception):
49-
pass
50+
ENTITY_CATEGORY = "http://macedir.org/entity-category"
51+
ENTITY_CATEGORY_SUPPORT = "http://macedir.org/entity-category-support"
5052

5153
REQ2SRV = {
5254
# IDP
@@ -70,12 +72,14 @@ class SourceNotFound(Exception):
7072
"discovery_service_request": "discovery_response"
7173
}
7274

73-
ENTITYATTRIBUTES = "urn:oasis:names:tc:SAML:metadata:attribute&EntityAttributes"
74-
ENTITY_CATEGORY = "http://macedir.org/entity-category"
75-
ENTITY_CATEGORY_SUPPORT = "http://macedir.org/entity-category-support"
7675

76+
class ToOld(Exception):
77+
pass
78+
79+
80+
class SourceNotFound(Exception):
81+
pass
7782

78-
# ---------------------------------------------------
7983

8084
def load_extensions():
8185
from saml2 import extension
@@ -359,7 +363,7 @@ def entity_categories(self, entity_id):
359363
res = []
360364
if "extensions" in self[entity_id]:
361365
for elem in self[entity_id]["extensions"]["extension_elements"]:
362-
if elem["__class__"] == ENTITYATTRIBUTES:
366+
if elem["__class__"] == classnames["mdattr_entityattributes"]:
363367
for attr in elem["attribute"]:
364368
res.append(attr["text"])
365369

@@ -1243,7 +1247,7 @@ def entity_attributes(self, entity_id):
12431247
except KeyError:
12441248
return res
12451249
for elem in ext["extension_elements"]:
1246-
if elem["__class__"] == ENTITYATTRIBUTES:
1250+
if elem["__class__"] == classnames["mdattr_entityattributes"]:
12471251
for attr in elem["attribute"]:
12481252
if attr["name"] not in res:
12491253
res[attr["name"]] = []

0 commit comments

Comments
 (0)