You are here

function _cas_single_sign_out_check in CAS 6.3

Same name and namespace in other branches
  1. 5.4 cas.module \_cas_single_sign_out_check()
  2. 5.3 cas.module \_cas_single_sign_out_check()
  3. 6.2 cas.module \_cas_single_sign_out_check()
  4. 7 cas.module \_cas_single_sign_out_check()
1 call to _cas_single_sign_out_check()
cas_init in ./cas.module
Implementation of hook_init().

File

./cas.module, line 1032
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_single_sign_out_check() {
  if (isset($_POST["logoutRequest"])) {
    $cas_logout_request_xml_string = utf8_encode(urldecode($_POST["logoutRequest"]));
    $cas_logout_request_xml = new SimpleXMLElement($cas_logout_request_xml_string);
    if (is_object($cas_logout_request_xml)) {
      $namespaces = $cas_logout_request_xml
        ->getNameSpaces();
      $xsearch = 'SessionIndex';
      if (isset($namespaces['samlp'])) {
        $cas_logout_request_xml
          ->registerXPathNamespace('samlp', $namespaces['samlp']);
        $xsearch = 'samlp:SessionIndex';
      }
      $cas_session_indexes = $cas_logout_request_xml
        ->xpath($xsearch);
      if ($cas_session_indexes) {
        $cas_session_index = (string) $cas_session_indexes[0];

        // Log them out now.
        // first lets find out who we want to log off
        $record = db_fetch_object(db_query_range("SELECT cld.uid, u.name FROM {users} u JOIN {cas_login_data} cld ON u.uid = cld.uid WHERE cld.cas_session_id = '%s'", $cas_session_index, 0, 1));
        if ($record) {
          watchdog('user', 'Session closed for %name by CAS logout request.', array(
            '%name' => $record->name,
          ));

          // remove all entry for user id in cas_login_data
          db_query("DELETE FROM {cas_login_data} WHERE uid = %d", $record->uid);

          // remove their session
          db_query("DELETE FROM {sessions} WHERE uid = %d", $record->uid);
        }
      }
    }

    // This request is done, so just exit.
    exit;
  }
}