Esempio n. 1
0
 /**
  * Handles a HTTP request
  *
  * @return void
  */
 public function handleRequest()
 {
     // Create the request very early so the Resource Management has a chance to grab it:
     $this->request = \TYPO3\Flow\Http\Request::createFromEnvironment();
     $this->response = new \TYPO3\Flow\Http\Response();
     $this->boot();
     $this->resolveDependencies();
     $this->request->injectSettings($this->settings);
     $this->addDebugToolbarRoutes();
     $this->router->setRoutesConfiguration($this->routesConfiguration);
     $actionRequest = $this->router->route($this->request);
     $this->securityContext->setRequest($actionRequest);
     $this->dispatcher->dispatch($actionRequest, $this->response);
     $this->response->makeStandardsCompliant($this->request);
     \Debug\Toolbar\Service\DataStorage::add('Request:Requests', $actionRequest);
     \Debug\Toolbar\Service\DataStorage::add('Request:Responses', $this->response);
     \Debug\Toolbar\Toolbar\View::handleRedirects($this->request, $this->response);
     $this->emitAboutToRenderDebugToolbar();
     \Debug\Toolbar\Service\DataStorage::set('Modules', \Debug\Toolbar\Service\Collector::getModules());
     if ($actionRequest->getFormat() === 'html') {
         echo \Debug\Toolbar\Toolbar\View::attachToolbar($this->response->getContent());
     } else {
         echo $this->response->getContent();
     }
     $this->bootstrap->shutdown('Runtime');
     $this->exit->__invoke();
     \Debug\Toolbar\Service\DataStorage::save();
 }
