You are here

function cas_init in CAS 7

Same name and namespace in other branches
  1. 6.3 cas.module \cas_init()
  2. 6 cas.module \cas_init()
  3. 6.2 cas.module \cas_init()

Implements hook_init().

Traps a page load to see if authentication is required.

File

./cas.module, line 29
Enables users to authenticate via a Central Authentication Service (CAS) Cas will currently work if the auto registration is turned on and will create user accounts automatically.

Code

function cas_init() {
  global $user;
  if (module_exists('cas_test') && arg(0) == 'cas_test') {

    // We are destined for a page handled by the cas_test module, so do not
    // do any processing here. Necessary for CAS gateway tests.
    return;
  }
  elseif (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE === 'install') {

    // Do nothing on profile install.
    return;
  }

  // Process a single-sign out request.
  _cas_single_sign_out_check();

  // If a user is not logged in, consider using CAS authentication.
  if (!$user->uid) {
    $force_authentication = _cas_force_login();
    $check_authentication = _cas_allow_check_for_login();
    $request_type = $_SERVER['REQUEST_METHOD'];
    $perform_login_check = $force_authentication || $check_authentication && $request_type == 'GET';
    if ($perform_login_check) {
      cas_login_check($force_authentication);
    }
  }
}