Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions src/saml2/attribute_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from saml2 import saml, ExtensionElement, NAMESPACE
from saml2 import extension_elements_to_elements
from saml2 import SAMLError
from saml2.saml import NAME_FORMAT_UNSPECIFIED, NAMEID_FORMAT_PERSISTENT
from saml2.saml import NAME_FORMAT_UNSPECIFIED, NAMEID_FORMAT_PERSISTENT, NameID, XSI_TYPE

import logging
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -344,7 +344,38 @@ def ava_from(self, attribute, allow_unknown=False):
elif not value.text:
val.append('')
else:
val.append(value.text.strip())
cur_val = value.text.strip()
if XSI_TYPE in value.extension_attributes:
cur_type = value.extension_attributes[XSI_TYPE]
cur_type_prefix = None
if cur_type.find(":") > 0:
cur_type_prefix = cur_type[0:cur_type.find(":")]
if ("xmlns:" + cur_type_prefix) in value.extension_attributes:
cur_type = "{" + value.extension_attributes["xmlns:" + cur_type_prefix] + "}" + cur_type[(len(cur_type_prefix) + 1):]

if cur_type == "{http://www.w3.org/2001/XMLSchema}boolean":
cur_val = (True if cur_val == "true" else False)
elif cur_type in ["{http://www.w3.org/2001/XMLSchema}decimal",
"{http://www.w3.org/2001/XMLSchema}float",
"{http://www.w3.org/2001/XMLSchema}double",
"{http://www.w3.org/2001/XMLSchema}float"]:
cur_val = float(cur_val)
elif cur_type in ["{http://www.w3.org/2001/XMLSchema}integer",
"{http://www.w3.org/2001/XMLSchema}nonPositiveInteger",
"{http://www.w3.org/2001/XMLSchema}negativeInteger",
"{http://www.w3.org/2001/XMLSchema}int",
"{http://www.w3.org/2001/XMLSchema}short",
"{http://www.w3.org/2001/XMLSchema}byte",
"{http://www.w3.org/2001/XMLSchema}nonNegativeInteger",
"{http://www.w3.org/2001/XMLSchema}unsignedInt",
"{http://www.w3.org/2001/XMLSchema}unsignedShort",
"{http://www.w3.org/2001/XMLSchema}unsignedByte",
"{http://www.w3.org/2001/XMLSchema}positiveInteger"]:
cur_val = int(cur_val)
elif cur_type in ["{http://www.w3.org/2001/XMLSchema}long",
"{http://www.w3.org/2001/XMLSchema}unsignedLong"]:
cur_val = long(cur_val)
val.append(cur_val)

return attr, val

Expand Down