You are here

public function SimplesamlSubscriber::checkAuthStatus in simpleSAMLphp Authentication 8.3

Logs out user if not SAML authenticated and local logins are disabled.

Parameters

\Symfony\Component\HttpKernel\Event\GetResponseEvent $event: The subscribed event.

File

src/EventSubscriber/SimplesamlSubscriber.php, line 84

Class

SimplesamlSubscriber
Event subscriber subscribing to KernelEvents::REQUEST.

Namespace

Drupal\simplesamlphp_auth\EventSubscriber

Code

public function checkAuthStatus(GetResponseEvent $event) {
  if ($this->account
    ->isAnonymous()) {
    return;
  }
  if (!$this->simplesaml
    ->isActivated()) {
    return;
  }
  if ($this->simplesaml
    ->isAuthenticated()) {
    return;
  }
  if ($this->config
    ->get('allow.default_login')) {
    $allowed_uids = explode(',', $this->config
      ->get('allow.default_login_users'));
    if (in_array($this->account
      ->id(), $allowed_uids)) {
      return;
    }
    $allowed_roles = $this->config
      ->get('allow.default_login_roles');
    if (array_intersect($this->account
      ->getRoles(), $allowed_roles)) {
      return;
    }
  }
  if ($this->config
    ->get('debug')) {
    $this->logger
      ->debug('User %name not authorized to log in using local account.', [
      '%name' => $this->account
        ->getAccountName(),
    ]);
  }
  user_logout();
  $response = new RedirectResponse('/', RedirectResponse::HTTP_FOUND);
  $event
    ->setResponse($response);
  $event
    ->stopPropagation();
}