|
55 | 55 | SAMLP_NAMESPACE = 'urn:oasis:names:tc:SAML:2.0:protocol' |
56 | 56 | XSI_NAMESPACE = 'http://www.w3.org/2001/XMLSchema-instance' |
57 | 57 | XS_NAMESPACE = 'http://www.w3.org/2001/XMLSchema' |
58 | | -DS_NAMESPACE = 'http://www.w3.org/2000/09/xmldsig#' |
59 | 58 | MD_NAMESPACE = "urn:oasis:names:tc:SAML:2.0:metadata" |
60 | 59 | MDUI_NAMESPACE = "urn:oasis:names:tc:SAML:metadata:ui" |
61 | | -DEFAULT_NS_PREFIXES = {'saml': NAMESPACE, 'samlp': SAMLP_NAMESPACE, |
62 | | - 'ds': DS_NAMESPACE, 'xsi': XSI_NAMESPACE, |
63 | | - 'xs': XS_NAMESPACE, |
64 | | - 'mdui': MDUI_NAMESPACE, |
65 | | - 'md': MD_NAMESPACE, |
66 | | - # 'alg': TODO: algsupport.DIGEST_METHODS|SIGNING_METHODS shoulb be moved before mapping them here |
67 | | - # TODO: <ns1:EntityAttributes> |
68 | | - } |
69 | | - |
| 60 | +DS_NAMESPACE = 'http://www.w3.org/2000/09/xmldsig#' |
| 61 | +XENC_NAMESPACE = "http://www.w3.org/2001/04/xmlenc#" |
| 62 | +ALG_NAMESPACE = "urn:oasis:names:tc:SAML:metadata:algsupport" |
| 63 | +MDATTR_NAMESPACE = "urn:oasis:names:tc:SAML:metadata:attribute" |
| 64 | + |
| 65 | +# this should be configurable by users |
| 66 | +OASIS_DEFAULT_NS_PREFIXES = {'saml': NAMESPACE, |
| 67 | + 'samlp': SAMLP_NAMESPACE, |
| 68 | + 'ds': DS_NAMESPACE, |
| 69 | + 'xsi': XSI_NAMESPACE, |
| 70 | + 'xs': XS_NAMESPACE, |
| 71 | + 'mdui': MDUI_NAMESPACE, |
| 72 | + 'md': MD_NAMESPACE, |
| 73 | + 'xenc': XENC_NAMESPACE, |
| 74 | + 'alg': ALG_NAMESPACE, |
| 75 | + 'mdattr': MDATTR_NAMESPACE} |
70 | 76 |
|
71 | 77 | NAMEID_FORMAT_EMAILADDRESS = ( |
72 | 78 | "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress") |
@@ -570,7 +576,8 @@ def _to_element_tree(self): |
570 | 576 | self._add_members_to_element_tree(new_tree) |
571 | 577 | return new_tree |
572 | 578 |
|
573 | | - def register_prefix(self, nspair): |
| 579 | + @staticmethod |
| 580 | + def register_prefix(nspair): |
574 | 581 | """ |
575 | 582 | Register with ElementTree a set of namespaces |
576 | 583 |
|
@@ -698,14 +705,11 @@ def fixup(name): |
698 | 705 | del elem.attrib[key] |
699 | 706 |
|
700 | 707 | def to_string_force_namespace(self, nspair): |
701 | | - |
702 | 708 | elem = self._to_element_tree() |
703 | | - |
704 | 709 | self.set_prefixes(elem, nspair) |
705 | | - |
706 | 710 | return ElementTree.tostring(elem, encoding="UTF-8") |
707 | 711 |
|
708 | | - def to_string(self, nspair=DEFAULT_NS_PREFIXES): |
| 712 | + def to_string(self, nspair=None): |
709 | 713 | """Converts the Saml object to a string containing XML. |
710 | 714 |
|
711 | 715 | :param nspair: A dictionary of prefixes and uris to use when |
@@ -1056,3 +1060,6 @@ def is_required_attribute(cls, attr): |
1056 | 1060 | :return: True if required |
1057 | 1061 | """ |
1058 | 1062 | return cls.c_attributes[attr][REQUIRED] |
| 1063 | + |
| 1064 | +# this register preferred prefix namespaces |
| 1065 | +SamlBase.register_prefix(OASIS_DEFAULT_NS_PREFIXES) |
0 commit comments