8000 Require entry_point to be configured with multiple authenticators · symfony/symfony@6179d5d · GitHub
[go: up one dir, main page]

Skip to content

Commit 6179d5d

Browse files
committed
Require entry_point to be configured with multiple authenticators
Meanwhile, entry_point can now also be set to an authenticator name (instead of only service IDs), to ease configuration.
1 parent c6cf433 commit 6179d5d

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpBasicFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* @author Fabien Potencier <fabien@symfony.com>
2323
*/
24-
class HttpBasicFactory implements SecurityFactoryInterface, AuthenticatorFactoryInterface
24+
class HttpBasicFactory implements SecurityFactoryInterface, AuthenticatorFactoryInterface, EntryPointFactoryInterface
2525
{
2626
public function create(ContainerBuilder $container, string $id, array $config, string $userProvider, ?string $defaultEntryPoint)
2727
{
@@ -77,7 +77,7 @@ public function addConfiguration(NodeDefinition $node)
7777
;
7878
}
7979

80-
protected function createEntryPoint(ContainerBuilder $container, string $id, array $config, ?string $defaultEntryPoint)
80+
public function createEntryPoint(ContainerBuilder $container, string $id, array $config, ?string $defaultEntryPoint): string
8181
{
8282
if (null !== $defaultEntryPoint) {
8383
return $defaultEntryPoint;

src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
use Symfony\Component\Security\Core\User\ChainUserProvider;
4040
use Symfony\Component\Security\Core\User\UserProviderInterface;
4141
use Symfony\Component\Security\Http\Controller\UserValueResolver;
42+
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
4243
use Twig\Extension\AbstractExtension;
4344

4445
/**
@@ -519,6 +520,7 @@ private function createAuthenticationListeners(ContainerBuilder $container, stri
519520
{
520521
$listeners = [];
521522
$hasListeners = false;
523+
$entryPoints = [];
522524

523525
foreach ($this->listenerPositions as $position) {
524526
foreach ($this->factories[$position] as $factory) {
@@ -542,7 +544,7 @@ private function createAuthenticationListeners(ContainerBuilder $container, stri
542544
}
543545

544546
if ($factory instanceof EntryPointFactoryInterface) {
545-
$defaultEntryPoint = $factory->createEntryPoint($container, $id, $firewall[$key], $defaultEntryPoint);
547+
$entryPoints[$key] = $factory->createEntryPoint($container, $id, $firewall[$key], null);
546548
}
547549
} else {
548550
list($provider, $listenerId, $defaultEntryPoint) = $factory->create($container, $id, $firewall[$key], $userProvider, $defaultEntryPoint);
@@ -555,6 +557,19 @@ private function createAuthenticationListeners(ContainerBuilder $container, stri
555557
}
556558
}
557559

560+
if (!$entryPoints) {
561+
// we can be sure the authenticator system is enabled
562+
if (null !== $defaultEntryPoint) {
563+
return $entryPoints[$defaultEntryPoint] ?? $defaultEntryPoint;
564+
}
565+
566+
if (1 === \count($entryPoints)) {
567+
return current($entryPoints);
568+
}
569+
570+
throw new InvalidConfigurationException(sprintf('Because you have multiple authenticators in firewall "%s", you need to set the "entry_point" key to one of your authenticators (%s) or a service ID implementing "%s".', $id, implode(', ', $entryPoints), AuthenticationEntryPointInterface::class));
571+
}
572+
558573
if (false === $hasListeners) {
559574
throw new InvalidConfigurationException(sprintf('No authentication listener registered for firewall "%s".', $id));
560575
}

0 commit comments

Comments
 (0)
0