This method is used to validate a cas 2.0 ST or PT; halt on failure Used for all CAS 2.0 validations.
3260 {
3264
3268 } else {
3271 }
3272
3274
3276 }
3277
3278 if ($renew) {
3279
3280 $validate_url .= '&renew=true';
3281 }
3282
3283
3284 if (!$this->
_readURL($validate_url, $headers, $text_response, $err_msg)) {
3286 'could not open URL \'' . $validate_url . '\' to validate (' . $err_msg . ')'
3287 );
3288 throw new CAS_AuthenticationException(
3289 $this,
3290 'Ticket not validated',
3291 $validate_url,
3292 true/*$no_response*/
3293 );
3294 $result = false;
3295 }
3296
3297 // create new DOMDocument object
3298 $dom = new DOMDocument();
3299 // Fix possible whitspace problems
3300 $dom->preserveWhiteSpace = false;
3301 // CAS servers should only return data in utf-8
3302 $dom->encoding = "utf-8";
3303 // read the response of the CAS server into a DOMDocument object
3304 if (!($dom->loadXML($text_response))) {
3305 // read failed
3306 throw new CAS_AuthenticationException(
3307 $this,
3308 'Ticket not validated',
3309 $validate_url,
3310 false/*$no_response*/,
3311 true/*$bad_response*/,
3312 $text_response
3313 );
3314 $result = false;
3315 } elseif (!($tree_response = $dom->documentElement)) {
3316 // read the root node of the XML tree
3317 // read failed
3318 throw new CAS_AuthenticationException(
3319 $this,
3320 'Ticket not validated',
3321 $validate_url,
3322 false/*$no_response*/,
3323 true/*$bad_response*/,
3324 $text_response
3325 );
3326 $result = false;
3327 } elseif ($tree_response->localName != 'serviceResponse') {
3328 // insure that tag name is 'serviceResponse'
3329 // bad root node
3330 throw new CAS_AuthenticationException(
3331 $this,
3332 'Ticket not validated',
3333 $validate_url,
3334 false/*$no_response*/,
3335 true/*$bad_response*/,
3336 $text_response
3337 );
3338 $result = false;
3339 } elseif ($tree_response->getElementsByTagName("authenticationFailure")->length != 0) {
3340 // authentication failed, extract the error code and message and throw exception
3341 $auth_fail_list = $tree_response
3342 ->getElementsByTagName("authenticationFailure");
3343 throw new CAS_AuthenticationException(
3344 $this,
3345 'Ticket not validated',
3346 $validate_url,
3347 false/*$no_response*/,
3348 false/*$bad_response*/,
3349 $text_response,
3350 $auth_fail_list->item(0)->getAttribute('code')/*$err_code*/,
3351 trim($auth_fail_list->item(0)->nodeValue)/*$err_msg*/
3352 );
3353 $result = false;
3354 } elseif ($tree_response->getElementsByTagName("authenticationSuccess")->length != 0) {
3355 // authentication succeded, extract the user name
3356 $success_elements = $tree_response
3357 ->getElementsByTagName("authenticationSuccess");
3358 if ($success_elements->item(0)->getElementsByTagName("user")->length == 0) {
3359 // no user specified => error
3360 throw new CAS_AuthenticationException(
3361 $this,
3362 'Ticket not validated',
3363 $validate_url,
3364 false/*$no_response*/,
3365 true/*$bad_response*/,
3366 $text_response
3367 );
3368 $result = false;
3369 } else {
3370 $this->_setUser(
3371 trim(
3372 $success_elements->item(0)->getElementsByTagName("user")->item(0)->nodeValue
3373 )
3374 );
3375 $this->_readExtraAttributesCas20($success_elements);
3376 // Store the proxies we are sitting behind for authorization checking
3377 $proxyList = array();
3378 if (sizeof($arr = $success_elements->item(0)->getElementsByTagName("proxy")) > 0) {
3379 foreach ($arr as $proxyElem) {
3380 phpCAS::trace("Found Proxy: " . $proxyElem->nodeValue);
3381 $proxyList[] = trim($proxyElem->nodeValue);
3382 }
3383 $this->_setProxies($proxyList);
3384 phpCAS::trace("Storing Proxy List");
3385 }
3386 // Check if the proxies in front of us are allowed
3387 if (!$this->getAllowedProxyChains()->isProxyListAllowed($proxyList)) {
3388 throw new CAS_AuthenticationException(
3389 $this,
3390 'Proxy not allowed',
3391 $validate_url,
3392 false/*$no_response*/,
3393 true/*$bad_response*/,
3394 $text_response
3395 );
3396 $result = false;
3397 } else {
3398 $result = true;
3399 }
3400 }
3401 } else {
3402 throw new CAS_AuthenticationException(
3403 $this,
3404 'Ticket not validated',
3405 $validate_url,
3406 false/*$no_response*/,
3407 true/*$bad_response*/,
3408 $text_response
3409 );
3410 $result = false;
3411 }
3412 if ($result) {
3413 $this->_renameSession($this->getTicket());
3414 }
3415 // at this step, Ticket has been validated and $this->_user has been set,
3416
3417 phpCAS::traceEnd($result);
3418 return $result;
3419 }
getTicket()
This method returns the Service Ticket provided in the URL of the request.
_getCallbackURL()
This method returns the URL that should be used for the PGT callback (in fact the URL of the current ...
getServerServiceValidateURL()
This method is used to retrieve the service validating URL of the CAS server.
getServerProxyValidateURL()
This method is used to retrieve the proxy validating URL of the CAS server.
_readURL($url, &$headers, &$body, &$err_msg)
This method is used to acces a remote URL.
isProxy()
Tells if a CAS client is a CAS proxy or not.
getAllowedProxyChains()
Answer the CAS_ProxyChain_AllowedList object for this client.
static trace($str)
This method is used to log something in debug mode.