You are here

function ldap_sso_boot in LDAP Single Sign On 7.2

Same name and namespace in other branches
  1. 7 ldap_sso.module \ldap_sso_boot()

Implements hook_boot().

Perform setup tasks. This entry point is used because hook_user_load no longer runs on anonymous users, and hook_boot is guaranteed to run, regardless of cache.

File

./ldap_sso.module, line 47
This module injects itself into Drupal's Authentication stack.

Code

function ldap_sso_boot() {
  if (!drupal_is_cli() && $GLOBALS['user']->uid == 0) {
    if (ldap_sso_path_excluded_from_sso()) {
      return;
    }
    module_load_include('module', 'ldap_servers');
    if (!isset($_COOKIE['seamless_login']) || $_COOKIE['seamless_login'] == 'auto login') {
      if (arg(0) == 'user' && !is_numeric(arg(1)) || arg(0) == 'logout') {
        return;
      }
      else {
        if (isset($_COOKIE['seamless_login_attempted'])) {
          $login_attempted = $_COOKIE['seamless_login_attempted'];
        }
        else {
          $login_attempted = FALSE;
        }
        require_once DRUPAL_ROOT . '/includes/common.inc';
        require_once DRUPAL_ROOT . '/' . variable_get('path_inc', 'includes/path.inc');
        $ldap_authentication_conf = variable_get('ldap_authentication_conf', array());
        if (isset($ldap_authentication_conf['seamlessLogin']) && $ldap_authentication_conf['seamlessLogin'] == 1 && $login_attempted != 'true') {
          if ($ldap_authentication_conf['cookieExpire'] == 0) {
            setcookie("seamless_login_attempted", 'true', 0, base_path(), "");
          }
          else {
            setcookie('seamless_login_attempted', 'true', time() + (int) $ldap_authentication_conf['cookieExpire'], base_path(), "");
          }
          ldap_servers_set_globals('_SESSION', 'seamless_login_attempted', $login_attempted);
          drupal_bootstrap(DRUPAL_BOOTSTRAP_LANGUAGE);

          // Seems redundant, but need to check this again after additional
          // bootstrap.
          if (ldap_sso_path_excluded_from_sso()) {
            return;
          }

          // Add the query key to the drupal_goto() options array only if there
          // is a destination set. This prevents infinite redirect loops.
          $options = array();
          $destination = drupal_get_destination();
          if (!empty($destination['destination'])) {
            $options['query'] = $destination;
          }
          drupal_goto('user/login/sso', $options);
        }
        else {
          return;
        }
      }
    }
  }
}