@@ -732,44 +732,44 @@ public function getSessionIndex()
732732 */
733733 public function getAttributes ()
734734 {
735- $ attributes = array ();
736-
737- /* EncryptedAttributes not supported
738-
739- $encriptedAttributes = $this->_queryAssertion('/saml:AttributeStatement/saml:EncryptedAttribute');
735+ return $ this ->_getAttributesByKeyName ('Name ' );
736+ }
740737
741- if ($encriptedAttributes->length > 0) {
742- foreach ($encriptedAttributes as $encriptedAttribute) {
743- $key = $this->_settings->getSPkey();
744- $seckey = new XMLSecurityKey(XMLSecurityKey::RSA_1_5, array('type'=>'private'));
745- $seckey->loadKey($key);
746- $attribute = Utils::decryptElement($encriptedAttribute->firstChild(), $seckey);
747- }
748- }
749- */
738+ /**
739+ * Gets the Attributes from the AttributeStatement element using their FriendlyName.
740+ *
741+ * @return array The attributes of the SAML Assertion
742+ */
743+ public function getAttributesWithFriendlyName ()
744+ {
745+ return $ this -> _getAttributesByKeyName ( ' FriendlyName ' );
746+ }
750747
748+ private function _getAttributesByKeyName ($ keyName ="Name " )
749+ {
750+ $ attributes = array ();
751751 $ entries = $ this ->_queryAssertion ('/saml:AttributeStatement/saml:Attribute ' );
752-
753- // @var $entry DOMNode
752+ /** @var $entry DOMNode */
754753 foreach ($ entries as $ entry ) {
755- $ attributeName = $ entry ->attributes ->getNamedItem ('Name ' )->nodeValue ;
756-
757- if (in_array ($ attributeName , array_keys ($ attributes ))) {
754+ $ attributeKeyNode = $ entry ->attributes ->getNamedItem ($ keyName );
755+ if ($ attributeKeyNode === null ) {
756+ continue ;
757+ }
758+ $ attributeKeyName = $ attributeKeyNode ->nodeValue ;
759+ if (in_array ($ attributeKeyName , array_keys ($ attributes ))) {
758760 throw new ValidationError (
759- "Found an Attribute element with duplicated Name " ,
761+ "Found an Attribute element with duplicated " . $ keyName ,
760762 ValidationError::DUPLICATED_ATTRIBUTE_NAME_FOUND
761763 );
762764 }
763-
764765 $ attributeValues = array ();
765766 foreach ($ entry ->childNodes as $ childNode ) {
766767 $ tagName = ($ childNode ->prefix ? $ childNode ->prefix .': ' : '' ) . 'AttributeValue ' ;
767768 if ($ childNode ->nodeType == XML_ELEMENT_NODE && $ childNode ->tagName === $ tagName ) {
768769 $ attributeValues [] = $ childNode ->nodeValue ;
769770 }
770771 }
771-
772- $ attributes [$ attributeName ] = $ attributeValues ;
772+ $ attributes [$ attributeKeyName ] = $ attributeValues ;
773773 }
774774 return $ attributes ;
775775 }
0 commit comments