diff --git a/src/Maker/MakeAuthenticator.php b/src/Maker/MakeAuthenticator.php index f2a048496..1722081be 100644 --- a/src/Maker/MakeAuthenticator.php +++ b/src/Maker/MakeAuthenticator.php @@ -38,6 +38,7 @@ use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\RateLimiter\LimiterInterface; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; @@ -209,6 +210,15 @@ function ($answer) { $supportRememberMeValues[$supportRememberMeType] ); } + + $command->addArgument('support-throttling', InputArgument::OPTIONAL); + $input->setArgument( + 'support-throttling', + $io->confirm( + 'Do you want to enable the throttling protection?', + true + ) + ); } } @@ -219,6 +229,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen $supportRememberMe = $input->hasArgument('support-remember-me') ? $input->getArgument('support-remember-me') : false; $alwaysRememberMe = $input->hasArgument('always-remember-me') ? $input->getArgument('always-remember-me') : false; + $supportThrottling = $input->hasArgument('support-throttling') ? $input->getArgument('support-throttling') : false; $this->generateAuthenticatorClass( $securityData, @@ -246,7 +257,8 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen $input->getArgument('authenticator-class'), $input->hasArgument('logout-setup') ? $input->getArgument('logout-setup') : false, $supportRememberMe, - $alwaysRememberMe + $alwaysRememberMe, + $supportThrottling, ); $generator->dumpFile($path, $newYaml); $securityYamlUpdated = true; @@ -458,5 +470,13 @@ public function configureDependencies(DependencyBuilder $dependencies, InputInte Yaml::class, 'yaml' ); + + $supportThrottling = $input->hasArgument('support-throttling') ? $input->getArgument('support-throttling') : false; + if ($supportThrottling) { + $dependencies->addClassDependency( + LimiterInterface::class, + 'symfony/rate-limiter' + ); + } } } diff --git a/src/Security/SecurityConfigUpdater.php b/src/Security/SecurityConfigUpdater.php index 2f45b0c8e..40ab1de93 100644 --- a/src/Security/SecurityConfigUpdater.php +++ b/src/Security/SecurityConfigUpdater.php @@ -69,7 +69,7 @@ public function updateForUserClass(string $yamlSource, UserClassConfiguration $u return $contents; } - public function updateForAuthenticator(string $yamlSource, string $firewallName, $chosenEntryPoint, string $authenticatorClass, bool $logoutSetup, bool $supportRememberMe, bool $alwaysRememberMe): string + public function updateForAuthenticator(string $yamlSource, string $firewallName, $chosenEntryPoint, string $authenticatorClass, bool $logoutSetup, bool $supportRememberMe, bool $alwaysRememberMe, bool $supportThrottling): string { $this->createYamlSourceManipulator($yamlSource); @@ -145,6 +145,10 @@ public function updateForAuthenticator(string $yamlSource, string $firewallName, } } + if ($supportThrottling) { + $firewall['throttling'] = '~'; + } + $newData['security']['firewalls'][$firewallName] = $firewall; if (!isset($firewall['logout']) && $logoutSetup) {