Skip to content

Commit 7eb58e6

Browse files
committed
[Security] Add XML support for authenticator manager
1 parent ca06651 commit 7eb58e6

File tree

6 files changed

+115
-1
lines changed

6 files changed

+115
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class LoginLinkFactory extends AbstractFactory implements AuthenticatorFactoryIn
3131
public function addConfiguration(NodeDefinition $node)
3232
{
3333
/** @var NodeBuilder $builder */
34-
$builder = $node->children();
34+
$builder = $node->fixXmlConfig('signature_property', 'signature_properties')->children();
3535

3636
$builder
3737
->scalarNode('check_route')

src/Symfony/Bundle/SecurityBundle/Resources/config/schema/security-1.0.xsd

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<xsd:attribute name="hide-user-not-found" type="xsd:boolean" />
2424
<xsd:attribute name="always-authenticate-before-granting" type="xsd:boolean" />
2525
<xsd:attribute name="erase-credentials" type="xsd:boolean" />
26+
<xsd:attribute name="enable-authenticator-manager" type="xsd:boolean" />
2627
</xsd:complexType>
2728

2829
<xsd:complexType name="encoders">
@@ -141,6 +142,7 @@
141142
<xsd:element name="http-basic-ldap" type="http_basic_ldap" minOccurs="0" maxOccurs="1" />
142143
<xsd:element name="json-login" type="json_login" minOccurs="0" maxOccurs="1" />
143144
<xsd:element name="json-login-ldap" type="json_login_ldap" minOccurs="0" maxOccurs="1" />
145+
<xsd:element name="login-throttling" type="login_throttling" minOccurs="0" maxOccurs="1" />
144146
<xsd:element name="remember-me" type="remember_me" minOccurs="0" maxOccurs="1" />
145147
<xsd:element name="remote-user" type="remote_user" minOccurs="0" maxOccurs="1" />
146148
<xsd:element name="x509" type="x509" minOccurs="0" maxOccurs="1" />
@@ -160,6 +162,7 @@
160162
<xsd:attribute name="provider" type="xsd:string" />
161163
<xsd:attribute name="stateless" type="xsd:boolean" />
162164
<xsd:attribute name="context" type="xsd:string" />
165+
<xsd:attribute name="lazy" type="xsd:boolean" />
163166
<!-- allow factories to use dynamic elements -->
164167
<xsd:anyAttribute processContents="lax" />
165168
</xsd:complexType>
@@ -231,6 +234,7 @@
231234
<xsd:attribute name="csrf-token-id" type="xsd:string" />
232235
<xsd:attribute name="post-only" type="xsd:boolean" />
233236
<xsd:attribute name="csrf-token-generator" type="xsd:string" />
237+
<xsd:attribute name="enable-csrf" type="xsd:boolean" />
234238
<xsd:attributeGroup ref="success-handler-options" />
235239
<xsd:attributeGroup ref="failure-handler-options" />
236240
</xsd:extension>
@@ -283,6 +287,25 @@
283287
</xsd:complexContent>
284288
</xsd:complexType>
285289

290+
<xsd:complexType name="login_link">
291+
<xsd:choice minOccurs="0" maxOccurs="unbounded">
292+
<xsd:element name="signature-property" type="xsd:string" />
293+
</xsd:choice>
294+
<xsd:attribute name="check-route" type="xsd:string" />
295+
<xsd:attribute name="check-post-only" type="xsd:boolean" />
296+
<xsd:attribute name="lifetime" type="xsd:integer" />
297+
<xsd:attribute name="max-uses" type="xsd:integer" />
298+
<xsd:attribute name="used-link-cache" type="xsd:string" />
299+
<xsd:attribute name="success-handler" type="xsd:string" />
300+
<xsd:attribute name="failure-handler" type="xsd:string" />
301+
<xsd:attribute name="provider" type="xsd:string" />
302+
</xsd:complexType>
303+
304+
<xsd:complexType name="login_throttling">
305+
<xsd:attribute name="limiter" type="xsd:string" />
306+
<xsd:attribute name="max-attempts" type="xsd:integer" />
307+
</xsd:complexType>
308+
286309
<xsd:complexType name="remember_me">
287310
<xsd:choice minOccurs="0" maxOccurs="unbounded">
288311
<xsd:element name="user-provider" type="xsd:string" />

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,46 @@
2121
use Symfony\Component\Security\Core\Authorization\AccessDecisionManager;
2222
use Symfony\Component\Security\Core\Encoder\NativePasswordEncoder;
2323
use Symfony\Component\Security\Core\Encoder\SodiumPasswordEncoder;
24+
use Symfony\Component\Security\Http\Authentication\AuthenticatorManager;
2425

2526
abstract class CompleteConfigurationTest extends TestCase
2627
{
2728
abstract protected function getLoader(ContainerBuilder $container);
2829

2930
abstract protected function getFileExtension();
3031

32+
public function testAuthenticatorManager()
33+
{
34+
$container = $this->getContainer('authenticator_manager');
35+
36+
$this->assertEquals(AuthenticatorManager::class, $container->getDefinition('security.authenticator.manager.main')->getClass());
37+
38+
// login link
39+
$expiredStorage = $container->getDefinition($expiredStorageId = 'security.authenticator.expired_login_link_storage.main');
40+
$this->assertEquals('cache.redis', (string) $expiredStorage->getArgument(0));
41+
$this->assertEquals(3600, (string) $expiredStorage->getArgument(1));
42+
43+
$linker = $container->getDefinition($linkerId = 'security.authenticator.login_link_handler.main');
44+
$this->assertEquals(['id', 'email'], $linker->getArgument(3));
45+
$this->assertEquals([
46+
'route_name' => 'login_check',
47+
'lifetime' => 3600,
48+
'max_uses' => 1,
49+
], $linker->getArgument(5));
50+
$this->assertEquals($expiredStorageId, (string) $linker->getArgument(6));
51+
52+
$authenticator = $container->getDefinition('security.authenticator.login_link.main');
53+
$this->assertEquals($linkerId, (string) $authenticator->getArgument(0));
54+
$this->assertEquals([
55+
'check_route' => 'login_check',
56+
'check_post_only' => true,
57+
], $authenticator->getArgument(4));
58+
59+
// login throttling
60+
$listener = $container->getDefinition('security.listener.login_throttling.main');
61+
$this->assertEquals('app.rate_limiter', (string) $listener->getArgument(1));
62+
}
63+
3164
public function testRolesHierarchy()
3265
{
3366
$container = $this->getContainer('container1');
@@ -648,6 +681,7 @@ protected function getContainer($file)
648681
$container->setParameter('kernel.debug', false);
649682
$container->setParameter('request_listener.http_port', 80);
650683
$container->setParameter('request_listener.https_port', 443);
684+
$container->register('cache.app', \stdClass::class);
651685

652686
$security = new SecurityExtension();
653687
$container->registerExtension($security);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
$container->loadFromExtension('security', [
4+
'enable_authenticator_manager' => true,
5+
'firewalls' => [
6+
'main' => [
7+
'login_link' => [
8+
'check_route' => 'login_check',
9+
'check_post_only' => true,
10+
'signature_properties' => ['id', 'email'],
11+
'max_uses' => 1,
12+
'lifetime' => 3600,
13+
'used_link_cache' => 'cache.redis',
14+
],
15+
'login_throttling' => [
16+
'limiter' => 'app.rate_limiter',
17+
],
18+
],
19+
],
20+
]);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<srv:container xmlns="http://symfony.com/schema/dic/security"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:srv="http://symfony.com/schema/dic/services"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services
6+
https://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/security
8+
https://symfony.com/schema/dic/security/security-1.0.xsd">
9+
10+
<config enable-authenticator-manager="true">
11+
<firewall name="main">
12+
<login-link check-route="login_check"
13+
check-post-only="true"
14+
max-uses="1"
15+
lifetime="3600"
16+
used-link-cache="cache.redis"
17+
>
18+
<signature-property>id</signature-property>
19+
<signature-property>email</signature-property>
20+
</login-link>
21+
<login-throttling limiter="app.rate_limiter"/>
22+
</firewall>
23+
</config>
24+
</srv:container>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
security:
2+
enable_authenticator_manager: true
3+
firewalls:
4+
main:
5+
login_link:
6+
check_route: login_check
7+
check_post_only: true
8+
signature_properties: [id, email]
9+
max_uses: 1
10+
lifetime: 3600
11+
used_link_cache: 'cache.redis'
12+
login_throttling:
13+
limiter: 'app.rate_limiter'

0 commit comments

Comments
 (0)