Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This replaces all individual authentication listeners when guard authentication manager is enabled.
- Loading branch information
Showing
6 changed files
with
314 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/Symfony/Bundle/SecurityBundle/EventListener/LazyGuardManagerListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?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\Bundle\SecurityBundle\EventListener; | ||
|
||
use Psr\Log\LoggerInterface; | ||
use Symfony\Component\DependencyInjection\ServiceLocator; | ||
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; | ||
|
||
/** | ||
* @author Wouter de Jong <wouter@wouterj.nl> | ||
*/ | ||
class LazyGuardManagerListener extends GuardManagerListener | ||
{ | ||
private $guardLocator; | ||
|
||
public function __construct( | ||
AuthenticationManagerInterface $authenticationManager, | ||
GuardAuthenticatorHandler $guardHandler, | ||
ServiceLocator $guardLocator, | ||
string $providerKey, | ||
?LoggerInterface $logger = null | ||
) { | ||
parent::__construct($authenticationManager, $guardHandler, [], $providerKey, $logger); | ||
|
||
$this->guardLocator = $guardLocator; | ||
} | ||
|
||
protected function getSupportingGuardAuthenticators(Request $request): array | ||
{ | ||
$guardAuthenticators = []; | ||
foreach ($this->guardLocator->getProvidedServices() as $key => $type) { | ||
$guardAuthenticator = $this->guardLocator->get($key); | ||
if (null !== $this->logger) { | ||
$this->logger->debug('Checking support on guard authenticator.', ['firewall_key' => $this->providerKey, 'authenticator' => \get_class($guardAuthenticator)]); | ||
} | ||
|
||
if ($guardAuthenticator->supports($request)) { | ||
$guardAuthenticators[$key] = $guardAuthenticator; | ||
} elseif (null !== $this->logger) { | ||
$this->logger->debug('Guard authenticator does not support the request.', ['firewall_key' => $this->providerKey, 'authenticator' => \get_class($guardAuthenticator)]); | ||
} | ||
} | ||
|
||
return $guardAuthenticators; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.