Skip to content

Commit

Permalink
[Security] Fix resetting traceable listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
chalasr committed Oct 5, 2023
1 parent 8dc9fee commit 504e6ba
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 5 deletions.
Expand Up @@ -17,13 +17,14 @@
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\Security\Http\Authenticator\Debug\TraceableAuthenticatorManagerListener;
use Symfony\Component\Security\Http\Firewall\FirewallListenerInterface;
use Symfony\Contracts\Service\ResetInterface;

/**
* Firewall collecting called security listeners and authenticators.
*
* @author Robin Chalas <robin.chalas@gmail.com>
*/
final class TraceableFirewallListener extends FirewallListener
final class TraceableFirewallListener extends FirewallListener implements ResetInterface
{
private $wrappedListeners = [];
private $authenticatorsInfo = [];
Expand All @@ -38,6 +39,12 @@ public function getAuthenticatorsInfo(): array
return $this->authenticatorsInfo;
}

public function reset(): void
{
$this->wrappedListeners = [];
$this->authenticatorsInfo = [];
}

protected function callListeners(RequestEvent $event, iterable $listeners)
{
$wrappedListeners = [];
Expand Down
Expand Up @@ -544,6 +544,7 @@ private function createFirewall(ContainerBuilder $container, string $id, array $
->register('debug.security.firewall.authenticator.'.$id, TraceableAuthenticatorManagerListener::class)
->setDecoratedService('security.firewall.authenticator.'.$id)
->setArguments([new Reference('debug.security.firewall.authenticator.'.$id.'.inner')])
->addTag('kernel.reset', ['method' => 'reset'])
;
}

Expand Down
Expand Up @@ -36,6 +36,7 @@
service('security.logout_url_generator'),
])
->tag('kernel.event_subscriber')
->tag('kernel.reset', ['method' => 'reset'])
->alias('security.firewall', 'debug.security.firewall')
;
};
3 changes: 2 additions & 1 deletion src/Symfony/Bundle/SecurityBundle/composer.json
Expand Up @@ -26,10 +26,11 @@
"symfony/http-foundation": "^5.3|^6.0",
"symfony/password-hasher": "^5.3|^6.0",
"symfony/polyfill-php80": "^1.16",
"symfony/service-contracts": "^1.10|^2|^3",
"symfony/security-core": "^5.4|^6.0",
"symfony/security-csrf": "^4.4|^5.0|^6.0",
"symfony/security-guard": "^5.3",
"symfony/security-http": "^5.4.20|~6.0.20|~6.1.12|^6.2.6"
"symfony/security-http": "^5.4.30|~6.0.20|~6.1.12|^6.2.6|^6.3.6"
},
"require-dev": {
"doctrine/annotations": "^1.10.4|^2",
Expand Down
Expand Up @@ -16,13 +16,14 @@
use Symfony\Component\Security\Http\Firewall\AbstractListener;
use Symfony\Component\Security\Http\Firewall\AuthenticatorManagerListener;
use Symfony\Component\VarDumper\Caster\ClassStub;
use Symfony\Contracts\Service\ResetInterface;

/**
* Decorates the AuthenticatorManagerListener to collect information about security authenticators.
*
* @author Robin Chalas <robin.chalas@gmail.com>
*/
final class TraceableAuthenticatorManagerListener extends AbstractListener
final class TraceableAuthenticatorManagerListener extends AbstractListener implements ResetInterface
{
private $authenticationManagerListener;
private $authenticatorsInfo = [];
Expand Down Expand Up @@ -78,4 +79,9 @@ public function getAuthenticatorsInfo(): array
{
return $this->authenticatorsInfo;
}

public function reset(): void
{
$this->authenticatorsInfo = [];
}
}
5 changes: 3 additions & 2 deletions src/Symfony/Component/Security/Http/composer.json
Expand Up @@ -18,12 +18,13 @@
"require": {
"php": ">=7.2.5",
"symfony/deprecation-contracts": "^2.1|^3",
"symfony/security-core": "^5.4.19|~6.0.19|~6.1.11|^6.2.5",
"symfony/http-foundation": "^5.3|^6.0",
"symfony/http-kernel": "^5.3|^6.0",
"symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php80": "^1.16",
"symfony/property-access": "^4.4|^5.0|^6.0"
"symfony/property-access": "^4.4|^5.0|^6.0",
"symfony/service-contracts": "^1.10|^2|^3",
"symfony/security-core": "^5.4.19|~6.0.19|~6.1.11|^6.2.5"
},
"require-dev": {
"symfony/cache": "^4.4|^5.0|^6.0",
Expand Down

0 comments on commit 504e6ba

Please sign in to comment.