You are here

private function CasProxyHelper::parseProxyTicket in CAS 8

Same name and namespace in other branches
  1. 2.x src/Service/CasProxyHelper.php \Drupal\cas\Service\CasProxyHelper::parseProxyTicket()

Parse proxy ticket from CAS Server response.

Parameters

string $xml: XML response from CAS Server.

Return value

mixed A proxy ticket to be used with the target service, FALSE on failure.

Throws

\Drupal\cas\Exception\CasProxyException Thrown if there was a problem parsing the proxy validation response.

1 call to CasProxyHelper::parseProxyTicket()
CasProxyHelper::getProxyTicket in src/Service/CasProxyHelper.php
Get a proxy ticket using a proxy granting ticket.

File

src/Service/CasProxyHelper.php, line 200

Class

CasProxyHelper
Class CasProxyHelper.

Namespace

Drupal\cas\Service

Code

private function parseProxyTicket($xml) {
  $dom = new \DOMDocument();
  $dom->preserveWhiteSpace = FALSE;
  $dom->encoding = "utf-8";
  if (@$dom
    ->loadXML($xml) === FALSE) {
    throw new CasProxyException("CAS Server returned non-XML response.");
  }
  $failure_elements = $dom
    ->getElementsByTagName("proxyFailure");
  if ($failure_elements->length > 0) {

    // Something went wrong with proxy ticket validation.
    throw new CasProxyException("CAS Server rejected proxy request.");
  }
  $success_elements = $dom
    ->getElementsByTagName("proxySuccess");
  if ($success_elements->length === 0) {

    // Malformed response from CAS Server.
    throw new CasProxyException("CAS Server returned malformed response.");
  }
  $success_element = $success_elements
    ->item(0);
  $proxy_ticket = $success_element
    ->getElementsByTagName("proxyTicket");
  if ($proxy_ticket->length === 0) {

    // Malformed ticket.
    throw new CasProxyException("CAS Server provided invalid or malformed ticket.");
  }
  return $proxy_ticket
    ->item(0)->nodeValue;
}