コード例 #1
0
 /**
  * @test
  */
 public function replaceHttpRequestReplacesTheCurrentRequest()
 {
     /** @var Request $mockNewHttpRequest */
     $mockNewHttpRequest = $this->getMockBuilder('TYPO3\\Flow\\Http\\Request')->disableOriginalConstructor()->getMock();
     $this->componentContext->replaceHttpRequest($mockNewHttpRequest);
     $this->assertSame($mockNewHttpRequest, $this->componentContext->getHttpRequest());
 }
コード例 #2
0
 /**
  * Resolve a route for the request
  *
  * Stores the resolved route values in the ComponentContext to pass them
  * to other components. They can be accessed via ComponentContext::getParameter('TYPO3\Flow\Mvc\Routing\RoutingComponent', 'matchResults');
  *
  * @param ComponentContext $componentContext
  * @return void
  */
 public function handle(ComponentContext $componentContext)
 {
     if ($componentContext->getParameter('TYPO3\\Flow\\Mvc\\Routing\\RoutingComponent', 'skipRouterInitialization') !== TRUE) {
         $routesConfiguration = $this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_ROUTES);
         $this->router->setRoutesConfiguration($routesConfiguration);
     }
     $matchResults = $this->router->route($componentContext->getHttpRequest());
     $componentContext->setParameter('TYPO3\\Flow\\Mvc\\Routing\\RoutingComponent', 'matchResults', $matchResults);
 }
コード例 #3
0
 /**
  * @param ComponentContext $componentContext
  * @return void
  */
 public function handle(ComponentContext $componentContext)
 {
     $routingMatchResults = $componentContext->getParameter(RoutingComponent::class, 'matchResults');
     if ($routingMatchResults !== NULL) {
         return;
     }
     $httpRequest = $componentContext->getHttpRequest();
     $this->redirectService->triggerRedirectIfApplicable($httpRequest);
 }
コード例 #4
0
 /**
  * Create an action request from stored route match values and dispatch to that
  *
  * @param ComponentContext $componentContext
  * @return void
  */
 public function handle(ComponentContext $componentContext)
 {
     $httpRequest = $componentContext->getHttpRequest();
     /** @var $actionRequest ActionRequest */
     $actionRequest = $this->objectManager->get(\TYPO3\Flow\Mvc\ActionRequest::class, $httpRequest);
     $this->securityContext->setRequest($actionRequest);
     $routingMatchResults = $componentContext->getParameter(\TYPO3\Flow\Mvc\Routing\RoutingComponent::class, 'matchResults');
     $actionRequest->setArguments($this->mergeArguments($httpRequest, $routingMatchResults));
     $this->setDefaultControllerAndActionNameIfNoneSpecified($actionRequest);
     $componentContext->setParameter(\TYPO3\Flow\Mvc\DispatchComponent::class, 'actionRequest', $actionRequest);
     $this->dispatcher->dispatch($actionRequest, $componentContext->getHttpResponse());
 }
コード例 #5
0
 /**
  * Check if the current request contains a widget context.
  * If so dispatch it directly, otherwise continue with the next HTTP component.
  *
  * @param ComponentContext $componentContext
  * @return void
  * @throws ComponentException
  */
 public function handle(ComponentContext $componentContext)
 {
     $httpRequest = $componentContext->getHttpRequest();
     $widgetContext = $this->extractWidgetContext($httpRequest);
     if ($widgetContext === null) {
         return;
     }
     /** @var $actionRequest ActionRequest */
     $actionRequest = $this->objectManager->get(\TYPO3\Flow\Mvc\ActionRequest::class, $httpRequest);
     $actionRequest->setArguments($this->mergeArguments($httpRequest, array()));
     $actionRequest->setArgument('__widgetContext', $widgetContext);
     $actionRequest->setControllerObjectName($widgetContext->getControllerObjectName());
     $this->setDefaultControllerAndActionNameIfNoneSpecified($actionRequest);
     $this->securityContext->setRequest($actionRequest);
     $this->dispatcher->dispatch($actionRequest, $componentContext->getHttpResponse());
     // stop processing the current component chain
     $componentContext->setParameter(\TYPO3\Flow\Http\Component\ComponentChain::class, 'cancel', true);
 }
