From ec9d640207a0ed2c31b6c7f464fa700573969714 Mon Sep 17 00:00:00 2001 From: Giuseppe De Marco Date: Fri, 19 Jul 2019 17:35:03 +0200 Subject: [PATCH] prettify XML string output by registering default namespace prefixes as @spaceone already proposed here: https://github.com/IdentityPython/pysaml2/pull/326 --- src/saml2/__init__.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/saml2/__init__.py b/src/saml2/__init__.py index 292513da5..d2a24cfe6 100644 --- a/src/saml2/__init__.py +++ b/src/saml2/__init__.py @@ -46,10 +46,28 @@ root_logger = logging.getLogger(__name__) root_logger.level = logging.NOTSET + NAMESPACE = 'urn:oasis:names:tc:SAML:2.0:assertion' # TEMPLATE = '{urn:oasis:names:tc:SAML:2.0:assertion}%s' # XSI_NAMESPACE = 'http://www.w3.org/2001/XMLSchema-instance' +# spaceone's https://github.com/IdentityPython/pysaml2/pull/326 +SAMLP_NAMESPACE = 'urn:oasis:names:tc:SAML:2.0:protocol' +XSI_NAMESPACE = 'http://www.w3.org/2001/XMLSchema-instance' +XS_NAMESPACE = 'http://www.w3.org/2001/XMLSchema' +DS_NAMESPACE = 'http://www.w3.org/2000/09/xmldsig#' +MD_NAMESPACE = "urn:oasis:names:tc:SAML:2.0:metadata" +MDUI_NAMESPACE = "urn:oasis:names:tc:SAML:metadata:ui" +DEFAULT_NS_PREFIXES = {'saml': NAMESPACE, 'samlp': SAMLP_NAMESPACE, + 'ds': DS_NAMESPACE, 'xsi': XSI_NAMESPACE, + 'xs': XS_NAMESPACE, + 'mdui': MDUI_NAMESPACE, + 'md': MD_NAMESPACE, + # 'alg': TODO: algsupport.DIGEST_METHODS|SIGNING_METHODS shoulb be moved before mapping them here + # TODO: + } + + NAMEID_FORMAT_EMAILADDRESS = ( "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress") @@ -687,7 +705,7 @@ def to_string_force_namespace(self, nspair): return ElementTree.tostring(elem, encoding="UTF-8") - def to_string(self, nspair=None): + def to_string(self, nspair=DEFAULT_NS_PREFIXES): """Converts the Saml object to a string containing XML. :param nspair: A dictionary of prefixes and uris to use when