|
58 | 58 | DS_NAMESPACE = 'http://www.w3.org/2000/09/xmldsig#' |
59 | 59 | MD_NAMESPACE = "urn:oasis:names:tc:SAML:2.0:metadata" |
60 | 60 | 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 | | - |
| 61 | +XENC_NAMESPACE = "http://www.w3.org/2001/04/xmlenc#" |
| 62 | + |
| 63 | +# this should be configurable by users |
| 64 | +OASIS_DEFAULT_NS_PREFIXES = {'saml': NAMESPACE, 'samlp': SAMLP_NAMESPACE, |
| 65 | + 'ds': DS_NAMESPACE, 'xsi': XSI_NAMESPACE, |
| 66 | + 'xs': XS_NAMESPACE, |
| 67 | + 'mdui': MDUI_NAMESPACE, |
| 68 | + 'md': MD_NAMESPACE, |
| 69 | + 'xenc': XENC_NAMESPACE, |
| 70 | + # mdattr: <ns1:EntityAttributes> |
| 71 | + } |
70 | 72 |
|
71 | 73 | NAMEID_FORMAT_EMAILADDRESS = ( |
72 | 74 | "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress") |
@@ -570,7 +572,8 @@ def _to_element_tree(self): |
570 | 572 | self._add_members_to_element_tree(new_tree) |
571 | 573 | return new_tree |
572 | 574 |
|
573 | | - def register_prefix(self, nspair): |
| 575 | + @staticmethod |
| 576 | + def register_prefix(nspair): |
574 | 577 | """ |
575 | 578 | Register with ElementTree a set of namespaces |
576 | 579 |
|
@@ -698,26 +701,23 @@ def fixup(name): |
698 | 701 | del elem.attrib[key] |
699 | 702 |
|
700 | 703 | def to_string_force_namespace(self, nspair): |
701 | | - |
702 | 704 | elem = self._to_element_tree() |
703 | | - |
704 | 705 | self.set_prefixes(elem, nspair) |
705 | | - |
706 | 706 | return ElementTree.tostring(elem, encoding="UTF-8") |
707 | 707 |
|
708 | | - def to_string(self, nspair=DEFAULT_NS_PREFIXES): |
| 708 | + def to_string(self, nspair=None): |
709 | 709 | """Converts the Saml object to a string containing XML. |
710 | 710 |
|
711 | 711 | :param nspair: A dictionary of prefixes and uris to use when |
712 | 712 | constructing the text representation. |
713 | 713 | :return: String representation of the object |
714 | 714 | """ |
715 | | - if not nspair and self.c_ns_prefix: |
| 715 | + if self.c_ns_prefix: |
716 | 716 | nspair = self.c_ns_prefix |
717 | 717 |
|
718 | 718 | if nspair: |
719 | 719 | self.register_prefix(nspair) |
720 | | - |
| 720 | + |
721 | 721 | return ElementTree.tostring(self._to_element_tree(), encoding="UTF-8") |
722 | 722 |
|
723 | 723 | def __str__(self): |
@@ -1056,3 +1056,6 @@ def is_required_attribute(cls, attr): |
1056 | 1056 | :return: True if required |
1057 | 1057 | """ |
1058 | 1058 | return cls.c_attributes[attr][REQUIRED] |
| 1059 | + |
| 1060 | +# this register preferred prefix namespaces |
| 1061 | +SamlBase.register_prefix(OASIS_DEFAULT_NS_PREFIXES) |
0 commit comments