CAS_Client::forceAuthentication PHP Method

forceAuthentication() public method

This method is called to be sure that the user is authenticated. When not authenticated, halt by redirecting to the CAS server; otherwise return true.
public forceAuthentication ( ) : true
return true when the user is authenticated; otherwise halt.
    public function forceAuthentication()
    {
        phpCAS::traceBegin();
        if ($this->isAuthenticated()) {
            // the user is authenticated, nothing to be done.
            phpCAS::trace('no need to authenticate');
            $res = true;
        } else {
            // the user is not authenticated, redirect to the CAS server
            if (isset($_SESSION['phpCAS']['auth_checked'])) {
                unset($_SESSION['phpCAS']['auth_checked']);
            }
            $this->redirectToCas(false);
            // never reached
            $res = false;
        }
        phpCAS::traceEnd($res);
        return $res;
    }

Usage Example

 /**
  * Test that the user is redirected to the CAS server
  */
 public function test_redirect()
 {
     try {
         ob_start();
         $this->object->forceAuthentication();
         $this->assertTrue(false, 'Should have thrown a CAS_GracefullTerminationException.');
     } catch (CAS_GracefullTerminationException $e) {
         ob_end_clean();
         // It would be great to test for the existance of headers here, but
         // the don't get set properly due to output before the test.
     }
 }
All Usage Examples Of CAS_Client::forceAuthentication
CAS_Client