OneLogin_Saml2_Response::getAttributes PHP Method

getAttributes() public method

Gets the Attributes from the AttributeStatement element.
public getAttributes ( ) : array
return array The attributes of the SAML Assertion
    public function getAttributes()
    {
        $attributes = array();
        /* EncryptedAttributes not supported
        
                $encriptedAttributes = $this->_queryAssertion('/saml:AttributeStatement/saml:EncryptedAttribute');
        
                if ($encriptedAttributes->length > 0) {
                    foreach ($encriptedAttributes as $encriptedAttribute) {
                        $key = $this->_settings->getSPkey();
                        $seckey = new XMLSecurityKey(XMLSecurityKey::RSA_1_5, array('type'=>'private'));
                        $seckey->loadKey($key);
                        $attribute = OneLogin_Saml2_Utils::decryptElement($encriptedAttribute->firstChild(), $seckey);
                    }
                }
                */
        $entries = $this->_queryAssertion('/saml:AttributeStatement/saml:Attribute');
        /** @var $entry DOMNode */
        foreach ($entries as $entry) {
            $attributeName = $entry->attributes->getNamedItem('Name')->nodeValue;
            if (in_array($attributeName, array_keys($attributes))) {
                throw new Exception("Found an Attribute element with duplicated Name");
            }
            $attributeValues = array();
            foreach ($entry->childNodes as $childNode) {
                $tagName = ($childNode->prefix ? $childNode->prefix . ':' : '') . 'AttributeValue';
                if ($childNode->nodeType == XML_ELEMENT_NODE && $childNode->tagName === $tagName) {
                    $attributeValues[] = $childNode->nodeValue;
                }
            }
            $attributes[$attributeName] = $attributeValues;
        }
        return $attributes;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Process the SAML Response sent by the IdP.
  *
  * @param string $requestId The ID of the AuthNRequest sent by this SP to the IdP
  */
 public function processResponse($requestId = null)
 {
     $this->_errors = array();
     if (isset($_POST) && isset($_POST['SAMLResponse'])) {
         // AuthnResponse -- HTTP_POST Binding
         $response = new OneLogin_Saml2_Response($this->_settings, $_POST['SAMLResponse']);
         if ($response->isValid($requestId)) {
             $this->_attributes = $response->getAttributes();
             $this->_nameid = $response->getNameId();
             $this->_authenticated = true;
         } else {
             $this->_errors[] = 'invalid_response';
         }
     } else {
         $this->_errors[] = 'invalid_binding';
         throw new OneLogin_Saml2_Error('SAML Response not found, Only supported HTTP_POST Binding', OneLogin_Saml2_Error::SAML_RESPONSE_NOT_FOUND);
     }
 }
All Usage Examples Of OneLogin_Saml2_Response::getAttributes