@@ -749,6 +749,61 @@ public function getAttributes()
749749 return $ attributes ;
750750 }
751751
752+ /**
753+ * Gets the Attributes from the AttributeStatement element using their FriendlyName.
754+ *
755+ * @return array The attributes of the SAML Assertion
756+ */
757+ public function getAttributesWithFriendlyName ()
758+ {
759+ $ attributes = array ();
760+
761+ /* EncryptedAttributes not supported
762+
763+ $encriptedAttributes = $this->_queryAssertion('/saml:AttributeStatement/saml:EncryptedAttribute');
764+
765+ if ($encriptedAttributes->length > 0) {
766+ foreach ($encriptedAttributes as $encriptedAttribute) {
767+ $key = $this->_settings->getSPkey();
768+ $seckey = new XMLSecurityKey(XMLSecurityKey::RSA_1_5, array('type'=>'private'));
769+ $seckey->loadKey($key);
770+ $attribute = OneLogin_Saml2_Utils::decryptElement($encriptedAttribute->firstChild(), $seckey);
771+ }
772+ }
773+ */
774+
775+ $ entries = $ this ->_queryAssertion ('/saml:AttributeStatement/saml:Attribute ' );
776+
777+ /** @var $entry DOMNode */
778+ foreach ($ entries as $ entry ) {
779+ $ attributeFriendlyNameNode = $ entry ->attributes ->getNamedItem ('FriendlyName ' );
780+
781+ if ($ attributeFriendlyNameNode === null ) {
782+ continue ;
783+ }
784+
785+ $ attributeFriendlyName = $ attributeFriendlyNameNode ->nodeValue ;
786+
787+ if (in_array ($ attributeFriendlyName , array_keys ($ attributes ))) {
788+ throw new OneLogin_Saml2_ValidationError (
789+ "Found an Attribute element with duplicated FriendlyName " ,
790+ OneLogin_Saml2_ValidationError::DUPLICATED_ATTRIBUTE_NAME_FOUND
791+ );
792+ }
793+
794+ $ attributeValues = array ();
795+ foreach ($ entry ->childNodes as $ childNode ) {
796+ $ tagName = ($ childNode ->prefix ? $ childNode ->prefix .': ' : '' ) . 'AttributeValue ' ;
797+ if ($ childNode ->nodeType == XML_ELEMENT_NODE && $ childNode ->tagName === $ tagName ) {
798+ $ attributeValues [] = $ childNode ->nodeValue ;
799+ }
800+ }
801+
802+ $ attributes [$ attributeFriendlyName ] = $ attributeValues ;
803+ }
804+ return $ attributes ;
805+ }
806+
752807 /**
753808 * Verifies that the document only contains a single Assertion (encrypted or not).
754809 *
0 commit comments