From b1048a4a982c8c3d60cd2daac9598378a1821dde Mon Sep 17 00:00:00 2001 From: Mohammed Date: Sun, 6 Oct 2024 19:57:21 +0100 Subject: [PATCH] * ibexa4.6 : eZ2FABundle Migration [support php>=8.1] --- .../Command/Remove2FAForUserCommand.php | 4 +-- .../2FABundle/bundle/Core/AuthCodeMailer.php | 4 +-- .../bundle/Core/BackupCodeManager.php | 2 +- .../bundle/Core/EmailCodeGenerator.php | 10 +++++--- .../2FABundle/bundle/Core/QRCodeGenerator.php | 4 +-- .../SiteAccessAwareAuthenticatorResolver.php | 25 ++++++++----------- .../Core/SiteAccessAwareQueryExecutor.php | 4 +-- .../2FABundle/bundle/Core/UserRepository.php | 2 +- .../DependencyInjection/Configuration.php | 2 +- .../bundle/Entity/BackupCodeAware.php | 2 +- .../2FABundle/bundle/Entity/UserEmailAuth.php | 4 +-- .../bundle/Entity/UserTotpAuthSecret.php | 10 ++++---- .../bundle/Listener/MenuEventSubscriber.php | 2 +- .../bundle/Listener/OnHttpRequestListener.php | 6 ++--- ...TwoFactorAuthenticationEventSubscriber.php | 2 +- .../bundle/Listener/UserEventSubscriber.php | 2 +- .../TwoFactorUserProviderDecorator.php | 4 +-- components/2FABundle/composer.json | 2 +- 18 files changed, 46 insertions(+), 45 deletions(-) diff --git a/components/2FABundle/bundle/Command/Remove2FAForUserCommand.php b/components/2FABundle/bundle/Command/Remove2FAForUserCommand.php index 5179ed324..07a79887c 100644 --- a/components/2FABundle/bundle/Command/Remove2FAForUserCommand.php +++ b/components/2FABundle/bundle/Command/Remove2FAForUserCommand.php @@ -26,12 +26,12 @@ final class Remove2FAForUserCommand extends Command /** * @var UserProviderInterface */ - private $userProvider; + private UserProviderInterface $userProvider; /** * @var UserRepository */ - private $userRepository; + private UserRepository $userRepository; /** * @required diff --git a/components/2FABundle/bundle/Core/AuthCodeMailer.php b/components/2FABundle/bundle/Core/AuthCodeMailer.php index 9e2522582..c68b9d85a 100644 --- a/components/2FABundle/bundle/Core/AuthCodeMailer.php +++ b/components/2FABundle/bundle/Core/AuthCodeMailer.php @@ -30,10 +30,10 @@ final class AuthCodeMailer implements AuthCodeMailerInterface private $senderAddress; public function __construct( - private MailerInterface $mailer, + protected MailerInterface $mailer, string $senderEmail, ?string $senderName, - private TranslatorInterface $translator + protected TranslatorInterface $translator ) { $this->senderAddress = new Address($senderEmail, $senderName ?? ''); } diff --git a/components/2FABundle/bundle/Core/BackupCodeManager.php b/components/2FABundle/bundle/Core/BackupCodeManager.php index 19b934861..e09eaf911 100644 --- a/components/2FABundle/bundle/Core/BackupCodeManager.php +++ b/components/2FABundle/bundle/Core/BackupCodeManager.php @@ -21,7 +21,7 @@ final class BackupCodeManager implements BackupCodeManagerInterface { - public function __construct(private UserRepository $userRepository) + public function __construct(protected UserRepository $userRepository) { } diff --git a/components/2FABundle/bundle/Core/EmailCodeGenerator.php b/components/2FABundle/bundle/Core/EmailCodeGenerator.php index 96c925728..f26cd0881 100644 --- a/components/2FABundle/bundle/Core/EmailCodeGenerator.php +++ b/components/2FABundle/bundle/Core/EmailCodeGenerator.php @@ -14,6 +14,7 @@ namespace Novactive\Bundle\eZ2FABundle\Core; +use Exception; use Novactive\Bundle\eZ2FABundle\Entity\UserEmailAuth; use Scheb\TwoFactorBundle\Mailer\AuthCodeMailerInterface; use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface; @@ -23,9 +24,9 @@ final class EmailCodeGenerator implements CodeGeneratorInterface { public function __construct( - private UserRepository $userRepository, - private AuthCodeMailerInterface $mailer, - private int $digits + protected UserRepository $userRepository, + protected AuthCodeMailerInterface $mailer, + protected int $digits ){ } @@ -45,6 +46,9 @@ public function reSend(TwoFactorInterface $user): void $this->mailer->sendAuthCode($user); } + /** + * @throws Exception + */ private function generateCode(int $min, int $max): int { return random_int($min, $max); diff --git a/components/2FABundle/bundle/Core/QRCodeGenerator.php b/components/2FABundle/bundle/Core/QRCodeGenerator.php index db14e4945..f3d553292 100644 --- a/components/2FABundle/bundle/Core/QRCodeGenerator.php +++ b/components/2FABundle/bundle/Core/QRCodeGenerator.php @@ -25,8 +25,8 @@ final class QRCodeGenerator { public function __construct( - private GoogleAuthenticator $googleAuthenticator, - private TotpAuthenticator $totpAuthenticator + protected GoogleAuthenticator $googleAuthenticator, + protected TotpAuthenticator $totpAuthenticator ) { } diff --git a/components/2FABundle/bundle/Core/SiteAccessAwareAuthenticatorResolver.php b/components/2FABundle/bundle/Core/SiteAccessAwareAuthenticatorResolver.php index 3e737ce8a..c0efe9ece 100644 --- a/components/2FABundle/bundle/Core/SiteAccessAwareAuthenticatorResolver.php +++ b/components/2FABundle/bundle/Core/SiteAccessAwareAuthenticatorResolver.php @@ -33,22 +33,22 @@ class SiteAccessAwareAuthenticatorResolver implements SiteAccessAware /** * @var SiteAccess|null */ - private $siteAccess; + private ?SiteAccess $siteAccess; /** * @var string */ - private $method; + private string $method; /** * @var array */ - private $config; + private array $config; /** * @var bool */ - private $emailMethodEnabled; + private bool $emailMethodEnabled; /** * @var bool @@ -56,11 +56,11 @@ class SiteAccessAwareAuthenticatorResolver implements SiteAccessAware private $forceSetup; public function __construct( - private ConfigResolverInterface $configResolver, - private GoogleAuthenticator $googleAuthenticator, - private TotpAuthenticator $totpAuthenticator, - private UserRepository $userRepository, - private bool $backupCodesEnabled + protected ConfigResolverInterface $configResolver, + protected GoogleAuthenticator $googleAuthenticator, + protected TotpAuthenticator $totpAuthenticator, + protected UserRepository $userRepository, + protected bool $backupCodesEnabled ) { } @@ -139,10 +139,7 @@ public function getUserForDecorator(User $user): User $this->method = 'email'; } - if ( - false === $userAuthData || - ('email' !== $this->method && empty($userAuthData["{$this->method}_authentication_secret"])) - ) { + if ('email' !== $this->method && empty($userAuthData["{$this->method}_authentication_secret"])) { return $user; } @@ -158,7 +155,7 @@ public function getUserForDecorator(User $user): User return $authenticatorEntity; } - public function getAuthenticator() + public function getAuthenticator(): TotpAuthenticator|GoogleAuthenticator { if ('google' === $this->method) { return $this->googleAuthenticator; diff --git a/components/2FABundle/bundle/Core/SiteAccessAwareQueryExecutor.php b/components/2FABundle/bundle/Core/SiteAccessAwareQueryExecutor.php index d5707cc6b..de2efea93 100644 --- a/components/2FABundle/bundle/Core/SiteAccessAwareQueryExecutor.php +++ b/components/2FABundle/bundle/Core/SiteAccessAwareQueryExecutor.php @@ -22,8 +22,8 @@ final class SiteAccessAwareQueryExecutor { public function __construct( - private Registry $registry, - private RepositoryConfigurationProvider $repositoryConfigurationProvider + protected Registry $registry, + protected RepositoryConfigurationProvider $repositoryConfigurationProvider ) { } diff --git a/components/2FABundle/bundle/Core/UserRepository.php b/components/2FABundle/bundle/Core/UserRepository.php index ceafe1141..d877125f9 100644 --- a/components/2FABundle/bundle/Core/UserRepository.php +++ b/components/2FABundle/bundle/Core/UserRepository.php @@ -21,7 +21,7 @@ */ final class UserRepository { - public function __construct(private SiteAccessAwareQueryExecutor $queryExecutor) + public function __construct(protected SiteAccessAwareQueryExecutor $queryExecutor) { } diff --git a/components/2FABundle/bundle/DependencyInjection/Configuration.php b/components/2FABundle/bundle/DependencyInjection/Configuration.php index a3cc94203..5eaf40af4 100644 --- a/components/2FABundle/bundle/DependencyInjection/Configuration.php +++ b/components/2FABundle/bundle/DependencyInjection/Configuration.php @@ -20,7 +20,7 @@ class Configuration extends SAConfiguration { - public const string NAMESPACE = 'nova_ez2fa'; + public const NAMESPACE = 'nova_ez2fa'; public function getConfigTreeBuilder(): TreeBuilder { diff --git a/components/2FABundle/bundle/Entity/BackupCodeAware.php b/components/2FABundle/bundle/Entity/BackupCodeAware.php index 023f8013e..00ba10a5e 100644 --- a/components/2FABundle/bundle/Entity/BackupCodeAware.php +++ b/components/2FABundle/bundle/Entity/BackupCodeAware.php @@ -19,7 +19,7 @@ trait BackupCodeAware /** * @var array */ - private $backupCodes = []; + private array $backupCodes = []; public function isBackupCode(string $code): bool { diff --git a/components/2FABundle/bundle/Entity/UserEmailAuth.php b/components/2FABundle/bundle/Entity/UserEmailAuth.php index fe110d899..2784727f6 100644 --- a/components/2FABundle/bundle/Entity/UserEmailAuth.php +++ b/components/2FABundle/bundle/Entity/UserEmailAuth.php @@ -23,12 +23,12 @@ final class UserEmailAuth extends User implements TwoFactorInterface /** * @var string */ - private $email; + private string $email; /** * @var string */ - private $authCode; + private string $authCode; public function __construct(APIUser $user, array $roles = []) { diff --git a/components/2FABundle/bundle/Entity/UserTotpAuthSecret.php b/components/2FABundle/bundle/Entity/UserTotpAuthSecret.php index 33b931237..d3f8e5ea2 100644 --- a/components/2FABundle/bundle/Entity/UserTotpAuthSecret.php +++ b/components/2FABundle/bundle/Entity/UserTotpAuthSecret.php @@ -27,13 +27,13 @@ final class UserTotpAuthSecret extends User implements TwoFactorInterface, Backu /** * @var string|null */ - private $secret; + private ?string $secret; - private const string DEFAULT_ALGORITHM = TotpConfiguration::ALGORITHM_SHA1; - private const int DEFAULT_PERIOD = 30; - private const int DEFAULT_DIGITS = 6; + private const DEFAULT_ALGORITHM = TotpConfiguration::ALGORITHM_SHA1; + private const DEFAULT_PERIOD = 30; + private const DEFAULT_DIGITS = 6; - public function __construct(APIUser $user, array $roles = [], private array $config = []) + public function __construct(APIUser $user, array $roles = [], protected array $config = []) { parent::__construct($user, $roles); } diff --git a/components/2FABundle/bundle/Listener/MenuEventSubscriber.php b/components/2FABundle/bundle/Listener/MenuEventSubscriber.php index bbb394df2..b58f404e5 100644 --- a/components/2FABundle/bundle/Listener/MenuEventSubscriber.php +++ b/components/2FABundle/bundle/Listener/MenuEventSubscriber.php @@ -21,7 +21,7 @@ final class MenuEventSubscriber implements EventSubscriberInterface { - public function __construct(private MenuManipulator $menuManipulator, private TranslatorInterface $translator) + public function __construct(protected MenuManipulator $menuManipulator, protected TranslatorInterface $translator) { } diff --git a/components/2FABundle/bundle/Listener/OnHttpRequestListener.php b/components/2FABundle/bundle/Listener/OnHttpRequestListener.php index afbc89e76..93b626b8c 100644 --- a/components/2FABundle/bundle/Listener/OnHttpRequestListener.php +++ b/components/2FABundle/bundle/Listener/OnHttpRequestListener.php @@ -25,9 +25,9 @@ final class OnHttpRequestListener { public function __construct( - private TokenStorageInterface $tokenStorage, - private SiteAccessAwareAuthenticatorResolver $saAuthenticatorResolver, - private RouterInterface $router + protected TokenStorageInterface $tokenStorage, + protected SiteAccessAwareAuthenticatorResolver $saAuthenticatorResolver, + protected RouterInterface $router ) { } diff --git a/components/2FABundle/bundle/Listener/TwoFactorAuthenticationEventSubscriber.php b/components/2FABundle/bundle/Listener/TwoFactorAuthenticationEventSubscriber.php index 887871cda..a9be502f2 100644 --- a/components/2FABundle/bundle/Listener/TwoFactorAuthenticationEventSubscriber.php +++ b/components/2FABundle/bundle/Listener/TwoFactorAuthenticationEventSubscriber.php @@ -21,7 +21,7 @@ final class TwoFactorAuthenticationEventSubscriber implements EventSubscriberInterface { - public function __construct(private SiteAccessAwareAuthenticatorResolver $saAwareAuthenticatorResolver) + public function __construct(protected SiteAccessAwareAuthenticatorResolver $saAwareAuthenticatorResolver) { } diff --git a/components/2FABundle/bundle/Listener/UserEventSubscriber.php b/components/2FABundle/bundle/Listener/UserEventSubscriber.php index e1e85e02f..637e05cc8 100644 --- a/components/2FABundle/bundle/Listener/UserEventSubscriber.php +++ b/components/2FABundle/bundle/Listener/UserEventSubscriber.php @@ -21,7 +21,7 @@ final class UserEventSubscriber implements EventSubscriberInterface { - public function __construct(private UserRepository $userRepository) + public function __construct(protected UserRepository $userRepository) { } diff --git a/components/2FABundle/bundle/Security/TwoFactorUserProviderDecorator.php b/components/2FABundle/bundle/Security/TwoFactorUserProviderDecorator.php index 634eec523..3f05f438b 100644 --- a/components/2FABundle/bundle/Security/TwoFactorUserProviderDecorator.php +++ b/components/2FABundle/bundle/Security/TwoFactorUserProviderDecorator.php @@ -25,8 +25,8 @@ final class TwoFactorUserProviderDecorator implements UserProviderInterface, API { public function __construct( - private UserProviderInterface $provider, - private SiteAccessAwareAuthenticatorResolver $saAuthenticatorResolver + protected UserProviderInterface $provider, + protected SiteAccessAwareAuthenticatorResolver $saAuthenticatorResolver ) { } diff --git a/components/2FABundle/composer.json b/components/2FABundle/composer.json index b6201e71b..b084abb89 100644 --- a/components/2FABundle/composer.json +++ b/components/2FABundle/composer.json @@ -28,7 +28,7 @@ "MIT" ], "require": { - "php": ">=8.3", + "php": ">=8.1", "scheb/2fa-bundle": "v5.13.2", "scheb/2fa-google-authenticator": "v5.13.2", "scheb/2fa-totp": "v5.13.2",