コード例 #6
0
 /**
  * @param ComponentContext $componentContext
  * @return void
  * @api
  */
 public function handle(ComponentContext $componentContext)
 {
     $request = $componentContext->getHttpRequest();
     $trustedRequest = $request->withAttribute(Request::ATTRIBUTE_TRUSTED_PROXY, $this->isFromTrustedProxy($request));
     $trustedRequest = $trustedRequest->withAttribute(Request::ATTRIBUTE_CLIENT_IP, $this->getTrustedClientIpAddress($trustedRequest));
     $protocolHeader = $this->getFirstTrustedProxyHeaderValue(self::HEADER_PROTOCOL, $trustedRequest);
     if ($protocolHeader !== null) {
         $trustedRequest->getUri()->setScheme($protocolHeader);
     }
     $hostHeader = $this->getFirstTrustedProxyHeaderValue(self::HEADER_HOST, $trustedRequest);
     if ($hostHeader !== null) {
         $trustedRequest->getUri()->setHost($hostHeader);
     }
     $portHeader = $this->getFirstTrustedProxyHeaderValue(self::HEADER_PORT, $trustedRequest);
     if ($portHeader !== null) {
         $trustedRequest->getUri()->setPort($portHeader);
     } elseif ($protocolHeader !== null) {
         $trustedRequest->getUri()->setPort(strtolower($protocolHeader) === 'https' ? 443 : 80);
     }
     $componentContext->replaceHttpRequest($trustedRequest);
 }
コード例 #7
0
 /**
  * @param ComponentContext $componentContext
  * @return void
  * @throws FileNotFoundException|AccessDeniedException|FlowException
  */
 public function handle(ComponentContext $componentContext)
 {
     $httpRequest = $componentContext->getHttpRequest();
     if (!$httpRequest->hasArgument('__protectedResource')) {
         return;
     }
     try {
         $encodedResourceData = $this->hashService->validateAndStripHmac($httpRequest->getArgument('__protectedResource'));
     } catch (InvalidHashException $exception) {
         throw new AccessDeniedException('Invalid HMAC!', 1421241393, $exception);
     }
     $tokenData = json_decode(base64_decode($encodedResourceData), TRUE);
     $this->verifyExpiration($tokenData);
     $this->verifySecurityContextHash($tokenData, $httpRequest);
     $resource = $this->resourceManager->getResourceBySha1($tokenData['resourceIdentifier']);
     if ($resource === NULL) {
         throw new FileNotFoundException(sprintf('Unknown resource!%sCould not find resource with identifier "%s"', chr(10), $tokenData['resourceIdentifier']), 1429621743);
     }
     // TODO there should be a better way to determine the absolute path of the resource? Resource::createTemporaryLocalCopy() is too expensive
     $resourcePathAndFilename = Files::concatenatePaths(array($this->options['basePath'], $tokenData['resourceIdentifier'][0], $tokenData['resourceIdentifier'][1], $tokenData['resourceIdentifier'][2], $tokenData['resourceIdentifier'][3], $tokenData['resourceIdentifier']));
     if (!is_file($resourcePathAndFilename)) {
         throw new FileNotFoundException(sprintf('File not found!%sThe file "%s" does not exist', chr(10), $resourcePathAndFilename), 1429702284);
     }
     if (!isset($this->options['serveStrategy'])) {
         throw new FlowException('No "serveStrategy" configured!', 1429704107);
     }
     $fileServeStrategy = $this->objectManager->get($this->options['serveStrategy']);
     if (!$fileServeStrategy instanceof FileServeStrategyInterface) {
         throw new FlowException(sprintf('The class "%s" does not implement the FileServeStrategyInterface', get_class($fileServeStrategy)), 1429704284);
     }
     $httpResponse = $componentContext->getHttpResponse();
     $httpResponse->setHeader('Content-Type', $resource->getMediaType());
     $this->emitResourceServed($resource, $httpRequest);
     $fileServeStrategy->serve($resourcePathAndFilename, $httpResponse);
     $componentContext->setParameter('TYPO3\\Flow\\Http\\Component\\ComponentChain', 'cancel', TRUE);
 }
 /**
  * Just call makeStandardsCompliant on the Response for now
  *
  * @param ComponentContext $componentContext
  * @return void
  */
 public function handle(ComponentContext $componentContext)
 {
     $response = $componentContext->getHttpResponse();
     $response->makeStandardsCompliant($componentContext->getHttpRequest());
 }
コード例 #9
0
 /**
  * Resolve a route for the request
  *
  * Stores the resolved route values in the ComponentContext to pass them
  * to other components. They can be accessed via ComponentContext::getParameter('TYPO3\Flow\Mvc\Routing\RoutingComponent', 'matchResults');
  *
  * @param ComponentContext $componentContext
  * @return void
  */
 public function handle(ComponentContext $componentContext)
 {
     $matchResults = $this->router->route($componentContext->getHttpRequest());
     $componentContext->setParameter('TYPO3\\Flow\\Mvc\\Routing\\RoutingComponent', 'matchResults', $matchResults);
 }
