8000 minor #43401 [Security] Move `TraceableAuthenticator` to `security-ht… · symfony/symfony@2c51cfc · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c51cfc

Browse files
committed
minor #43401 [Security] Move TraceableAuthenticator to security-http (chalasr)
This PR was merged into the 5.4 branch. Discussion ---------- [Security] Move `TraceableAuthenticator` to `security-http` | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Necessary to fix tests on branch 6.0 https://github.com/symfony/symfony/runs/3861906767. There is an incompatible signature for `AuthenticatorInterface::createAuthenticatedToken()` between security-bundle 6.0 and security-http 5.4 because of the deprecated `PassportInterface` type. Moving `TraceableAuthenticator` and `TraceableAuthenticatorManagerListener` to `security-http` fixes the issue and it's looking good to me. Commits ------- 876222f [Security] Move TraceableAuthenticator to security-http
2 parents 9b2e551 + 876222f commit 2c51cfc

File tree

7 files changed

+54
-13
lines changed

7 files changed

+54
-13
lines changed

src/Symfony/Bundle/SecurityBundle/Debug/TraceableFirewallListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
namespace Symfony\Bundle\SecurityBundle\Debug;
1313

14-
use Symfony\Bundle\SecurityBundle\Debug\Authenticator\TraceableAuthenticatorManagerListener;
1514
use Symfony\Bundle\SecurityBundle\EventListener\FirewallListener;
1615
use Symfony\Bundle\SecurityBundle\Security\FirewallContext;
1716
use Symfony\Bundle\SecurityBundle\Security\LazyFirewallContext;
1817
use Symfony\Component\HttpKernel\Event\RequestEvent;
18+
use Symfony\Component\Security\Http\Authenticator\Debug\TraceableAuthenticatorManagerListener;
1919
use Symfony\Component\Security\Http\Firewall\FirewallListenerInterface;
2020

