You are here

function cas_server_logout_clients in CAS 7

Same name and namespace in other branches
  1. 6.3 cas_server.module \cas_server_logout_clients()

Send CAS a logout requests for each of the user's CAS tickets.

Parameters

$account: The user for whom to send CAS logout requests.

1 call to cas_server_logout_clients()
cas_server_user_logout in ./cas_server.module
Implements hook_user_logout().

File

./cas_server.module, line 349
Provides a protocol compliant version of CAS server 2.x

Code

function cas_server_logout_clients($account) {
  $result = db_query("SELECT service, ticket, valid FROM {cas_server_tickets} WHERE uid= :uid", array(
    ':uid' => $account->uid,
  ));
  if ($result !== FALSE) {
    $expired_tickets = array();

    // Set a time limit for all logout requests. This is useful if a user has
    // accumulated a lot of login sessions for services that may be
    // unresponsive.
    $timelimit = time() + (int) variable_get('cas_server_slo_group_timeout', 15);
    foreach ($result as $client) {
      if (time() > $timelimit) {
        break;
      }
      $expired_tickets[] = $client->ticket;
      if (!$client->valid) {
        $id = 'LR-' . user_password();
        $date = date('c');
        $logout_request = theme('cas_service_logout_request', array(
          'id' => $id,
          'date' => $date,
          'ticket' => $client->ticket,
        ));

        // Send POST request
        $response = drupal_http_request($client->service, array(
          'headers' => array(
            'Content-Type' => 'application/x-www-form-urlencoded',
          ),
          'method' => 'POST',
          'data' => 'logoutRequest=' . urlencode($logout_request),
          'timeout' => (int) variable_get('cas_server_slo_individual_timeout', 5),
        ));
        if (@$response->error) {
          watchdog('error', 'Error in CAS logout Request - %code : %message', array(
            '%code' => $response->code,
            '%error' => $response->error,
          ));
        }
      }

      // Remove ticket
    }
    if ($expired_tickets) {
      db_delete('cas_server_tickets')
        ->condition('ticket', $expired_tickets, 'IN')
        ->execute();
    }
  }
}