Skip to content

Commit 8e5eeec

Browse files
committed
Removed "services" prototype node from "custom_authenticator"
1 parent 8923514 commit 8e5eeec

File tree

2 files changed

+81
-11
lines changed

2 files changed

+81
-11
lines changed

DependencyInjection/Security/Factory/CustomAuthenticatorFactory.php

Lines changed: 17 additions & 9 deletions
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,27 @@ 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+
->prototype('scalar')->end();
50+
51+
// get the parent array node builder ("firewalls") from inside the children builder
52+
$factoryRootNode = $builder->end()->end();
53+
$factoryRootNode
54+
->fixXmlConfig('custom_authenticator')
55+
->validate()
56+
->ifTrue(function ($v) { return isset($v['custom_authenticators']) && empty($v['custom_authenticators']); })
57+
->then(function ($v) {
58+
unset($v['custom_authenticators']);
59+
60+
return $v;
61+
})
5462
->end()
5563
;
5664
}
5765

5866
public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): array
5967
{
60-
return $config['services'];
68+
return $config;
6169
}
6270
}

Tests/DependencyInjection/SecurityExtensionTest.php

Lines changed: 64 additions & 2 deletions
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)