You are here

public function CasSubscriber::on403 in CAS 8

Handle 403 errors.

Other request subscribers with a higher priority may intercept the request and return a 403 before our request subscriber can handle it. In those instances we handle the forced login redirect if applicable here instead, using an exception subscriber.

Parameters

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

File

src/Subscriber/CasSubscriber.php, line 371

Class

CasSubscriber
Provides a CasSubscriber.

Namespace

Drupal\cas\Subscriber

Code

public function on403(GetResponseForExceptionEvent $event) {
  if ($this->currentUser
    ->isAnonymous()) {
    $return_to = $this->requestStack
      ->getCurrentRequest()
      ->getUri();
    $redirect_data = new CasRedirectData([
      'returnto' => $return_to,
    ]);
    if ($this
      ->handleForcedPath()) {
      $this->casHelper
        ->log(LogLevel::DEBUG, 'Initializing forced login auth from CasSubscriber.');
      $redirect_data
        ->forceRedirection();
      $redirect_data
        ->setIsCacheable(TRUE);
    }
    else {
      $redirect_data
        ->preventRedirection();
    }

    // If we're still going to redirect, lets do it.
    $response = $this->casRedirector
      ->buildRedirectResponse($redirect_data);
    if ($response) {
      $event
        ->setResponse($response);
    }
  }
}