You are here

function _cas_force_login in CAS 6.2

Same name and namespace in other branches
  1. 5.4 cas.module \_cas_force_login()
  2. 5 cas.module \_cas_force_login()
  3. 5.3 cas.module \_cas_force_login()
  4. 6.3 cas.module \_cas_force_login()
  5. 6 cas.module \_cas_force_login()
  6. 7 cas.module \_cas_force_login()

Determines whether cas login should be enforced for this page load. This is done based on the redirection settings for this module.

1 call to _cas_force_login()
cas_login_check in ./cas.module
Checks to see if the user needs to be logged in

File

./cas.module, line 1017

Code

function _cas_force_login() {
  list($arg0) = explode('/', $_GET['q']);

  // Don't even do the test if we're hitting the cas page
  if ($arg0 == "cas") {
    return TRUE;
  }

  // cron
  if (stristr($_SERVER['SCRIPT_FILENAME'], 'xmlrpc.php')) {
    return FALSE;
  }

  // XMLRPC
  if (stristr($_SERVER['SCRIPT_FILENAME'], 'cron.php')) {
    return FALSE;
  }

  // Drush
  if (stristr($_SERVER['SCRIPT_FILENAME'], 'drush')) {
    return FALSE;
  }

  // Drush
  if (stristr($_SERVER['argv'][0], 'drush')) {
    return FALSE;
  }

  // set the default behavior
  if (variable_get('cas_access', 0) == 1) {
    $force_login = TRUE;
  }
  else {
    $force_login = FALSE;
  }

  // Test against exclude pages.
  $pages = variable_get('cas_exclude', CAS_EXCLUDE);
  if ($pages) {
    $path = drupal_get_path_alias($_GET['q']);
    $regexp = '/^(' . preg_replace(array(
      '/(\\r\\n?|\\n)/',
      '/\\\\\\*/',
      '/(^|\\|)\\\\<front\\\\>($|\\|)/',
    ), array(
      '|',
      '.*',
      '\\1' . variable_get('site_frontpage', 'node') . '\\2',
    ), preg_quote($pages, '/')) . ')$/';
    $path_match = preg_match($regexp, $path);

    // Alter the default
    if ($path_match) {
      return FALSE;
    }
  }
  $pages = variable_get('cas_pages', '');

  // This common page matching logic used throughout drupal.
  if ($pages) {
    $path = drupal_get_path_alias($_GET['q']);
    $regexp = '/^(' . preg_replace(array(
      '/(\\r\\n?|\\n)/',
      '/\\\\\\*/',
      '/(^|\\|)\\\\<front\\\\>($|\\|)/',
    ), array(
      '|',
      '.*',
      '\\1' . variable_get('site_frontpage', 'node') . '\\2',
    ), preg_quote($pages, '/')) . ')$/';
    $path_match = preg_match($regexp, $path);

    // Alter the default
    if ($path_match) {
      if ($force_login) {
        $force_login = FALSE;
      }
      else {
        $force_login = TRUE;
      }
    }
  }
  return $force_login;
}