2121
/**

src/Symfony/Bundle/SecurityBundle/Debug/TraceableListenerTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Bundle\SecurityBundle\Debug;
1313

14-
use Symfony\Bundle\SecurityBundle\Debug\Authenticator\TraceableAuthenticatorManagerListener;
14+
use Symfony\Component\Security\Http\Authenticator\Debug\TraceableAuthenticatorManagerListener;
1515
use Symfony\Component\VarDumper\Caster\ClassStub;
1616

1717
/**

src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Bundle\SecurityBundle\DependencyInjection;
1313

1414
use Symfony\Bridge\Twig\Extension\LogoutUrlExtension;
15-
use Symfony\Bundle\SecurityBundle\Debug\Authenticator\TraceableAuthenticatorManagerListener;
1615
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface;
1716
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\FirewallListenerFactoryInterface;
1817
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
@@ -45,6 +44,7 @@
4544
use Symfony\Component\Security\Core\User\ChainUserProvider;
4645
use Symfony\Component\Security\Core\ 8000 User\PasswordAuthenticatedUserInterface;
4746
use Symfony\Component\Security\Core\User\UserProviderInterface;
47+
use Symfony\Component\Security\Http\Authenticator\Debug\TraceableAuthenticatorManagerListener;
4848
use Symfony\Component\Security\Http\Event\CheckPassportEvent;
4949

5050
/**

src/Symfony/Bundle/SecurityBundle/Tests/Debug/TraceableFirewallListenerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Bundle\SecurityBundle\Tests\Debug;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Bundle\SecurityBundle\Debug\Authenticator\TraceableAuthenticatorManagerListener;
1615
use Symfony\Bundle\SecurityBundle\Debug\TraceableFirewallListener;
1716
use Symfony\Bundle\SecurityBundle\Security\FirewallMap;
1817
use Symfony\Component\EventDispatcher\EventDispatcher;
@@ -23,6 +22,7 @@
2322
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
2423
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
2524
use Symfony\Component\Security\Http\Authentication\AuthenticatorManager;
25+
use Symfony\Component\Security\Http\Authenticator\Debug\TraceableAuthenticatorManagerListener;
2626
use Symfony\Component\Security\Http\Authenticator\InteractiveAuthenticatorInterface;
2727
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
2828
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;

src/Symfony/Bundle/SecurityBundle/Debug/Authenticator/TraceableAuthenticator.php renamed to src/Symfony/Component/Security/Http/Authenticator/Debug/TraceableAuthenticator.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Bundle\SecurityBundle\Debug\Authenticator;
12+
namespace Symfony\Component\Security\Http\Authenticator\Debug;
1313

1414
use Symfony\Component\HttpFoundation\Request;
1515
use Symfony\Component\HttpFoundation\Response;
@@ -25,9 +25,9 @@
2525
use Symfony\Component\VarDumper\Caster\ClassStub;
2626

2727
/**
28-
* @author Robin Chalas <robin.chalas@gmail.com>
28+
* Collects info about an authenticator for debugging purposes.
2929
*
30-
* @internal
30+
* @author Robin Chalas <robin.chalas@gmail.com>
3131
*/
3232
final class TraceableAuthenticator implements AuthenticatorInterface, InteractiveAuthenticatorInterface, AuthenticationEntryPointInterface
3333
{
@@ -43,11 +43,13 @@ public function __construct(AuthenticatorInterface $authenticator)
4343

4444
public function getInfo(): array
4545
{
46+
$class = \get_class($this->authenticator instanceof GuardBridgeAuthenticator ? $this->authenticator->getGuardAuthenticator() : $this->authenticator);
47+
4648
return [
4749
'supports' => true,
4850
'passport' => $this->passport,
4951
'duration' => $this->duration,
50-
'stub' => $this->stub ?? $this->stub = new ClassStub(\get_class($this->authenticator instanceof GuardBridgeAuthenticator ? $this->authenticator->getGuardAuthenticator() : $this->authenticator)),
52+
'stub' => $this->stub ?? $this->stub = class_exists(ClassStub::class) ? new ClassStub($class) : $class,
5153
];
5254
}
5355

src/Symfony/Bundle/SecurityBundle/Debug/Authenticator/TraceableAuthenticatorManagerListener.php renamed to src/Symfony/Component/Security/Http/Authenticator/Debug/TraceableAuthenticatorManagerListener.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Bundle\SecurityBundle\Debug\Authenticator;
12+
namespace Symfony\Component\Security\Http\Authenticator\Debug;
1313

1414
use Symfony\Component\HttpFoundation\Request;
1515
use Symfony\Component\HttpKernel\Event\RequestEvent;
@@ -21,17 +21,17 @@
2121
* Decorates the AuthenticatorManagerListener to collect information about security authenticators.
2222
*
2323
* @author Robin Chalas <robin.chalas@gmail.com>
24-
*
25-
* @internal
2624
*/
27-
class TraceableAuthenticatorManagerListener extends AbstractListener
25+
final class TraceableAuthenticatorManagerListener extends AbstractListener
2826
{
2927
private $authenticationManagerListener;
3028
private $authenticatorsInfo = [];
29+
private $hasVardumper;
3130

3231
public function __construct(AuthenticatorManagerListener $authenticationManagerListener)
3332
{
3433
$this->authenticationManagerListener = $authenticationManagerListener;
34+
$this->hasVardumper = class_exists(ClassStub::class);
3535
}
3636

3737
public function supports(Request $request): ?bool
@@ -50,7 +50,7 @@ public function authenticate(RequestEvent $event): void
5050
foreach ($request->attributes->get('_security_skipped_authenticators') as $skippedAuthenticator) {
5151
$this->authenticatorsInfo[] = [
5252
'supports' => false,
53-
'stub' => new ClassStub(\get_class($skippedAuthenticator)),
53+
'stub' => $this->hasVardumper ? new ClassStub(\get_class($skippedAuthenticator)) : \get_class($skippedAuthenticator),
5454
'passport' => null,
5555
'duration' => 0,
5656
];
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Security\Http\Tests\Authenticator\Debug;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\HttpFoundation\Request;
16+
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
17+
use Symfony\Component\Security\Http\Authenticator\Debug\TraceableAuthenticator;
18+
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
19+
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;
20+
21+
class TraceableAuthenticatorTest extends TestCase
22+
{
23+
public function testGetInfo()
24+
{
25+
$request = new Request();
26+
$passport = new SelfValidatingPassport(new UserBadge('robin', function () {}));
27+
28+
$authenticator = $this->createMock(AuthenticatorInterface::class);
29+
$authenticator
30+
->expects($this->once())
31+
->method('authenticate')
32+
->with($request)
33+
->willReturn($passport);
34+
35+
$traceable = new TraceableAuthenticator($authenticator);
36+
$this->assertSame($passport, $traceable->authenticate($request));
37+
$this->assertSame($passport, $traceable->getInfo()['passport']);
38+
}
39+
}
31EB

0 commit comments

Comments
 (0)
0