You are here

private function SAML2_Assertion::addAttributeStatement in SAML SP 2.0 Single Sign On (SSO) - SAML Service Provider 8

Add an AttributeStatement-node to the assertion.

Parameters

DOMElement $root The assertion element we should add the subject to.:

1 call to SAML2_Assertion::addAttributeStatement()
SAML2_Assertion::toXML in src/SAML2_Assertion.php
Convert this assertion to an XML element.

File

src/SAML2_Assertion.php, line 761

Class

SAML2_Assertion

Namespace

Drupal\miniorange_saml

Code

private function addAttributeStatement(DOMElement $root) {
  if (empty($this->attributes)) {
    return;
  }
  $document = $root->ownerDocument;
  $attributeStatement = $document
    ->createElementNS('urn:oasis:names:tc:SAML:2.0:assertion', 'saml:AttributeStatement');
  $root
    ->appendChild($attributeStatement);
  foreach ($this->attributes as $name => $values) {
    $attribute = $document
      ->createElementNS('urn:oasis:names:tc:SAML:2.0:assertion', 'saml:Attribute');
    $attributeStatement
      ->appendChild($attribute);
    $attribute
      ->setAttribute('Name', $name);
    if ($this->nameFormat !== 'urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified') {
      $attribute
        ->setAttribute('NameFormat', $this->nameFormat);
    }
    foreach ($values as $value) {
      if (is_string($value)) {
        $type = 'xs:string';
      }
      elseif (is_int($value)) {
        $type = 'xs:integer';
      }
      else {
        $type = NULL;
      }
      $attributeValue = $document
        ->createElementNS('urn:oasis:names:tc:SAML:2.0:assertion', 'saml:AttributeValue');
      $attribute
        ->appendChild($attributeValue);
      if ($type !== NULL) {
        $attributeValue
          ->setAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi:type', $type);
      }
      if (is_null($value)) {
        $attributeValue
          ->setAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi:nil', 'true');
      }
      if ($value instanceof DOMNodeList) {
        for ($i = 0; $i < $value->length; $i++) {
          $node = $document
            ->importNode($value
            ->item($i), TRUE);
          $attributeValue
            ->appendChild($node);
        }
      }
      else {
        $attributeValue
          ->appendChild($document
          ->createTextNode($value));
      }
    }
  }
}