Esempio n. 2
0
 /**
  * Handles a raw ExtDirect request and sends the response.
  *
  * @return void
  */
 public function handleRequest()
 {
     // Create the request very early so the Resource Management has a chance to grab it:
     $this->request = \TYPO3\Flow\Http\Request::createFromEnvironment();
     $this->response = new \TYPO3\Flow\Http\Response();
     $this->boot();
     $this->resolveDependencies();
     $this->request->injectSettings($this->flowSettings);
     $this->router->setRoutesConfiguration($this->routesConfiguration);
     try {
         $extDirectRequest = $this->buildJsonRequest($this->request);
         $results = array();
         foreach ($extDirectRequest->getTransactions() as $transaction) {
             $requestOfCurrentTransaction = $transaction->buildRequest($extDirectRequest);
             $responseOfCurrentTransaction = $transaction->buildResponse();
             try {
                 $this->securityContext->setRequest($requestOfCurrentTransaction);
                 $this->securityContext->initialize();
                 $this->dispatcher->dispatch($requestOfCurrentTransaction, $responseOfCurrentTransaction);
                 $results[] = array('type' => 'rpc', 'tid' => $transaction->getTid(), 'action' => $transaction->getAction(), 'method' => $transaction->getMethod(), 'result' => $responseOfCurrentTransaction->getResult());
             } catch (\Exception $exception) {
                 $results[] = $this->handleException($exception, $transaction->getTid());
             }
         }
         $this->prepareResponse($results, $extDirectRequest);
     } catch (InvalidExtDirectRequestException $exception) {
         $results[] = $this->handleException($exception);
         $this->prepareResponse($results);
     }
     $this->response->makeStandardsCompliant($this->request);
     $this->response->send();
     $this->bootstrap->shutdown('Runtime');
     $this->exit->__invoke();
 }
 /**
  * Construct
  */
 public function __construct()
 {
     $httpRequest = \TYPO3\Flow\Http\Request::createFromEnvironment();
     $actionRequest = new \TYPO3\Flow\Mvc\ActionRequest($httpRequest);
     $this->uriBuilder = new \TYPO3\Flow\Mvc\Routing\UriBuilder();
     $this->uriBuilder->setRequest($actionRequest);
 }
 /**
  * @return ControllerContext
  */
 protected function createControllerContextFromEnvironment()
 {
     $httpRequest = Request::createFromEnvironment();
     /** @var ActionRequest $request */
     $request = $httpRequest->createActionRequest();
     $uriBuilder = new UriBuilder();
     $uriBuilder->setRequest($request);
     return new ControllerContext($request, new Response(), new Arguments(array()), $uriBuilder);
 }
 /**
  * @return null|string
  */
 protected function getRequestMediaType()
 {
     if (PHP_SAPI !== 'cli' && ($httpRequest = \TYPO3\Flow\Http\Request::createFromEnvironment())) {
         if ($httpRequest !== NULL) {
             return $httpRequest->getNegotiatedMediaType($this->supportedMediaTypes);
         }
     }
     return NULL;
 }
 /**
  * @test
  */
 public function createFromEnvironmentWithEmptyServerVariableWorks()
 {
     $_GET = array();
     $_POST = array();
     $_COOKIE = array();
     $_FILES = array();
     $_SERVER = array();
     $request = Request::createFromEnvironment();
     $this->assertEquals('http://localhost/', (string) $request->getUri());
 }
 /**
  * Initiates the StandaloneView by creating the required ControllerContext
  *
  * @return void
  */
 public function initializeObject()
 {
     if ($this->request === null) {
         $httpRequest = Request::createFromEnvironment();
         $this->request = $this->objectManager->get(\TYPO3\Flow\Mvc\ActionRequest::class, $httpRequest);
     }
     $uriBuilder = new UriBuilder();
     $uriBuilder->setRequest($this->request);
     $this->setControllerContext(new ControllerContext($this->request, new Response(), new Arguments(array()), $uriBuilder));
 }
 /**
  * Helper to build a TypoScript view object
  *
  * @return TypoScriptView
  */
 protected function buildView()
 {
     $view = new TypoScriptView();
     $httpRequest = Request::createFromEnvironment();
     $request = $httpRequest->createActionRequest();
     $uriBuilder = new UriBuilder();
     $uriBuilder->setRequest($request);
     $this->controllerContext = new ControllerContext($request, new Response(), new Arguments(array()), $uriBuilder);
     $view->setControllerContext($this->controllerContext);
     $view->disableFallbackView();
     $view->setPackageKey('TYPO3.TypoScript');
     $view->setTypoScriptPathPattern(__DIR__ . '/Fixtures/TypoScript');
     $view->assign('fixtureDirectory', __DIR__ . '/Fixtures/');
     return $view;
 }
Esempio n. 9
0
 /**
  * @param Account $account
  * @return void
  */
 protected function sendNotificationMail(Account $account)
 {
     $notificationMailSettings = $this->settings['notificationMail'];
     if (!$notificationMailSettings['to']) {
         return;
     }
     $httpRequest = Request::createFromEnvironment();
     $failedAttemptsThreshold = $this->settings['failedAttemptsThreshold'];
     $time = (new \DateTime())->format('Y-m-d H:i');
     $replacePlaceholders = function ($string) use($account, $httpRequest, $failedAttemptsThreshold, $time) {
         return str_replace(['{domain}', '{ip}', '{userAgent}', '{accountIdentifier}', '{failedAttemptsThreshold}', '{time}'], [$httpRequest->getUri()->getHost(), $httpRequest->getClientIpAddress(), $_SERVER['HTTP_USER_AGENT'], $account->getAccountIdentifier(), $failedAttemptsThreshold, $time], $string);
     };
     $mail = new Message();
     $mail->setFrom($replacePlaceholders($notificationMailSettings['from']['email']), $replacePlaceholders($notificationMailSettings['from']['name']))->setTo($notificationMailSettings['to'])->setSubject($replacePlaceholders($notificationMailSettings['subject']))->setBody($replacePlaceholders($notificationMailSettings['message']))->send();
 }
