-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1089 from ezsystems/fix_EZP-23632_reverseUserCont…
…extRegression Fix EZP-23632: Exception when running eZ Publish behind built in reverse proxy
- Loading branch information
Showing
16 changed files
with
506 additions
and
122 deletions.
There are no files selected for viewing
This file contains 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 characters
85 changes: 85 additions & 0 deletions
85
eZ/Bundle/EzPublishCoreBundle/EventListener/DynamicSettingsListener.php
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
/** | ||
* File containing the DynamicSettingsListener class. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
* @version //autogentag// | ||
*/ | ||
|
||
namespace eZ\Bundle\EzPublishCoreBundle\EventListener; | ||
|
||
use eZ\Publish\Core\MVC\Symfony\Event\PostSiteAccessMatchEvent; | ||
use eZ\Publish\Core\MVC\Symfony\Event\ScopeChangeEvent; | ||
use eZ\Publish\Core\MVC\Symfony\MVCEvents; | ||
use Symfony\Component\DependencyInjection\ContainerAware; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\HttpKernel\HttpKernelInterface; | ||
|
||
class DynamicSettingsListener extends ContainerAware implements EventSubscriberInterface | ||
{ | ||
/** | ||
* Array of serviceIds to reset in the container. | ||
* | ||
* @var array | ||
*/ | ||
private $resettableServiceIds; | ||
|
||
/** | ||
* Array of "fake" services handling dynamic settings injection. | ||
* | ||
* @var array | ||
*/ | ||
private $dynamicSettingsServiceIds; | ||
|
||
public function __construct( array $resettableServiceIds, array $dynamicSettingsServiceIds ) | ||
{ | ||
$this->resettableServiceIds = $resettableServiceIds; | ||
$this->dynamicSettingsServiceIds = $dynamicSettingsServiceIds; | ||
} | ||
|
||
public static function getSubscribedEvents() | ||
{ | ||
return array( | ||
MVCEvents::SITEACCESS => array( 'onSiteAccessMatch', 254 ), | ||
MVCEvents::CONFIG_SCOPE_CHANGE => array( 'onConfigScopeChange', 90 ), | ||
MVCEvents::CONFIG_SCOPE_RESTORE => array( 'onConfigScopeChange', 90 ) | ||
); | ||
} | ||
|
||
public function onSiteAccessMatch( PostSiteAccessMatchEvent $event ) | ||
{ | ||
if ( $event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST ) | ||
{ | ||
return; | ||
} | ||
|
||
$this->resetDynamicSettings(); | ||
} | ||
|
||
public function onConfigScopeChange( ScopeChangeEvent $event ) | ||
{ | ||
$this->resetDynamicSettings(); | ||
} | ||
|
||
/** | ||
* Ensure that dynamic settings are correctly reset, | ||
* so that services that rely on those are correctly updated | ||
*/ | ||
private function resetDynamicSettings() | ||
{ | ||
// Ensure to reset services that need to be. | ||
foreach ( $this->resettableServiceIds as $serviceId ) | ||
{ | ||
$this->container->set( $serviceId, null ); | ||
} | ||
|
||
// Force dynamic settings services to synchronize. | ||
// This will trigger services depending on dynamic settings to update if they use setter injection. | ||
foreach ( $this->dynamicSettingsServiceIds as $fakeServiceId ) | ||
{ | ||
$this->container->set( $fakeServiceId, null ); | ||
$this->container->set( $fakeServiceId, $this->container->get( $fakeServiceId ) ); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
eZ/Bundle/EzPublishCoreBundle/EventListener/OriginalRequestListener.php
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
/** | ||
* File containing the OriginalRequestListener class. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
* @version //autogentag// | ||
*/ | ||
|
||
namespace eZ\Bundle\EzPublishCoreBundle\EventListener; | ||
|
||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpKernel\Event\GetResponseEvent; | ||
use Symfony\Component\HttpKernel\HttpKernelInterface; | ||
use Symfony\Component\HttpKernel\KernelEvents; | ||
|
||
/** | ||
* Request listener setting potential original request as current request attribute. | ||
* Such situation occurs when generating user context hash from an external reverse proxy (e.g. Varnish). | ||
*/ | ||
class OriginalRequestListener implements EventSubscriberInterface | ||
{ | ||
public static function getSubscribedEvents() | ||
{ | ||
return array( | ||
KernelEvents::REQUEST => array( 'onKernelRequest', 200 ) | ||
); | ||
} | ||
|
||
public function onKernelRequest( GetResponseEvent $event ) | ||
{ | ||
if ( $event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST ) | ||
{ | ||
return; | ||
} | ||
|
||
$request = $event->getRequest(); | ||
if ( !$request->headers->has( 'x-fos-original-url' ) ) | ||
{ | ||
return; | ||
} | ||
|
||
$originalRequest = Request::create( | ||
$request->getSchemeAndHttpHost() . $request->headers->get( 'x-fos-original-url' ), | ||
'GET', array(), array(), array(), | ||
array( 'HTTP_ACCEPT' => $request->headers->get( 'x-fos-original-accept' ) ) | ||
); | ||
$originalRequest->headers->set( 'user-agent', $request->headers->get( 'user-agent' ) ); | ||
$originalRequest->headers->set( 'accept-language', $request->headers->get( 'accept-language' ) ); | ||
$request->attributes->set( '_ez_original_request', $originalRequest ); | ||
} | ||
} |
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Oops, something went wrong.