class DrupalAuthForSSPSubscriber in DrupalAuth for SimpleSAMLphp 8
DrupalAuth for SimpleSAMLphp event subscriber.
Hierarchy
- class \Drupal\drupalauth4ssp\EventSubscriber\DrupalAuthForSSPSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of DrupalAuthForSSPSubscriber
1 string reference to 'DrupalAuthForSSPSubscriber'
1 service uses DrupalAuthForSSPSubscriber
File
- src/
EventSubscriber/ DrupalAuthForSSPSubscriber.php, line 16
Namespace
Drupal\drupalauth4ssp\EventSubscriberView source
class DrupalAuthForSSPSubscriber implements EventSubscriberInterface {
/**
* Account proxy.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $accountProxy;
/**
* Constructs event subscriber.
*
* @param \Drupal\Core\Session\AccountProxyInterface $account_proxy
* Account proxy.
*/
public function __construct(AccountProxyInterface $account_proxy) {
$this->accountProxy = $account_proxy;
}
/**
* Kernel response event handler.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
* Response event.
*/
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();
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
KernelEvents::RESPONSE => [
'checkRedirection',
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DrupalAuthForSSPSubscriber:: |
protected | property | Account proxy. | |
DrupalAuthForSSPSubscriber:: |
public | function | Kernel response event handler. | |
DrupalAuthForSSPSubscriber:: |
public static | function | ||
DrupalAuthForSSPSubscriber:: |
public | function | Constructs event subscriber. |