Skip to content

Commit

Permalink
Removed all mentions of 'guard' in the new system
Browse files Browse the repository at this point in the history
This to remove confusion between the new system and Guard. When using the new
system, guard should not be installed. Guard did however influence the idea
behind the new system. Thus keeping the mentions of "guard" makes it confusing
to use the new system.
  • Loading branch information
wouterj committed Feb 6, 2020
1 parent 62133fe commit 2b2d17f
Show file tree
Hide file tree
Showing 43 changed files with 427 additions and 324 deletions.
Expand Up @@ -72,7 +72,7 @@ public function getConfigTreeBuilder()
->booleanNode('hide_user_not_found')->defaultTrue()->end()
->booleanNode('always_authenticate_before_granting')->defaultFalse()->end()
->booleanNode('erase_credentials')->defaultTrue()->end()
->booleanNode('guard_authentication_manager')->defaultFalse()->end()
->booleanNode('enable_authenticator_manager')->defaultFalse()->end()
->arrayNode('access_decision_manager')
->addDefaultsIfNotSet()
->children()
Expand Down
Expand Up @@ -19,7 +19,7 @@
/**
* @author Wouter de Jong <wouter@wouterj.nl>
*/
class AnonymousFactory implements SecurityFactoryInterface, GuardFactoryInterface
class AnonymousFactory implements SecurityFactoryInterface, AuthenticatorFactoryInterface
{
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint)
{
Expand All @@ -42,7 +42,7 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,
return [$providerId, $listenerId, $defaultEntryPoint];
}

