You are here

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

Convert this assertion to an XML element.

Parameters

DOMNode|NULL $parentElement The DOM node the assertion should be created in.:

Return value

DOMElement This assertion.

File

src/SAML2_Assertion.php, line 590

Class

SAML2_Assertion

Namespace

Drupal\miniorange_saml

Code

public function toXML(DOMNode $parentElement = NULL) {
  if ($parentElement === NULL) {
    $document = new DOMDocument();
    $parentElement = $document;
  }
  else {
    $document = $parentElement->ownerDocument;
  }
  $root = $document
    ->createElementNS('urn:oasis:names:tc:SAML:2.0:assertion', 'saml:' . 'Assertion');
  $parentElement
    ->appendChild($root);

  /* Ugly hack to add another namespace declaration to the root element. */
  $root
    ->setAttributeNS('urn:oasis:names:tc:SAML:2.0:protocol', 'samlp:tmp', 'tmp');
  $root
    ->removeAttributeNS('urn:oasis:names:tc:SAML:2.0:protocol', 'tmp');
  $root
    ->setAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi:tmp', 'tmp');
  $root
    ->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'tmp');
  $root
    ->setAttributeNS('http://www.w3.org/2001/XMLSchema', 'xs:tmp', 'tmp');
  $root
    ->removeAttributeNS('http://www.w3.org/2001/XMLSchema', 'tmp');
  $root
    ->setAttribute('ID', $this->id);
  $root
    ->setAttribute('Version', '2.0');
  $root
    ->setAttribute('IssueInstant', gmdate('Y-m-d\\TH:i:s\\Z', $this->issueInstant));
  $issuer = Utilities::addString($root, 'urn:oasis:names:tc:SAML:2.0:assertion', 'saml:Issuer', $this->issuer);
  $this
    ->addSubject($root);
  $this
    ->addConditions($root);
  $this
    ->addAuthnStatement($root);
  if ($this->requiredEncAttributes == FALSE) {
    $this
      ->addAttributeStatement($root);
  }
  else {
    $this
      ->addEncryptedAttributeStatement($root);
  }
  if ($this->signatureKey !== NULL) {
    Utilities::insertSignature($this->signatureKey, $this->certificates, $root, $issuer->nextSibling);
  }
  return $root;
}