Skip to content

Commit b17c440

Browse files
committed
Removed "services" prototype node from "custom_authenticator"
1 parent a99a55f commit b17c440

File tree

2 files changed

+76
-12
lines changed

2 files changed

+76
-12
lines changed

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

+12-10
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function getPosition(): string
3535

3636
public function getKey(): string
3737
{
38-
return 'custom_authenticator';
38+
return 'custom_authenticators';
3939
}
4040

4141
/**
@@ -44,19 +44,21 @@ public function getKey(): string
4444
public function addConfiguration(NodeDefinition $builder)
4545
{
4646
$builder
47-
->fixXmlConfig('service')
48-
->children()
49-
->arrayNode('services')
50-
->info('An array of service ids for all of your "authenticators"')
51-
->requiresAtLeastOneElement()
52-
->prototype('scalar')->end()
53-
->end()
47+
->info('An array of service ids for all of your "authenticators"')
48+
->requiresAtLeastOneElement()
49+
->beforeNormalization()
50+
->ifString()
51+
->then(function ($v) { return [$v]; })
5452
->end()
55-
;
53+
->prototype('scalar')->end();
54+
55+
// get the parent array node builder ("firewalls") from inside the children builder
56+
$factoryRootNode = $builder->end()->end();
57+
$factoryRootNode->fixXmlConfig('custom_authenticator');
5658
}
5759

5860
public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): array
5961
{
60-
return $config['services'];
62+
return $config;
6163
}
6264
}

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php

+64-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@
2424
use Symfony\Component\DependencyInjection\Reference;
2525
use Symfony\Component\ExpressionLanguage\Expression;
2626
use Symfony\Component\HttpFoundation\Request;
27+
use Symfony\Component\HttpFoundation\Response;
2728
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
2829
use Symfony\Component\Security\Core\Exception\AuthenticationException;
2930
use Symfony\Component\Security\Core\User\UserInterface;
3031
use Symfony\Component\Security\Core\User\UserProviderInterface;
31-
use Symfony\Component\Security\Guard\AuthenticatorInterface;
32+
use Symfony\Component\Security\Guard\AuthenticatorInterface as GuardAuthenticatorInterface;
33+
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
34+
use Symfony\Component\Security\Http\Authenticator\HttpBasicAuthenticator;
35+
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
3236

3337
class SecurityExtensionTest extends TestCase
3438
{
@@ -520,6 +524,41 @@ public function testAlwaysAuthenticateBeforeGrantingCannotBeTrueWithAuthenticati
520524
$container->compile();
521525
}
522526

527+
/**
528+
* @dataProvider provideConfigureCustomAuthenticatorData
529+
*/
530+
public function testConfigureCustomAuthenticator(array $firewall, array $expectedAuthenticators)
531+
{
532+
$container = $this->getRawContainer();
533+
$container->loadFromExtension('security', [
534+
'enable_authenticator_manager' => true,
535+
'providers' => [
536+
'first' => ['id' => 'users'],
537+
],
538+
539+
'firewalls' => [
540+
'main' => $firewall,
541+
],
542+
]);
543+
544+
$container->compile();
545+
546+
$this->assertEquals($expectedAuthenticators, array_map('strval', $container->getDefinition('security.authenticator.manager.main')->getArgument(0)));
547+
}
548+
549+
public function provideConfigureCustomAuthenticatorData()
550+
{
551+
yield [
552+
['custom_authenticator' => TestAuthenticator::class],
553+
[TestAuthenticator::class],
554+
];
555+
556+
yield [
557+
['custom_authenticators' => [TestAuthenticator::class, HttpBasicAuthenticator::class]],
558+
[TestAuthenticator::class, HttpBasicAuthenticator::class],
559+
];
560+
}
561+
523562
protected function getRawContainer()
524563
{
525564
$container = new ContainerBuilder();
@@ -547,7 +586,30 @@ protected function getContainer()
547586
}
548587
}
549588

550-
class NullAuthenticator implements AuthenticatorInterface
589+
class TestAuthenticator implements AuthenticatorInterface
590+
{
591+
public function supports(Request $request): ?bool
592+
{
593+
}
594+
595+
public function authenticate(Request $request): PassportInterface
596+
{
597+
}
598+
599+
public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface
600+
{
601+
}
602+
603+
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response
604+
{
605+
}
606+
607+
public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response
608+
{
609+
}
610+
}
611+
612+
class NullAuthenticator implements GuardAuthenticatorInterface
551613
{
552614
public function start(Request $request, AuthenticationException $authException = null)
553615
{

0 commit comments

Comments
 (0)