From 5229e9c965885db795e48e68b464d10ee8d31c0f Mon Sep 17 00:00:00 2001 From: konradoboza Date: Thu, 9 May 2024 15:13:24 +0200 Subject: [PATCH] IBX-8140: Enabled authenticator manager-based security --- phpstan-baseline.neon | 55 ------------------- .../Security/RestSessionBasedFactory.php | 46 +++++++++++++--- src/bundle/IbexaRestBundle.php | 11 ++-- 3 files changed, 43 insertions(+), 69 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index a661bbdf..48ef070e 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -85,56 +85,6 @@ parameters: count: 1 path: src/bundle/DependencyInjection/IbexaRestExtension.php - - - message: "#^Method Ibexa\\\\Bundle\\\\Rest\\\\DependencyInjection\\\\Security\\\\RestSessionBasedFactory\\:\\:createEntryPoint\\(\\) has parameter \\$config with no type specified\\.$#" - count: 1 - path: src/bundle/DependencyInjection/Security/RestSessionBasedFactory.php - - - - message: "#^Method Ibexa\\\\Bundle\\\\Rest\\\\DependencyInjection\\\\Security\\\\RestSessionBasedFactory\\:\\:createEntryPoint\\(\\) has parameter \\$container with no type specified\\.$#" - count: 1 - path: src/bundle/DependencyInjection/Security/RestSessionBasedFactory.php - - - - message: "#^Method Ibexa\\\\Bundle\\\\Rest\\\\DependencyInjection\\\\Security\\\\RestSessionBasedFactory\\:\\:createEntryPoint\\(\\) has parameter \\$defaultEntryPoint with no type specified\\.$#" - count: 1 - path: src/bundle/DependencyInjection/Security/RestSessionBasedFactory.php - - - - message: "#^Method Ibexa\\\\Bundle\\\\Rest\\\\DependencyInjection\\\\Security\\\\RestSessionBasedFactory\\:\\:createEntryPoint\\(\\) has parameter \\$id with no type specified\\.$#" - count: 1 - path: src/bundle/DependencyInjection/Security/RestSessionBasedFactory.php - - - - message: "#^Method Ibexa\\\\Bundle\\\\Rest\\\\DependencyInjection\\\\Security\\\\RestSessionBasedFactory\\:\\:createListener\\(\\) has no return type specified\\.$#" - count: 1 - path: src/bundle/DependencyInjection/Security/RestSessionBasedFactory.php - - - - message: "#^Method Ibexa\\\\Bundle\\\\Rest\\\\DependencyInjection\\\\Security\\\\RestSessionBasedFactory\\:\\:createListener\\(\\) has parameter \\$config with no type specified\\.$#" - count: 1 - path: src/bundle/DependencyInjection/Security/RestSessionBasedFactory.php - - - - message: "#^Method Ibexa\\\\Bundle\\\\Rest\\\\DependencyInjection\\\\Security\\\\RestSessionBasedFactory\\:\\:createListener\\(\\) has parameter \\$container with no type specified\\.$#" - count: 1 - path: src/bundle/DependencyInjection/Security/RestSessionBasedFactory.php - - - - message: "#^Method Ibexa\\\\Bundle\\\\Rest\\\\DependencyInjection\\\\Security\\\\RestSessionBasedFactory\\:\\:createListener\\(\\) has parameter \\$id with no type specified\\.$#" - count: 1 - path: src/bundle/DependencyInjection/Security/RestSessionBasedFactory.php - - - - message: "#^Method Ibexa\\\\Bundle\\\\Rest\\\\DependencyInjection\\\\Security\\\\RestSessionBasedFactory\\:\\:createListener\\(\\) has parameter \\$userProvider with no type specified\\.$#" - count: 1 - path: src/bundle/DependencyInjection/Security/RestSessionBasedFactory.php - - - - message: "#^Method Ibexa\\\\Bundle\\\\Rest\\\\DependencyInjection\\\\Security\\\\RestSessionBasedFactory\\:\\:isRememberMeAware\\(\\) has parameter \\$config with no type specified\\.$#" - count: 1 - path: src/bundle/DependencyInjection/Security/RestSessionBasedFactory.php - - message: "#^Cannot call method isTokenValid\\(\\) on Symfony\\\\Component\\\\Security\\\\Csrf\\\\CsrfTokenManagerInterface\\|null\\.$#" count: 1 @@ -190,11 +140,6 @@ parameters: count: 1 path: src/bundle/EventListener/UserCheckRequestListener.php - - - message: "#^Method Ibexa\\\\Bundle\\\\Rest\\\\IbexaRestBundle\\:\\:build\\(\\) has no return type specified\\.$#" - count: 1 - path: src/bundle/IbexaRestBundle.php - - message: "#^Method Ibexa\\\\Bundle\\\\Rest\\\\RequestParser\\\\Router\\:\\:generate\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#" count: 1 diff --git a/src/bundle/DependencyInjection/Security/RestSessionBasedFactory.php b/src/bundle/DependencyInjection/Security/RestSessionBasedFactory.php index 778417ca..01486c4f 100644 --- a/src/bundle/DependencyInjection/Security/RestSessionBasedFactory.php +++ b/src/bundle/DependencyInjection/Security/RestSessionBasedFactory.php @@ -4,30 +4,44 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); + namespace Ibexa\Bundle\Rest\DependencyInjection\Security; use Ibexa\Rest\Server\Security\RestLogoutHandler; use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\FormLoginFactory; use Symfony\Component\DependencyInjection\ChildDefinition; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; -class RestSessionBasedFactory extends FormLoginFactory +final class RestSessionBasedFactory extends FormLoginFactory { public function __construct() { parent::__construct(); unset($this->options['check_path']); + $this->defaultSuccessHandlerOptions = []; $this->defaultFailureHandlerOptions = []; } - protected function isRememberMeAware($config) + /** + * @param array $config + */ + protected function isRememberMeAware(array $config): bool { return false; } - protected function createListener($container, $id, $config, $userProvider) - { + /** + * @param array $config + */ + protected function createListener( + ContainerBuilder $container, + string $id, + array $config, + ?string $userProvider + ): string { $listenerId = $this->getListenerId(); $listener = new ChildDefinition($listenerId); $listener->replaceArgument(2, $id); @@ -72,10 +86,24 @@ public function getKey(): string return 'ibexa_rest_session'; } - protected function createEntryPoint($container, $id, $config, $defaultEntryPoint): ?string - { - return $defaultEntryPoint; + /** + * @param array $config + */ + protected function createEntryPoint( + ContainerBuilder $container, + string $id, + array $config, + ?string $defaultEntryPointId + ): ?string { + return $defaultEntryPointId; } -} -class_alias(RestSessionBasedFactory::class, 'EzSystems\EzPlatformRestBundle\DependencyInjection\Security\RestSessionBasedFactory'); + public function createAuthenticator( + ContainerBuilder $container, + string $firewallName, + array $config, + string $userProviderId + ): string { + return parent::createAuthenticator($container, $firewallName . '__rest', $config, $userProviderId); + } +} diff --git a/src/bundle/IbexaRestBundle.php b/src/bundle/IbexaRestBundle.php index 1fb730cf..5e1cf4b2 100644 --- a/src/bundle/IbexaRestBundle.php +++ b/src/bundle/IbexaRestBundle.php @@ -4,6 +4,8 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); + namespace Ibexa\Bundle\Rest; use Ibexa\Bundle\Rest\DependencyInjection\Compiler; @@ -11,11 +13,12 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; -class IbexaRestBundle extends Bundle +final class IbexaRestBundle extends Bundle { - public function build(ContainerBuilder $container) + public function build(ContainerBuilder $container): void { parent::build($container); + $container->addCompilerPass(new Compiler\FieldTypeProcessorPass()); $container->addCompilerPass(new Compiler\InputHandlerPass()); $container->addCompilerPass(new Compiler\InputParserPass()); @@ -24,12 +27,10 @@ public function build(ContainerBuilder $container) /** @var \Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension $securityExtension */ $securityExtension = $container->getExtension('security'); - $securityExtension->addSecurityListenerFactory(new RestSessionBasedFactory()); + $securityExtension->addAuthenticatorFactory(new RestSessionBasedFactory()); if ($container->hasExtension('lexik_jwt_authentication')) { $container->addCompilerPass(new Compiler\LexikAuthorizationHeaderBridgePass()); } } } - -class_alias(IbexaRestBundle::class, 'EzSystems\EzPlatformRestBundle\EzPlatformRestBundle');