コード例 #1
0
 /**
  * Class EcasPhpCASParser
  * @param \DOMElement $root XML element coming from phpCAS
  * @return array Attributes
  * @see \phpCAS
  */
 public function parse(\DOMElement $root)
 {
     phpCAS::trace('Found attribute ' . $root->nodeName);
     $result = array();
     if ($root->hasAttributes()) {
         $attrs = $root->attributes;
         foreach ($attrs as $attr) {
             if ($attr->name == 'number') {
                 continue;
             }
             phpCAS::trace('Additional attribute ' . $attr->name . ' : ' . $attr->value);
             $result['@attributes'][$attr->name] = $attr->value;
         }
     }
     if ($root->hasChildNodes()) {
         $children = $root->childNodes;
         if ($children->length == 1) {
             $child = $children->item(0);
             if ($child->nodeType == XML_TEXT_NODE) {
                 $result['_value'] = $child->nodeValue;
                 return count($result) == 1 ? $result['_value'] : $result;
             }
         }
         $groups = array();
         foreach ($children as $child) {
             $nodeName = str_replace('cas:', '', $child->nodeName);
             phpCAS::traceBegin();
             if ($nodeName == 'groups') {
                 $result['groups'] = array();
                 phpCas::traceBegin();
                 foreach ($child->childNodes as $groupChild) {
                     $result['groups'][] = $this->parse($groupChild);
                 }
                 phpCAS::traceEnd('Parsed groups');
             } elseif (!isset($result[$nodeName])) {
                 $result[$nodeName] = $this->parse($child);
             } else {
                 if (!isset($groups[$nodeName])) {
                     $result[$nodeName] = array($result[$nodeName]);
                     $groups[$nodeName] = 1;
                 }
                 $result[$nodeName][] = $this->parse($child);
             }
             phpCAS::traceEnd();
         }
     }
     return $result;
 }
コード例 #2
0
 /**
  * This method is used to redirect the client to the CAS server.
  * It is used by CASClient::forceAuthentication() and CASClient::checkAuthentication().
  * @param $gateway true to check authentication, false to force it
  * @public
  */
 function redirectToCas($gateway = false)
 {
     $cas = new phpCas();
     $cas->traceBegin();
     $cas_url = $this->getServerLoginURL($gateway);
     header('Location: ' . $cas_url);
     $this->printHTMLHeader($this->getString(CAS_STR_AUTHENTICATION_WANTED));
     printf('<p>' . $this->getString(CAS_STR_SHOULD_HAVE_BEEN_REDIRECTED) . '</p>', $cas_url);
     $this->printHTMLFooter();
     $cas->traceExit();
     exit;
 }