17
17
use Symfony \Component \Security \Core \Exception \AuthenticationException ;
18
18
use Symfony \Component \Security \Http \Authenticator \AuthenticatorInterface ;
19
19
use Symfony \Component \Security \Http \Authenticator \InteractiveAuthenticatorInterface ;
20
+ use Symfony \Component \Security \Http \Authenticator \Passport \Badge \BadgeInterface ;
20
21
use Symfony \Component \Security \Http \Authenticator \Passport \Passport ;
21
22
use Symfony \Component \Security \Http \EntryPoint \AuthenticationEntryPointInterface ;
22
23
use Symfony \Component \Security \Http \EntryPoint \Exception \NotAnEntryPointException ;
29
30
*/
30
31
final class TraceableAuthenticator implements AuthenticatorInterface, InteractiveAuthenticatorInterface, AuthenticationEntryPointInterface
31
32
{
32
- private AuthenticatorInterface $ authenticator ;
33
33
private ?Passport $ passport = null ;
34
34
private ?float $ duration = null ;
35
35
private ClassStub |string $ stub ;
36
+ private ?bool $ authenticated = null ;
36
37
37
- public function __construct (AuthenticatorInterface $ authenticator )
38
+ public function __construct (private AuthenticatorInterface $ authenticator )
38
39
{
39
- $ this ->authenticator = $ authenticator ;
40
40
}
41
41
42
42
public function getInfo (): array
@@ -46,6 +46,16 @@ public function getInfo(): array
46
46
'passport ' => $ this ->passport ,
47
47
'duration ' => $ this ->duration ,
48
48
'stub ' => $ this ->stub ??= class_exists (ClassStub::class) ? new ClassStub ($ this ->authenticator ::class) : $ this ->authenticator ::class,
49
+ 'authenticated ' => $ this ->authenticated ,
50
+ 'badges ' => array_map (
51
+ static function (BadgeInterface $ badge ): array {
52
+ return [
53
+ 'stub ' => class_exists (ClassStub::class) ? new ClassStub ($ badge ::class) : $ badge ::class,
54
+ 'resolved ' => $ badge ->isResolved (),
55
+ ];
56
+ },
57
+ $ this ->passport ->getBadges (),
58
+ ),
49
59
];
50
60
}
51
61
@@ -70,11 +80,15 @@ public function createToken(Passport $passport, string $firewallName): TokenInte
70
80
71
81
public function onAuthenticationSuccess (Request $ request , TokenInterface $ token , string $ firewallName ): ?Response
72
82
{
83
+ $ this ->authenticated = true ;
84
+
73
85
return $ this ->authenticator ->onAuthenticationSuccess ($ request , $ token , $ firewallName );
74
86
}
75
87
76
88
public function onAuthenticationFailure (Request $ request , AuthenticationException $ exception ): ?Response
77
89
{
90
+ $ this ->authenticated = false ;
91
+
78
92
return $ this ->authenticator ->onAuthenticationFailure ($ request , $ exception );
79
93
}
80
94
0 commit comments