public function createGuard(ContainerBuilder $container, string $id, array $config, ?string $userProviderId): string
public function createAuthenticator(ContainerBuilder $container, string $id, array $config, ?string $userProviderId): string
{
if (null === $config['secret']) {
$config['secret'] = new Parameter('container.build_hash');
Expand Down
Expand Up @@ -18,12 +18,12 @@
*
* @experimental in 5.1
*/
interface GuardFactoryInterface
interface AuthenticatorFactoryInterface
{
/**
* Creates the Guard service for the provided configuration.
*
* @return string The Guard service ID to be used by the firewall
*/
public function createGuard(ContainerBuilder $container, string $id, array $config, ?string $userProviderId): string;
public function createAuthenticator(ContainerBuilder $container, string $id, array $config, ?string $userProviderId): string;
}
Expand Up @@ -22,7 +22,7 @@
* @author Fabien Potencier <fabien@symfony.com>
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class FormLoginFactory extends AbstractFactory implements GuardFactoryInterface, EntrypointFactoryInterface
class FormLoginFactory extends AbstractFactory implements AuthenticatorFactoryInterface, EntrypointFactoryInterface
{
public function __construct()
{
Expand Down Expand Up @@ -97,7 +97,7 @@ public function createEntryPoint(ContainerBuilder $container, string $id, array
return $entryPointId;
}

public function createGuard(ContainerBuilder $container, string $id, array $config, ?string $userProviderId): string
public function createAuthenticator(ContainerBuilder $container, string $id, array $config, ?string $userProviderId): string
{
$authenticatorId = 'security.authenticator.form_login.'.$id;
$defaultOptions = array_merge($this->defaultSuccessHandlerOptions, $this->options);
Expand Down
Expand Up @@ -21,7 +21,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class HttpBasicFactory implements SecurityFactoryInterface, GuardFactoryInterface
class HttpBasicFactory implements SecurityFactoryInterface, AuthenticatorFactoryInterface
{
public function create(ContainerBuilder $container, string $id, array $config, string $userProvider, ?string $defaultEntryPoint)
{
Expand All @@ -46,7 +46,7 @@ public function create(ContainerBuilder $container, string $id, array $config, s
return [$provider, $listenerId, $entryPointId];
}

public function createGuard(ContainerBuilder $container, string $id, array $config, ?string $userProviderId): string
public function createAuthenticator(ContainerBuilder $container, string $id, array $config, ?string $userProviderId): string
{
$authenticatorId = 'security.authenticator.basic.'.$id;
$container
Expand Down
Expand Up @@ -12,7 +12,7 @@
namespace Symfony\Bundle\SecurityBundle\DependencyInjection;

use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\EntrypointFactoryInterface;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\GuardFactoryInterface;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\RememberMeFactory;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\UserProviderFactoryInterface;
Expand Down Expand Up @@ -53,7 +53,7 @@ class SecurityExtension extends Extension implements PrependExtensionInterface
private $userProviderFactories = [];
private $statelessFirewallKeys = [];

private $guardAuthenticationManagerEnabled = false;
private $authenticatorManagerEnabled = false;

public function __construct()
{
Expand Down Expand Up @@ -138,7 +138,7 @@ public function load(array $configs, ContainerBuilder $container)
$container->setParameter('security.access.always_authenticate_before_granting', $config['always_authenticate_before_granting']);
$container->setParameter('security.authentication.hide_user_not_found', $config['hide_user_not_found']);

if ($this->guardAuthenticationManagerEnabled = $config['guard_authentication_manager']) {
if ($this->authenticatorManagerEnabled = $config['enable_authenticator_manager']) {
$loader->load('authenticators.xml');
}

Expand All @@ -148,6 +148,8 @@ public function load(array $configs, ContainerBuilder $container)

$container->getDefinition('security.authentication.guard_handler')
->replaceArgument(2, $this->statelessFirewallKeys);
$container->getDefinition('security.authenticator_handler')
->replaceArgument(2, $this->statelessFirewallKeys);

if ($config['encoders']) {
$this->createEncoders($config['encoders'], $container);
Expand Down Expand Up @@ -266,8 +268,8 @@ private function createFirewalls(array $config, ContainerBuilder $container)
return new Reference($id);
}, array_unique($authenticationProviders));
$authenticationManagerId = 'security.authentication.manager.provider';
if ($this->guardAuthenticationManagerEnabled) {
$authenticationManagerId = 'security.authentication.manager.guard';
if ($this->authenticatorManagerEnabled) {
$authenticationManagerId = 'security.authentication.manager.authenticator';
$container->setAlias('security.authentication.manager', new Alias($authenticationManagerId));
}
$container
Expand Down Expand Up @@ -405,7 +407,7 @@ private function createFirewall(ContainerBuilder $container, string $id, array $
// Determine default entry point
$configuredEntryPoint = isset($firewall['entry_point']) ? $firewall['entry_point'] : null;

if ($this->guardAuthenticationManagerEnabled) {
if ($this->authenticatorManagerEnabled) {
// Remember me listener (must be before calling createAuthenticationListeners() to inject remember me services)
$container
->setDefinition('security.listener.remember_me.'.$id, new ChildDefinition('security.listener.remember_me'))
Expand All @@ -421,24 +423,24 @@ private function createFirewall(ContainerBuilder $container, string $id, array $

$authenticationProviders = array_merge($authenticationProviders, $firewallAuthenticationProviders);

if ($this->guardAuthenticationManagerEnabled) {
// guard authentication manager listener
if ($this->authenticatorManagerEnabled) {
// authenticator manager listener
$container
->setDefinition('security.firewall.guard.'.$id.'.locator', new ChildDefinition('security.firewall.guard.locator'))
->setDefinition('security.firewall.authenticator.'.$id.'.locator', new ChildDefinition('security.firewall.authenticator.locator'))
->setArguments([array_map(function ($id) {
return new Reference($id);
}, $firewallAuthenticationProviders)])
->addTag('container.service_locator')
;

$container
->setDefinition('security.firewall.guard.'.$id, new ChildDefinition('security.firewall.guard'))
->replaceArgument(2, new Reference('security.firewall.guard.'.$id.'.locator'))
->setDefinition('security.firewall.authenticator.'.$id, new ChildDefinition('security.firewall.authenticator'))
->replaceArgument(2, new Reference('security.firewall.authenticator.'.$id.'.locator'))
->replaceArgument(3, $id)
->addTag('kernel.event_listener', ['event' => KernelEvents::REQUEST])
;

$listeners[] = new Reference('security.firewall.guard.'.$id);
$listeners[] = new Reference('security.firewall.authenticator.'.$id);
}

$config->replaceArgument(7, $configuredEntryPoint ?: $defaultEntryPoint);
Expand Down Expand Up @@ -502,12 +504,12 @@ private function createAuthenticationListeners(ContainerBuilder $container, stri
if (isset($firewall[$key])) {
$userProvider = $this->getUserProvider($container, $id, $firewall, $key, $defaultProvider, $providerIds, $contextListenerId);

if ($this->guardAuthenticationManagerEnabled) {
if (!$factory instanceof GuardFactoryInterface) {
throw new InvalidConfigurationException(sprintf('Cannot configure GuardAuthenticationManager as %s authentication does not support it, set security.guard_authentication_manager to `false`.', $key));
if ($this->authenticatorManagerEnabled) {
if (!$factory instanceof AuthenticatorFactoryInterface) {
throw new InvalidConfigurationException(sprintf('Cannot configure AuthenticatorManager as %s authentication does not support it, set security.enable_authenticator_manager to `false`.', $key));
}

$authenticationProviders[$id.'_'.$key] = $factory->createGuard($container, $id, $firewall[$key], $userProvider);
$authenticationProviders[$id.'_'.$key] = $factory->createAuthenticator($container, $id, $firewall[$key], $userProvider);
if ($factory instanceof EntrypointFactoryInterface) {
$defaultEntryPoint = $factory->createEntryPoint($container, $id, $firewall[$key], $defaultEntryPoint);
}
Expand Down
Expand Up @@ -16,32 +16,32 @@
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
use Symfony\Component\Security\Guard\GuardAuthenticatorHandler;
use Symfony\Component\Security\Http\Firewall\GuardManagerListener;
use Symfony\Component\Security\Http\Authentication\AuthenticatorHandler;
use Symfony\Component\Security\Http\Firewall\AuthenticatorManagerListener;

/**
* @author Wouter de Jong <wouter@wouterj.nl>
*
* @experimental in 5.1
*/
class LazyGuardManagerListener extends GuardManagerListener
class LazyAuthenticatorManagerListener extends AuthenticatorManagerListener
{
private $guardLocator;

public function __construct(
AuthenticationManagerInterface $authenticationManager,
GuardAuthenticatorHandler $guardHandler,
AuthenticatorHandler $authenticatorHandler,
ServiceLocator $guardLocator,
string $providerKey,
EventDispatcherInterface $eventDispatcher,
?LoggerInterface $logger = null
) {
parent::__construct($authenticationManager, $guardHandler, [], $providerKey, $eventDispatcher, $logger);
parent::__construct($authenticationManager, $authenticatorHandler, [], $providerKey, $eventDispatcher, $logger);

$this->guardLocator = $guardLocator;
}

protected function getSupportingGuardAuthenticators(Request $request): array
protected function getSupportingAuthenticators(Request $request): array
{
$guardAuthenticators = [];
foreach ($this->guardLocator->getProvidedServices() as $key => $type) {
Expand Down
Expand Up @@ -4,17 +4,28 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="security.firewall.guard.locator"
<service id="security.authenticator_handler"
class="Symfony\Component\Security\Http\Authentication\AuthenticatorHandler"
>
<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="security.firewall.authenticator.locator"
class="Symfony\Component\DependencyInjection\ServiceLocator"
abstract="true" />

<service id="security.firewall.guard"
class="Symfony\Bundle\SecurityBundle\EventListener\LazyGuardManagerListener"
<service id="security.firewall.authenticator"
class="Symfony\Bundle\SecurityBundle\EventListener\LazyAuthenticatorManagerListener"
abstract="true">
<tag name="monolog.logger" channel="security" />
<argument type="service" id="security.authentication.manager" />
<argument type="service" id="security.authentication.guard_handler" />
<argument/> <!-- guard authenticator locator -->
<argument type="service" id="security.authenticator_handler" />
<argument/> <!-- authenticator locator -->
<argument/> <!-- provider key -->
<argument type="service" id="event_dispatcher" />
<argument type="service" id="logger" on-invalid="null" />
Expand Down Expand Up @@ -48,7 +59,7 @@
<!-- Authenticators -->

<service id="security.authenticator.basic"
class="Symfony\Component\Security\Http\Authentication\Authenticator\HttpBasicAuthenticator"
class="Symfony\Component\Security\Http\Authenticator\HttpBasicAuthenticator"
abstract="true">
<argument/> <!-- realm name -->
<argument/> <!-- user provider -->
Expand All @@ -57,7 +68,7 @@
</service>

<service id="security.authenticator.form_login"
class="Symfony\Component\Security\Http\Authentication\Authenticator\FormLoginAuthenticator"
class="Symfony\Component\Security\Http\Authenticator\FormLoginAuthenticator"
abstract="true">
<argument type="service" id="security.http_utils" />
<argument /> <!-- csrf token generator -->
Expand All @@ -66,7 +77,7 @@
</service>

<service id="security.authenticator.anonymous"
class="Symfony\Component\Security\Http\Authentication\Authenticator\AnonymousAuthenticator"
class="Symfony\Component\Security\Http\Authenticator\AnonymousAuthenticator"
abstract="true">
<argument /> <!-- secret -->
<argument type="service" id="security.token_storage" />
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Bundle/SecurityBundle/Resources/config/guard.xml
Expand Up @@ -8,7 +8,7 @@
<defaults public="false" />

<service id="security.authentication.guard_handler"
class="Symfony\Component\Security\Guard\GuardAuthenticatorHandler"
class="Symfony\Component\Security\Guard\GuardHandler"
>
<argument type="service" id="security.token_storage" />
<argument type="service" id="event_dispatcher" on-invalid="null" />
Expand All @@ -17,8 +17,8 @@
<argument type="service" id="security.authentication.session_strategy" />
</call>
</service>
<service id="Symfony\Component\Security\Guard\GuardAuthenticatorHandler" alias="security.authentication.guard_handler" />

<service id="AuthenticatorHandler" alias="security.authentication.guard_handler" />

<!-- See GuardAuthenticationFactory -->
<service id="security.authentication.provider.guard"
Expand Down
Expand Up @@ -52,8 +52,8 @@
<argument type="service" id="event_dispatcher" />
</call>
</service>
<service id="security.authentication.manager.guard" class="Symfony\Component\Security\Http\Authentication\GuardAuthenticationManager">
<argument /> <!-- guard authenticators -->
<service id="security.authentication.manager.authenticator" class="Symfony\Component\Security\Http\Authentication\AuthenticatorManager">
<argument /> <!-- authenticators -->
<argument type="service" id="event_dispatcher" />
<argument>%security.authentication.manager.erase_credentials%</argument>
<call method="setEventDispatcher">
Expand Down

0 comments on commit 2b2d17f

Please sign in to comment.