You are here

public function CasLogout::handleSlo in CAS 8

Same name and namespace in other branches
  1. 2.x src/Service/CasLogout.php \Drupal\cas\Service\CasLogout::handleSlo()

Handles a single-log-out request from a CAS server.

Parameters

string $data: The raw data posted to us from the CAS server.

Throws

\Drupal\cas\Exception\CasSloException If the logout data could not be parsed.

File

src/Service/CasLogout.php, line 61

Class

CasLogout
Class CasLogout.

Namespace

Drupal\cas\Service

Code

public function handleSlo($data) {
  $this->casHelper
    ->log(LogLevel::DEBUG, "Attempting to handle single-log-out request.");

  // Only look up tickets if they were stored to begin with.
  if (!$this->settings
    ->get('logout.enable_single_logout')) {
    $this->casHelper
      ->log(LogLevel::DEBUG, "Aborting single-log-out handling; it's not enabled in the CAS settings.");
    return;
  }
  $service_ticket = $this
    ->getServiceTicketFromData($data);
  $this->casHelper
    ->log(LogLevel::DEBUG, 'Service ticket %ticket extracted from single-log-out request.', [
    '%ticket' => $service_ticket,
  ]);

  // Look up the session ID by the service ticket, then load up that
  // session and destroy it.
  $sid = $this
    ->lookupSessionIdByServiceTicket($service_ticket);
  if (!$sid) {
    $this->casHelper
      ->log(LogLevel::DEBUG, 'No matching session found for %ticket', [
      '%ticket' => $service_ticket,
    ]);
    return;
  }
  $this
    ->destroySession($sid);
  $this
    ->removeSessionMapping($sid);
  $this->casHelper
    ->log(LogLevel::DEBUG, "Single-log-out request completed successfully.");
}