CAS_Client::checkAuthentication PHP Method

checkAuthentication() public method

This method is called to check whether the user is authenticated or not.
public checkAuthentication ( ) : true
return true when the user is authenticated, false when a previous gateway login failed or the function will not return if the user is redirected to the cas server for a gateway login attempt
    public function checkAuthentication()
    {
        phpCAS::traceBegin();
        $res = false;
        if ($this->isAuthenticated()) {
            phpCAS::trace('user is authenticated');
            /* The 'auth_checked' variable is removed just in case it's set. */
            unset($_SESSION['phpCAS']['auth_checked']);
            $res = true;
        } else {
            if (isset($_SESSION['phpCAS']['auth_checked'])) {
                // the previous request has redirected the client to the CAS server
                // with gateway=true
                unset($_SESSION['phpCAS']['auth_checked']);
                $res = false;
            } else {
                // avoid a check against CAS on every request
                if (!isset($_SESSION['phpCAS']['unauth_count'])) {
                    $_SESSION['phpCAS']['unauth_count'] = -2;
                    // uninitialized
                }
                if ($_SESSION['phpCAS']['unauth_count'] != -2 && $this->_cache_times_for_auth_recheck == -1 || $_SESSION['phpCAS']['unauth_count'] >= 0 && $_SESSION['phpCAS']['unauth_count'] < $this->_cache_times_for_auth_recheck) {
                    $res = false;
                    if ($this->_cache_times_for_auth_recheck != -1) {
                        $_SESSION['phpCAS']['unauth_count']++;
                        phpCAS::trace('user is not authenticated (cached for ' . $_SESSION['phpCAS']['unauth_count'] . ' times of ' . $this->_cache_times_for_auth_recheck . ')');
                    } else {
                        phpCAS::trace('user is not authenticated (cached for until login pressed)');
                    }
                } else {
                    $_SESSION['phpCAS']['unauth_count'] = 0;
                    $_SESSION['phpCAS']['auth_checked'] = true;
                    phpCAS::trace('user is not authenticated (cache reset)');
                    $this->redirectToCas(true);
                    // never reached
                    $res = false;
                }
            }
        }
        phpCAS::traceEnd($res);
        return $res;
    }

Usage Example

示例#1
0
文件: CAS.php 项目: DCUnit711/Demeter
 /**
  * This method is called to check if the user is already authenticated
  * locally or has a global cas session. A already existing cas session is
  * determined by a cas gateway call.(cas login call without any interactive
  * prompt)
  *
  * @return true when the user is authenticated, false when a previous
  * gateway login failed or the function will not return if the user is
  * redirected to the cas server for a gateway login attempt
  */
 public static function checkAuthentication()
 {
     phpCAS::traceBegin();
     phpCAS::_validateClientExists();
     $auth = self::$_PHPCAS_CLIENT->checkAuthentication();
     // store where the authentication has been checked and the result
     self::$_PHPCAS_CLIENT->markAuthenticationCall($auth);
     phpCAS::traceEnd($auth);
     return $auth;
 }
CAS_Client