public function DrupalAuthForSSPSubscriber::checkRedirection in DrupalAuth for SimpleSAMLphp 8
Kernel response event handler.
Parameters
\Symfony\Component\HttpKernel\Event\FilterResponseEvent $event: Response event.
File
- src/
EventSubscriber/ DrupalAuthForSSPSubscriber.php, line 41
Class
- DrupalAuthForSSPSubscriber
- DrupalAuth for SimpleSAMLphp event subscriber.
Namespace
Drupal\drupalauth4ssp\EventSubscriberCode
public function checkRedirection(FilterResponseEvent $event) {
if ($event
->getResponse() instanceof RedirectResponse) {
$response = $event
->getResponse();
$path = $response
->getTargetUrl();
$frontPage = Url::fromRoute('<front>')
->setAbsolute()
->toString();
// Redirect after log out.
$responseIsHttpFound = $response
->getStatusCode() === Response::HTTP_FOUND;
$isRedirectToFrontPage = $path === $frontPage && $responseIsHttpFound;
$destination =& drupal_static('drupalauth4ssp_user_logout');
if ($isRedirectToFrontPage && !empty($destination)) {
$response
->setTargetUrl($destination);
$event
->stopPropagation();
return;
}
// If this was request to login and user was authenticated by cookie.
$returnTo = $event
->getRequest()->query
->get('ReturnTo');
$isLoginRequest = $event
->getRequest()->attributes
->get('_route') === 'user.login';
if ($isLoginRequest && $responseIsHttpFound && $returnTo) {
drupalauth4ssp_set_user_cookie($this->accountProxy);
$response
->setTargetUrl($returnTo);
$event
->stopPropagation();
}
}
}