Esempio n. 10
0
 /**
  * Handles a HTTP request
  *
  * @return void
  */
 public function handleRequest()
 {
     // Create the request very early so the Resource Management has a chance to grab it:
     $this->request = Request::createFromEnvironment();
     $this->response = new Response();
     $this->checkBasicRequirementsAndDisplayLoadingScreen();
     $this->boot();
     $this->resolveDependencies();
     if (isset($this->settings['http']['baseUri'])) {
         $this->request->setBaseUri(new Uri($this->settings['http']['baseUri']));
     }
     $componentContext = new ComponentContext($this->request, $this->response);
     $this->baseComponentChain->handle($componentContext);
     $this->response->send();
     $this->bootstrap->shutdown('Runtime');
     $this->exit->__invoke();
 }
Esempio n. 11
0
 /**
  * @param string $sitePackage
  * @param string $siteName
  * @param string $baseDomain
  * @return Site
  */
 public function importSiteFromTemplate($sitePackage, $siteName, $baseDomain = '')
 {
     if (empty($baseDomain)) {
         $request = Request::createFromEnvironment();
         $baseDomain = $request->getBaseUri()->getHost();
     }
     $siteTemplate = new StandaloneView();
     $siteTemplate->setTemplatePathAndFilename(FLOW_PATH_PACKAGES . 'Sites/' . $sitePackage . '/Resources/Private/Templates/Content/Sites.xml');
     $siteTemplate->assignMultiple(['siteName' => $siteName, 'siteNodeName' => \TYPO3\TYPO3CR\Utility::renderValidNodeName($siteName), 'packageKey' => $sitePackage]);
     $generatedSiteImportXmlContent = $siteTemplate->render();
     $dataTemporaryPath = $this->environment->getPathToTemporaryDirectory();
     $temporarySiteXml = $dataTemporaryPath . uniqid($siteName) . '.xml';
     file_put_contents($temporarySiteXml, $generatedSiteImportXmlContent);
     $site = $this->siteImportService->importFromFile($temporarySiteXml);
     $domain = new Domain();
     $domain->setActive(true);
     $domain->setSite($site);
     $domain->setHostPattern(\TYPO3\TYPO3CR\Utility::renderValidNodeName($siteName) . '.' . $baseDomain);
     $this->domainRepository->add($domain);
     return $site;
 }
 /**
  * Sets up security test requirements
  *
  * Security is based on action requests so we need a working route for the TestingProvider.
  *
  * @return void
  */
 protected function setupSecurity()
 {
     if ($this->securityInitialized === true) {
         return;
     }
     $this->privilegeManager = $this->objectManager->get(\TYPO3\Flow\Security\Authorization\PrivilegeManagerInterface::class);
     $this->privilegeManager->setOverrideDecision(null);
     $this->policyService = $this->objectManager->get(\TYPO3\Flow\Security\Policy\PolicyService::class);
     $this->authenticationManager = $this->objectManager->get(\TYPO3\Flow\Security\Authentication\AuthenticationProviderManager::class);
     $this->testingProvider = $this->objectManager->get(\TYPO3\Flow\Security\Authentication\Provider\TestingProvider::class);
     $this->testingProvider->setName('TestingProvider');
     $this->securityContext = $this->objectManager->get(\TYPO3\Flow\Security\Context::class);
     $this->securityContext->clearContext();
     $httpRequest = Request::createFromEnvironment();
     $this->mockActionRequest = new ActionRequest($httpRequest);
     $this->mockActionRequest->setControllerObjectName(\TYPO3\Flow\Tests\Functional\Security\Fixtures\Controller\AuthenticationController::class);
     $this->securityContext->setRequest($this->mockActionRequest);
     $this->securityInitialized = true;
 }
