[Security] Move configuration of guard to PHP

This commit is contained in:
Judicael 2020-06-11 13:14:10 +02:00 committed by Judicael RUFFIEUX
parent 79764a9e85
commit 417636fb61
3 changed files with 52 additions and 48 deletions

View File

@ -136,7 +136,7 @@ class SecurityExtension extends Extension implements PrependExtensionInterface
}
$phpLoader->load('collectors.php');
$loader->load('guard.xml');
$phpLoader->load('guard.php');
if ($container->hasParameter('kernel.debug') && $container->getParameter('kernel.debug')) {
$loader->load('security_debug.xml');

View File

@ -0,0 +1,51 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
use Symfony\Component\Security\Guard\Firewall\GuardAuthenticationListener;
use Symfony\Component\Security\Guard\GuardAuthenticatorHandler;
use Symfony\Component\Security\Guard\Provider\GuardAuthenticationProvider;
return static function (ContainerConfigurator $container) {
$container->services()
->set('security.authentication.guard_handler', GuardAuthenticatorHandler::class)
->args([
service('security.token_storage'),
service('event_dispatcher')->nullOnInvalid(),
abstract_arg('stateless firewall keys'),
])
->call('setSessionAuthenticationStrategy', [service('security.authentication.session_strategy')])
->alias(GuardAuthenticatorHandler::class, 'security.authentication.guard_handler')
->set('security.authentication.provider.guard', GuardAuthenticationProvider::class)
->abstract()
->args([
abstract_arg('Authenticators'),
abstract_arg('User Provider'),
abstract_arg('Provider-shared Key'),
abstract_arg('User Checker'),
service('security.password_encoder'),
])
->set('security.authentication.listener.guard', GuardAuthenticationListener::class)
->abstract()
->args([
service('security.authentication.guard_handler'),
service('security.authentication.manager'),
abstract_arg('Provider-shared Key'),
abstract_arg('Authenticators'),
service('logger')->nullOnInvalid(),
])
->tag('monolog.logger', ['channel' => 'security'])
;
};

View File

@ -1,47 +0,0 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="false" />
<service id="security.authentication.guard_handler"
class="Symfony\Component\Security\Guard\GuardAuthenticatorHandler"
>
<argument type="service" id="security.token_storage" />
<argument type="service" id="event_dispatcher" on-invalid="null" />
<argument /> <!-- stateless firewall keys -->
<call method="setSessionAuthenticationStrategy">
<argument type="service" id="security.authentication.session_strategy" />
</call>
</service>
<service id="Symfony\Component\Security\Guard\GuardAuthenticatorHandler" alias="security.authentication.guard_handler" />
<!-- See GuardAuthenticationFactory -->
<service id="security.authentication.provider.guard"
class="Symfony\Component\Security\Guard\Provider\GuardAuthenticationProvider"
abstract="true"
>
<argument /> <!-- Simple Authenticator -->
<argument /> <!-- User Provider -->
<argument /> <!-- Provider-shared Key -->
<argument /> <!-- User Checker -->
<argument type="service" id="security.password_encoder" />
</service>
<service id="security.authentication.listener.guard"
class="Symfony\Component\Security\Guard\Firewall\GuardAuthenticationListener"
abstract="true"
>
<tag name="monolog.logger" channel="security" />
<argument type="service" id="security.authentication.guard_handler" />
<argument type="service" id="security.authentication.manager" />
<argument /> <!-- Provider-shared Key -->
<argument /> <!-- Authenticator -->
<argument type="service" id="logger" on-invalid="null" />
</service>
</services>
</container>