/**
  * Parse CAS server validation response content.
  *
  * @param string $content
  *
  * @return CasLoginData
  */
 public function parseResponse($content)
 {
     $dom = new \DOMDocument();
     $dom->preserveWhiteSpace = false;
     $dom->encoding = "utf-8";
     $data = new CasLoginData();
     if (@$dom->loadXML($content) !== false) {
         $failureElements = $dom->getElementsByTagName('authenticationFailure');
         if ($failureElements->length == 0) {
             $successElements = $dom->getElementsByTagName("authenticationSuccess");
             if ($successElements->length == 1) {
                 // There should only be one success element, grab it and extract username.
                 $successElement = $successElements->item(0);
                 $userElement = $successElement->getElementsByTagName("user");
                 if ($userElement->length == 1) {
                     $data->setUsername($userElement->item(0)->nodeValue);
                     $data->setSuccess();
                 } else {
                     $data->setFailure('Malformed CAS validation data.');
                 }
             } else {
                 // All reponses should have either an authenticationFailure
                 // or authenticationSuccess node.
                 $data->setFailure('Malformed CAS validation data.');
             }
         } else {
             $failureElement = $failureElements->item(0);
             $errorCode = $failureElement->getAttribute('code');
             $errorMsg = $failureElement->nodeValue;
             $data->setFailure('CAS Validation error: ' . trim($errorCode) . ': ' . trim($errorMsg));
         }
     } else {
         $data->setFailure('Malformed CAS validation data.');
     }
     return $data;
 }
 /**
  * Parse CAS server validation response content.
  *
  * @param string $content
  *
  * @return CasLoginData
  */
 public function parseResponse($content)
 {
     $splitContent = explode("\n", str_replace("\n\n", "\n", str_replace("\r", "\n", $content)));
     $success = strtolower($splitContent[0] === 'yes');
     $data = new CasLoginData();
     if ($success) {
         // Extract the username from the message field and return it.
         $username = count($splitContent) > 1 && $splitContent[1] ? $splitContent[1] : null;
         if ($username) {
             $data->setUsername($username);
             $data->setSuccess();
         } else {
             $data->setFailure('Malformed CAS validation data.');
         }
     } else {
         $data->setFailure('Unknown CAS validation failure.');
     }
     return $data;
 }
 /**
  * Inspects login data object for a failure and throws exception if needed.
  *
  * @param CasLoginData $loginData
  */
 protected function checkLoginFailure(CasLoginData $loginData)
 {
     if (!$loginData->isSuccess()) {
         throw new AuthenticationException($loginData->getFailureMessage());
     }
 }