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 from GHSA-jr83-m233-gg6p
* Fix setting of Webspace Security System before Symfony RouteListener * Fix Redirect for Security System checker error * Add test case to avoid regression * Add test for none secured pages * Fix some PHP 7.2 issues * Remmove website based system listener test * Activate security only for specific test * Remove old ContentRouteProviderTests * Fix phpcs * Skip security listener test for older symfony security system * Fix code style * Fix phpstan issues * Throw deprecation when requestAnalyzer is still given * Fix code style * Mark new service as internal and final
- Loading branch information
1 parent
9bbc9c8
commit ec9c3f9
Showing
17 changed files
with
429 additions
and
224 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
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
83 changes: 83 additions & 0 deletions
83
src/Sulu/Bundle/WebsiteBundle/EventListener/SecurityListener.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,83 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) Sulu GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Bundle\WebsiteBundle\EventListener; | ||
|
||
use Sulu\Bundle\PageBundle\Document\BasePageDocument; | ||
use Sulu\Component\Content\Compat\Structure\PageBridge; | ||
use Sulu\Component\DocumentManager\Subscriber\EventSubscriberInterface; | ||
use Sulu\Component\Security\Authorization\PermissionTypes; | ||
use Sulu\Component\Security\Authorization\SecurityCheckerInterface; | ||
use Sulu\Component\Security\Authorization\SecurityCondition; | ||
use Sulu\Component\Webspace\Analyzer\Attributes\RequestAttributes; | ||
use Symfony\Component\HttpKernel\Event\RequestEvent; | ||
use Symfony\Component\HttpKernel\KernelEvents; | ||
|
||
class SecurityListener implements EventSubscriberInterface | ||
{ | ||
/** | ||
* @var SecurityCheckerInterface|null | ||
*/ | ||
private $securityChecker; | ||
|
||
public function __construct( | ||
?SecurityCheckerInterface $securityChecker = null | ||
) { | ||
$this->securityChecker = $securityChecker; | ||
} | ||
|
||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
KernelEvents::REQUEST => [ | ||
['onKernelRequest', 7], // set the security listener after the firewall and after the routing listener | ||
], | ||
]; | ||
} | ||
|
||
public function onKernelRequest(RequestEvent $event): void | ||
{ | ||
$request = $event->getRequest(); | ||
|
||
if (null === $this->securityChecker) { | ||
return; | ||
} | ||
|
||
$requestAttributes = $request->attributes->get('_sulu'); | ||
if (!$requestAttributes instanceof RequestAttributes) { | ||
return; | ||
} | ||
|
||
$webspace = $requestAttributes->getAttribute('webspace'); | ||
|
||
$structure = $request->attributes->get('structure'); | ||
if (!$structure instanceof PageBridge) { | ||
return; | ||
} | ||
|
||
$document = $structure->getDocument(); | ||
if (!$document instanceof BasePageDocument) { | ||
return; | ||
} | ||
|
||
if ($webspace->hasWebsiteSecurity()) { | ||
$this->securityChecker->checkPermission( | ||
new SecurityCondition( | ||
'sulu.webspaces.' . $document->getWebspaceName(), | ||
$document->getLocale(), | ||
\get_class($document), | ||
$document->getUuid() | ||
), | ||
PermissionTypes::VIEW | ||
); | ||
} | ||
} | ||
} |
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.