コード例 #10
0
 /**
  * Resolve a route for the request
  *
  * Stores the resolved route values in the ComponentContext to pass them
  * to other components. They can be accessed via ComponentContext::getParameter(outingComponent::class, 'matchResults');
  *
  * @param ComponentContext $componentContext
  * @return void
  */
 public function handle(ComponentContext $componentContext)
 {
     $matchResults = $this->router->route($componentContext->getHttpRequest());
     $componentContext->setParameter(RoutingComponent::class, 'matchResults', $matchResults);
 }
コード例 #11
0
 /**
  * Returns the currently handled HTTP request
  *
  * @return Request
  * @api
  */
 public function getHttpRequest()
 {
     return $this->componentContext->getHttpRequest();
 }
 /**
  * @param ComponentContext $componentContext
  * @return void
  */
 public function handle(ComponentContext $componentContext)
 {
     $httpRequest = $componentContext->getHttpRequest();
     $requestPath = $httpRequest->getUri()->getPath();
     $firstRequestPathSegment = explode('/', ltrim($requestPath, '/'))[0];
     //Check if url contains user, if so, don't detect language
     if (strpos($requestPath, '@user-')) {
         return;
     }
     if (isset($this->options['allowedMethods']) && !in_array($httpRequest->getMethod(), $this->options['allowedMethods'])) {
         //the current HTTP method is not within the allow methods, abort!
         return;
     }
     $preset = null;
     if (!isset($this->options['ignoreSegments']) || !in_array($firstRequestPathSegment, $this->options['ignoreSegments'])) {
         $preset = $this->findPreset($firstRequestPathSegment);
         if ($preset !== null) {
             //uri contains a valid language segment => no need for us to proceed
             return;
         }
     } else {
         //the configuration told us to ignore this segment => no need for us to proceed
         return;
     }
     $defaultPreset = $this->contentDimensionPresetSource->getDefaultPreset('language');
     $referer = $httpRequest->getHeaders()->get('Referer');
     $refererInfo = $this->parseUriInfo($referer);
     $currentInfo = $this->parseUriInfo((string) $httpRequest->getUri());
     $varnishInfo = isset($this->varnishSettings['varnishUrl']) ? $this->parseUriInfo($this->varnishSettings['varnishUrl']) : null;
     if ($refererInfo['host'] == $currentInfo['host'] || $varnishInfo !== null && $refererInfo['host'] == $varnishInfo['host']) {
         $firstRefererRequestPathSegment = explode('/', ltrim($refererInfo['requestPath'], '/'))[0];
         $refererPreset = $preset = $this->findPreset($firstRefererRequestPathSegment);
         if (empty($firstRequestPathSegment) && $refererPreset !== null && empty(ltrim(str_replace($firstRefererRequestPathSegment, '', $refererInfo['requestPath']), '/'))) {
             $preset = $defaultPreset;
         } else {
             $preset = $refererPreset;
         }
     } else {
         $detectedLocale = $this->localeDetector->detectLocaleFromHttpHeader($httpRequest->getHeader('Accept-Language'));
         if ($detectedLocale instanceof Locale) {
             $preset = $this->findPreset($detectedLocale->getLanguage());
             if ($preset !== null && empty(trim($requestPath, " \t\n\r\v/")) && $preset['uriSegment'] == $defaultPreset['uriSegment']) {
                 //we're on the homepage, and the browsers language is equal to the default language => no need for us to proceed
                 return;
             }
         }
     }
     if ($preset === null) {
         $preset = $defaultPreset;
     }
     if ($preset === null) {
         throw new Exception("Couldn't resolve the language and default language is not set. Check your language config.");
         return;
     }
     $uri = $httpRequest->getUri();
     if (isset($this->httpSettings['baseUri'])) {
         $baseInfo = $this->parseUriInfo($this->httpSettings['baseUri']);
         $uri->setHost($baseInfo['host']);
     }
     if (isset($this->httpSettings['port'])) {
         $uri->setPort($this->httpSettings['port']);
     }
     if (isset($this->httpSettings['username'])) {
         $uri->setUsername($this->httpSettings['username']);
     }
     if (isset($this->httpSettings['password'])) {
         $uri->setUsername($this->httpSettings['password']);
     }
     $uri->setPath('/' . $preset['uriSegment'] . $requestPath);
     $response = $componentContext->getHttpResponse();
     $response->setContent(sprintf('<html><head><meta http-equiv="refresh" content="0;url=%s"/></head></html>', htmlentities((string) $uri, ENT_QUOTES, 'utf-8')));
     $response->setHeader('Location', (string) $uri);
     $componentContext->setParameter(ComponentChain::class, 'cancel', TRUE);
 }