You are here

function _cas_force_login in CAS 5.4

Same name and namespace in other branches
  1. 5 cas.module \_cas_force_login()
  2. 5.3 cas.module \_cas_force_login()
  3. 6.3 cas.module \_cas_force_login()
  4. 6 cas.module \_cas_force_login()
  5. 6.2 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 914

Code

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

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

  // Don't even do the test if cron.php or xmlrpc.php is invoked.  Don't require login.
  if (base_path() . 'cron.php' == $_SERVER['PHP_SELF'] || base_path() . 'xmlrpc.php' == $_SERVER['PHP_SELF']) {
    return FALSE;
  }

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

  // Test against exclude pages.
  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;
}