-
-
Save vixe76/dd6bf0fbfd590fcaee8f9e289bf79e7c to your computer and use it in GitHub Desktop.
Revisions
-
Bastian Waidelich revised this gist
Jun 1, 2015 . 2 changed files with 55 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,6 +9,7 @@ use TYPO3\Flow\Annotations as Flow; use TYPO3\Flow\Http\Component\ComponentChain; use TYPO3\Flow\Http\Component\ComponentContext; use TYPO3\Flow\Mvc\Routing\UriBuilder; use TYPO3\Flow\Security\Exception\AccessDeniedException; /** @@ -24,17 +25,60 @@ public function handle(ComponentContext $componentContext) { try { parent::handle($componentContext); } catch (AccessDeniedException $exception) { $this->initiateRedirect($componentContext); } } /** * Triggers the redirect, if configured * * @param ComponentContext $componentContext * @return void */ protected function initiateRedirect(ComponentContext $componentContext) { if (isset($this->options['redirectUriUponAccessDenied']['routeValues'])) { $routeValues = $this->options['redirectUriUponAccessDenied']['routeValues']; $actionRequest = $componentContext->getParameter('TYPO3\Flow\Mvc\DispatchComponent', 'actionRequest'); $uriBuilder = new UriBuilder(); $uriBuilder->setRequest($actionRequest); $actionName = $this->extractRouteValue($routeValues, '@action'); $controllerName = $this->extractRouteValue($routeValues, '@controller'); $packageKey = $this->extractRouteValue($routeValues, '@package'); $subPackageKey = $this->extractRouteValue($routeValues, '@subpackage'); $uri = $uriBuilder->setCreateAbsoluteUri(TRUE)->uriFor($actionName, $routeValues, $controllerName, $packageKey, $subPackageKey); } elseif (isset($this->options['redirectUriUponAccessDenied']['uri'])) { $uri = $this->options['redirectUriUponAccessDenied']['uri']; if (strpos($uri, '://') === FALSE) { $uri = $componentContext->getHttpRequest()->getBaseUri() . $uri; } } else { // no redirect URI configured return; } $response = $componentContext->getHttpResponse(); $response->setContent(sprintf('<html><head><meta http-equiv="refresh" content="0;url=%s"/></head></html>', htmlentities($uri, ENT_QUOTES, 'utf-8'))); $response->setStatus(303); $response->setHeader('Location', $uri); $componentContext->setParameter(ComponentChain::class, 'cancel', TRUE); } /** * Returns the entry $key from the array $routeValues removing the original array item. * If $key does not exist, NULL is returned. * * @param array $routeValues * @param string $key * @return mixed the specified route value or NULL if it is not set */ protected function extractRouteValue(array &$routeValues, $key) { if (!isset($routeValues[$key])) { return NULL; } $routeValue = $routeValues[$key]; unset($routeValues[$key]); return $routeValue; } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,4 +7,8 @@ TYPO3: 'dispatching': component: 'Wwwision\Test\Mvc\DispatchComponent' componentOptions: 'redirectUriUponAccessDenied': routeValues: '@package': 'Wwwision.Test' '@controller': 'Login' '@action': 'login' -
Bastian Waidelich revised this gist
Jun 1, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,7 @@ public function handle(ComponentContext $componentContext) { parent::handle($componentContext); } catch (AccessDeniedException $exception) { $uri = $this->options['redirectUriUponAccessDenied']; if (strpos($uri, '://') === FALSE) { $uri = $componentContext->getHttpRequest()->getBaseUri() . $uri; } -
Bastian Waidelich created this gist
Jun 1, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ <?php namespace Wwwision\Test\Mvc; /* * * This script belongs to the TYPO3 Flow package "Wwwision.Test". * * * * */ use TYPO3\Flow\Annotations as Flow; use TYPO3\Flow\Http\Component\ComponentChain; use TYPO3\Flow\Http\Component\ComponentContext; use TYPO3\Flow\Security\Exception\AccessDeniedException; /** * A custom implementation of the default DispatchComponent that allows for redirecting to a configurable URI upon access denied exceptions */ class DispatchComponent extends \TYPO3\Flow\Mvc\DispatchComponent { /** * @param ComponentContext $componentContext * @return void */ public function handle(ComponentContext $componentContext) { try { parent::handle($componentContext); } catch (AccessDeniedException $exception) { $uri = $this->options['redirectUriUponAccessDenied']; if (strpos($this->options['uri'], '://') === FALSE) { $uri = $componentContext->getHttpRequest()->getBaseUri() . $uri; } $response = $componentContext->getHttpResponse(); $response->setContent(sprintf('<html><head><meta http-equiv="refresh" content="0;url=%s"/></head></html>', htmlentities($uri, ENT_QUOTES, 'utf-8'))); $response->setStatus(303); $response->setHeader('Location', $uri); $componentContext->setParameter(ComponentChain::class, 'cancel', TRUE); } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ TYPO3: Flow: http: chain: 'process': chain: 'dispatching': component: 'Wwwision\Test\Mvc\DispatchComponent' componentOptions: 'redirectUriUponAccessDenied': 'login'