Esempio n. 13
0
 /**
  * The Resource Information most likely needs an UriBuilder, so having a
  * ControllerContext in place might come in handy.
  *
  * @return void
  */
 protected function initializeControllerContext()
 {
     $request = new ActionRequest(Request::createFromEnvironment());
     $request->setDispatched(true);
     $response = new Response();
     $uriBuilder = new UriBuilder();
     $uriBuilder->setRequest($request);
     $arguments = new Arguments(array());
     $this->controllerContext = new ControllerContext($request, $response, $arguments, $uriBuilder);
 }
 /**
  * Handles a HTTP request
  *
  * @return void
  */
 public function handleRequest()
 {
     // Create the request very early so the Resource Management has a chance to grab it:
     $this->request = Request::createFromEnvironment();
     $this->response = new Response();
     $this->boot();
     $this->resolveDependencies();
     $this->addPoweredByHeader($this->response);
     if (isset($this->settings['http']['baseUri'])) {
         $this->request->setBaseUri(new Uri($this->settings['http']['baseUri']));
     }
     $componentContext = new ComponentContext($this->request, $this->response);
     $this->baseComponentChain->handle($componentContext);
     $this->response->send();
     $this->bootstrap->shutdown(Bootstrap::RUNLEVEL_RUNTIME);
     $this->exit->__invoke();
 }
Esempio n. 15
0
 /**
  * Initiates the StandaloneView by creating the required ControllerContext
  *
  * @return void
  */
 public function initializeObject()
 {
     if ($this->request === NULL) {
         $httpRequest = Request::createFromEnvironment();
         $this->request = $httpRequest->createActionRequest();
     }
     $uriBuilder = new UriBuilder();
     $uriBuilder->setRequest($this->request);
     $this->setControllerContext(new ControllerContext($this->request, new Response(), new Arguments(array()), $uriBuilder, $this->flashMessageContainer));
 }
Esempio n. 16
0
 /**
  * Handles a HTTP request
  *
  * @return void
  */
 public function handleRequest()
 {
     // Create the request very early so the Resource Management has a chance to grab it:
     $this->request = Request::createFromEnvironment();
     $this->response = new Response();
     $this->boot();
     $this->resolveDependencies();
     $this->request->injectSettings($this->settings);
     $this->router->setRoutesConfiguration($this->routesConfiguration);
     $actionRequest = $this->router->route($this->request);
     $this->securityContext->setRequest($actionRequest);
     $this->dispatcher->dispatch($actionRequest, $this->response);
     $this->response->makeStandardsCompliant($this->request);
     $this->response->send();
     $this->bootstrap->shutdown('Runtime');
     $this->exit->__invoke();
 }
 /**
  * Sets up security test requirements
  *
  * Security is based on action requests so we need a working route for the TestingProvider.
  *
  * @return void
  */
 protected function setupSecurity()
 {
     $this->accessDecisionManager = $this->objectManager->get('TYPO3\\Flow\\Security\\Authorization\\AccessDecisionManagerInterface');
     $this->accessDecisionManager->setOverrideDecision(NULL);
     $this->policyService = $this->objectManager->get('TYPO3\\Flow\\Security\\Policy\\PolicyService');
     $this->authenticationManager = $this->objectManager->get('TYPO3\\Flow\\Security\\Authentication\\AuthenticationProviderManager');
     $this->testingProvider = $this->objectManager->get('TYPO3\\Flow\\Security\\Authentication\\Provider\\TestingProvider');
     $this->testingProvider->setName('TestingProvider');
     $this->securityContext = $this->objectManager->get('TYPO3\\Flow\\Security\\Context');
     $this->securityContext->clearContext();
     $httpRequest = Request::createFromEnvironment();
     $this->mockActionRequest = new ActionRequest($httpRequest);
     $this->mockActionRequest->setControllerObjectName('TYPO3\\Flow\\Tests\\Functional\\Security\\Fixtures\\Controller\\AuthenticationController');
     $this->securityContext->setRequest($this->mockActionRequest);
 }
 /**
  * Internal getter to ensure an existing ComponentContext.
  *
  * @return ComponentContext
  */
 protected function getComponentContext()
 {
     if ($this->componentContext === null) {
         $this->componentContext = new ComponentContext(Http\Request::createFromEnvironment(), new Http\Response());
     }
     return $this->componentContext;
 }