Example #1
0
 /**
  * Check if we should implement the CAS gateway feature.
  *
  * @param GetResponseEvent $event
  *   The response event from the kernel.
  *
  * @return bool
  *   TRUE if gateway mode was implemented, FALSE otherwise.
  */
 private function handleGateway(GetResponseEvent $event)
 {
     // Only implement gateway feature for GET requests, to prevent users from
     // being redirected to CAS server for things like form submissions.
     if (!$this->requestStack->getCurrentRequest()->isMethod('GET')) {
         return FALSE;
     }
     $config = $this->configFactory->get('cas.settings');
     $check_frequency = $config->get('gateway.check_frequency');
     if ($check_frequency === CasHelper::CHECK_NEVER) {
         return FALSE;
     }
     // User can indicate specific paths to enable (or disable) gateway mode.
     $condition = $this->conditionManager->createInstance('request_path');
     $condition->setConfiguration($config->get('gateway.paths'));
     if (!$this->conditionManager->execute($condition)) {
         return FALSE;
     }
     // If set to only implement gateway once per session, we use a session
     // variable to store the fact that we've already done the gateway check
     // so we don't keep doing it.
     if ($check_frequency === CasHelper::CHECK_ONCE) {
         // If the session var is already set, we know to back out.
         if (isset($_SESSION['cas_gateway_checked'])) {
             $this->casHelper->log("Gateway already checked, will not check again.");
             return FALSE;
         }
         $_SESSION['cas_gateway_checked'] = TRUE;
     }
     $cas_login_url = $this->casHelper->getServerLoginUrl(array('returnto' => $this->requestStack->getCurrentRequest()->getUri(), 'cas_temp_disable' => TRUE), TRUE);
     $this->casHelper->log("Gateway activated, redirecting to {$cas_login_url}");
     $event->setResponse(TrustedRedirectResponse::create($cas_login_url));
     return TRUE;
 }