This method is used to validate a cas 2.0 ST or PT; halt on failure Used for all CAS 2.0 validations.
3167 {
3171
3175 } else {
3178 }
3179
3181
3183 }
3184
3185 if ( $renew ) {
3186
3187 $validate_url .= '&renew=true';
3188 }
3189
3190
3191 if ( !$this->
_readURL($validate_url, $headers, $text_response, $err_msg) ) {
3193 'could not open URL \''.$validate_url.'\' to validate ('.$err_msg.')'
3194 );
3195 throw new CAS_AuthenticationException(
3196 $this, 'Ticket not validated', $validate_url,
3197 true/*$no_response*/
3198 );
3199 $result = false;
3200 }
3201
3202 // create new DOMDocument object
3203 $dom = new DOMDocument();
3204 // Fix possible whitspace problems
3205 $dom->preserveWhiteSpace = false;
3206 // CAS servers should only return data in utf-8
3207 $dom->encoding = "utf-8";
3208 // read the response of the CAS server into a DOMDocument object
3209 if ( !($dom->loadXML($text_response))) {
3210 // read failed
3211 throw new CAS_AuthenticationException(
3212 $this, 'Ticket not validated', $validate_url,
3213 false/*$no_response*/, true/*$bad_response*/, $text_response
3214 );
3215 $result = false;
3216 } else if ( !($tree_response = $dom->documentElement) ) {
3217 // read the root node of the XML tree
3218 // read failed
3219 throw new CAS_AuthenticationException(
3220 $this, 'Ticket not validated', $validate_url,
3221 false/*$no_response*/, true/*$bad_response*/, $text_response
3222 );
3223 $result = false;
3224 } else if ($tree_response->localName != 'serviceResponse') {
3225 // insure that tag name is 'serviceResponse'
3226 // bad root node
3227 throw new CAS_AuthenticationException(
3228 $this, 'Ticket not validated', $validate_url,
3229 false/*$no_response*/, true/*$bad_response*/, $text_response
3230 );
3231 $result = false;
3232 } else if ( $tree_response->getElementsByTagName("authenticationFailure")->length != 0) {
3233 // authentication failed, extract the error code and message and throw exception
3234 $auth_fail_list = $tree_response
3235 ->getElementsByTagName("authenticationFailure");
3236 throw new CAS_AuthenticationException(
3237 $this, 'Ticket not validated', $validate_url,
3238 false/*$no_response*/, false/*$bad_response*/,
3239 $text_response,
3240 $auth_fail_list->item(0)->getAttribute('code')/*$err_code*/,
3241 trim($auth_fail_list->item(0)->nodeValue)/*$err_msg*/
3242 );
3243 $result = false;
3244 } else if ($tree_response->getElementsByTagName("authenticationSuccess")->length != 0) {
3245 // authentication succeded, extract the user name
3246 $success_elements = $tree_response
3247 ->getElementsByTagName("authenticationSuccess");
3248 if ( $success_elements->item(0)->getElementsByTagName("user")->length == 0) {
3249 // no user specified => error
3250 throw new CAS_AuthenticationException(
3251 $this, 'Ticket not validated', $validate_url,
3252 false/*$no_response*/, true/*$bad_response*/, $text_response
3253 );
3254 $result = false;
3255 } else {
3256 $this->_setUser(
3257 trim(
3258 $success_elements->item(0)->getElementsByTagName("user")->item(0)->nodeValue
3259 )
3260 );
3261 $this->_readExtraAttributesCas20($success_elements);
3262 // Store the proxies we are sitting behind for authorization checking
3263 $proxyList = array();
3264 if ( sizeof($arr = $success_elements->item(0)->getElementsByTagName("proxy")) > 0) {
3265 foreach ($arr as $proxyElem) {
3266 phpCAS::trace("Found Proxy: ".$proxyElem->nodeValue);
3267 $proxyList[] = trim($proxyElem->nodeValue);
3268 }
3269 $this->_setProxies($proxyList);
3270 phpCAS::trace("Storing Proxy List");
3271 }
3272 // Check if the proxies in front of us are allowed
3273 if (!$this->getAllowedProxyChains()->isProxyListAllowed($proxyList)) {
3274 throw new CAS_AuthenticationException(
3275 $this, 'Proxy not allowed', $validate_url,
3276 false/*$no_response*/, true/*$bad_response*/,
3277 $text_response
3278 );
3279 $result = false;
3280 } else {
3281 $result = true;
3282 }
3283 }
3284 } else {
3285 throw new CAS_AuthenticationException(
3286 $this, 'Ticket not validated', $validate_url,
3287 false/*$no_response*/, true/*$bad_response*/,
3288 $text_response
3289 );
3290 $result = false;
3291 }
3292 if ($result) {
3293 $this->_renameSession($this->getTicket());
3294 }
3295 // at this step, Ticket has been validated and $this->_user has been set,
3296
3297 phpCAS::traceEnd($result);
3298 return $result;
3299 }
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.