You are here

function cas_phpcas_init in CAS 7

Same name and namespace in other branches
  1. 6.3 cas.module \cas_phpcas_init()

Initialize phpCAS.

Will load phpCAS if necessary.

3 calls to cas_phpcas_init()
cas_login_check in ./cas.module
Checks to see if the user needs to be logged in.
cas_logout in ./cas.module
Logs a user out of Drupal and then out of CAS.
cas_phpcas_attributes in ./cas.module
Get the CAS attributes of the current CAS user.

File

./cas.module, line 254
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_phpcas_init() {
  if (!defined('PHPCAS_VERSION') || !class_exists('phpCAS')) {
    cas_phpcas_load();
  }
  $initialized =& drupal_static(__FUNCTION__, FALSE);
  if ($initialized) {

    // phpCAS cannot be initialized twice. If you need to force this function
    // to run again, call drupal_static_reset('cas_phpcas_init') first.
    return;
  }
  $initialized = TRUE;

  // Variable set
  $server_version = (string) variable_get('cas_version', '3.0');
  $server_cas_server = (string) variable_get('cas_server', '');
  $server_port = (int) variable_get('cas_port', '443');
  $server_uri = (string) variable_get('cas_uri', '');
  $cas_cert = (string) variable_get('cas_cert', '');
  $debug_file = (string) variable_get('cas_debugfile', '');

  // Back out if there's no configured CAS server hostname. This is the
  // minimum required configuration to initialize phpCAS.
  if (empty($server_cas_server)) {
    watchdog('cas', 'Unable to initialize phpCAS because no CAS server hostname has been configured.', array(), WATCHDOG_ERROR);
    return FALSE;
  }
  if ($debug_file != '') {
    phpCAS::setDebug($debug_file);
  }
  $start_session = (bool) FALSE;
  if (variable_get('cas_proxy', 0)) {
    phpCAS::proxy($server_version, $server_cas_server, $server_port, $server_uri, $start_session);
    $cas_pgt_storage_path = variable_get('cas_pgtpath', '');
    if ($cas_pgt_storage_path != '') {
      if (version_compare(PHPCAS_VERSION, '1.3', '>=')) {
        phpCAS::setPGTStorageFile($cas_pgt_storage_path);
      }
      else {
        $cas_pgt_format = variable_get('cas_pgtformat', 'plain');
        phpCAS::setPGTStorageFile($cas_pgt_format, $cas_pgt_storage_path);
      }
    }
  }
  else {
    phpCAS::client($server_version, $server_cas_server, $server_port, $server_uri, $start_session);
  }

  //Add CAS proxy lists allowed
  $proxy_list = variable_get('cas_proxy_list', '');
  if ($proxy_list) {
    $proxy_list = explode("\n", $proxy_list);
    phpCAS::allowProxyChain(new CAS_ProxyChain($proxy_list));
  }

  // force CAS authentication
  if ($cas_cert = variable_get('cas_cert', '')) {
    phpCAS::setCasServerCACert($cas_cert);
  }
  else {
    phpCAS::setNoCasServerValidation();
  }
  phpCAS::setFixedServiceURL(url(current_path(), array(
    'query' => drupal_get_query_parameters(),
    'absolute' => TRUE,
  )));
  phpCAS::setCacheTimesForAuthRecheck((int) variable_get('cas_check_frequency', CAS_CHECK_NEVER));

  // Allow other modules to call phpCAS routines. We do not call
  // drupal_alter() since there are no parameters to pass.
  module_invoke_all('cas_phpcas_alter');
}