@@ -573,49 +573,25 @@ def get_attributes(self):
573573 Gets the Attributes from the AttributeStatement element.
574574 EncryptedAttributes are not supported
575575 """
576- attributes = {}
577- attribute_nodes = self .__query_assertion ('/saml:AttributeStatement/saml:Attribute' )
578- for attribute_node in attribute_nodes :
579- attr_name = attribute_node .get ('Name' )
580- if attr_name in attributes .keys ():
581- raise OneLogin_Saml2_ValidationError (
582- 'Found an Attribute element with duplicated Name' ,
583- OneLogin_Saml2_ValidationError .DUPLICATED_ATTRIBUTE_NAME_FOUND
584- )
585-
586- values = []
587- for attr in attribute_node .iterchildren ('{%s}AttributeValue' % OneLogin_Saml2_Constants .NSMAP ['saml' ]):
588- attr_text = OneLogin_Saml2_XML .element_text (attr )
589- if attr_text :
590- attr_text = attr_text .strip ()
591- if attr_text :
592- values .append (attr_text )
593-
594- # Parse any nested NameID children
595- for nameid in attr .iterchildren ('{%s}NameID' % OneLogin_Saml2_Constants .NSMAP ['saml' ]):
596- values .append ({
597- 'NameID' : {
598- 'Format' : nameid .get ('Format' ),
599- 'NameQualifier' : nameid .get ('NameQualifier' ),
600- 'value' : nameid .text
601- }
602- })
603- attributes [attr_name ] = values
604- return attributes
576+ return self ._get_attributes ('Name' )
605577
606578 def get_friendlyname_attributes (self ):
607579 """
608580 Gets the Attributes from the AttributeStatement element indexed by FiendlyName.
609581 EncryptedAttributes are not supported
610582 """
583+ return self ._get_attributes ('FriendlyName' )
584+
585+ def _get_attributes (self , attr_name ):
586+ allow_duplicates = self .__settings .get_security_data ().get ('allowRepeatAttributeName' , False )
611587 attributes = {}
612588 attribute_nodes = self .__query_assertion ('/saml:AttributeStatement/saml:Attribute' )
613589 for attribute_node in attribute_nodes :
614- attr_friendlyname = attribute_node .get ('FriendlyName' )
615- if attr_friendlyname :
616- if attr_friendlyname in attributes . keys () :
590+ attr_key = attribute_node .get (attr_name )
591+ if attr_key :
592+ if not allow_duplicates and attr_key in attributes :
617593 raise OneLogin_Saml2_ValidationError (
618- 'Found an Attribute element with duplicated FriendlyName' ,
594+ 'Found an Attribute element with duplicated ' + attr_name ,
619595 OneLogin_Saml2_ValidationError .DUPLICATED_ATTRIBUTE_NAME_FOUND
620596 )
621597
@@ -636,7 +612,10 @@ def get_friendlyname_attributes(self):
636612 'value' : nameid .text
637613 }
638614 })
639- attributes [attr_friendlyname ] = values
615+ if attr_key in attributes :
616+ attributes [attr_key ].extend (values )
617+ else :
618+ attributes [attr_key ] = values
640619 return attributes
641620
642621 def validate_num_assertions (self ):
0 commit comments