You are here

public function SecuresiteSubscriber::onKernelRequest in Secure Site 8

Check every page request for authentication

Parameters

\Symfony\Component\HttpKernel\Event\GetResponseEvent $event: The event to process.

File

src/EventSubscriber/SecuresiteSubscriber.php, line 46
Contains Drupal\securesite\EventSubscriber\SecuresiteSubscriber.

Class

SecuresiteSubscriber
Subscribes to the kernel request event to check whether authentication is required

Namespace

Drupal\securesite\EventSubscriber

Code

public function onKernelRequest(GetResponseEvent $event) {
  $account = \Drupal::currentUser();
  $request = $event
    ->getRequest();

  //creating an array of headers to be added to the response. This array will be populated later on
  $request->securesiteHeaders = array();
  $this->manager
    ->setRequest($request);

  // Did the user send credentials that we accept?
  $type = $this->manager
    ->getMechanism();
  if ($type !== FALSE && (isset($_SESSION['securesite_repeat']) ? !$_SESSION['securesite_repeat'] : TRUE)) {
    $this->manager
      ->boot($type);
  }
  elseif ($account
    ->id() == 0 && !isset($_SESSION['securesite_guest'])) {
    if (isset($_SESSION['securesite_repeat'])) {
      unset($_SESSION['securesite_repeat']);
    }
    if ($this->manager
      ->forcedAuth()) {
      $types = \Drupal::config('securesite.settings')
        ->get('securesite_type');
      sort($types, SORT_NUMERIC);
      $this->manager
        ->showDialog(array_pop($types));
    }
  }
}