|
13 | 13 |
|
14 | 14 | use Symfony\Bundle\SecurityBundle\Debug\TraceableFirewallListener;
|
15 | 15 | use Symfony\Bundle\SecurityBundle\Security\FirewallMap;
|
| 16 | +use Symfony\Component\HttpFoundation\Cookie; |
16 | 17 | use Symfony\Component\HttpFoundation\Request;
|
17 | 18 | use Symfony\Component\HttpFoundation\Response;
|
18 | 19 | use Symfony\Component\HttpKernel\DataCollector\DataCollector;
|
@@ -195,6 +196,27 @@ public function collect(Request $request, Response $response, ?\Throwable $excep
|
195 | 196 | }
|
196 | 197 |
|
197 | 198 | $this->data['authenticators'] = $this->firewall ? $this->firewall->getAuthenticatorsInfo() : [];
|
| 199 | + |
| 200 | + if ($this->data['listeners'] && !($this->data['firewall']['stateless'] ?? true)) { |
| 201 | + $authCookieName = "{$this->data['firewall']['name']}_auth_profile_token"; |
| 202 | + $deauthCookieName = "{$this->data['firewall']['name']}_deauth_profile_token"; |
| 203 | + $profileToken = $response->headers->get('X-Debug-Token'); |
| 204 | + |
| 205 | + $this->data['auth_profile_token'] = $request->cookies->get($authCookieName); |
| 206 | + $this->data['deauth_profile_token'] = $request->cookies->get($deauthCookieName); |
| 207 | + |
| 208 | + if ($this->data['authenticated'] && !$this->data['auth_profile_token']) { |
| 209 | + $response->headers->setCookie(new Cookie($authCookieName, $profileToken)); |
| 210 | + |
| 211 | + $this->data['deauth_profile_token'] = null; |
| 212 | + $response->headers->clearCookie($deauthCookieName); |
| 213 | + } elseif(!$this->data['authenticated'] && !$this->data['deauth_profile_token']) { |
| 214 | + $response->headers->setCookie(new Cookie($deauthCookieName, $profileToken)); |
| 215 | + |
| 216 | + $this->data['auth_profile_token'] = null; |
| 217 | + $response->headers->clearCookie($authCookieName); |
| 218 | + } |
| 219 | + } |
198 | 220 | }
|
199 | 221 |
|
200 | 222 | public function reset(): void
|
@@ -339,6 +361,16 @@ public function getAuthenticators(): array|Data
|
339 | 361 | return $this->data['authenticators'];
|
340 | 362 | }
|
341 | 363 |
|
| 364 | + public function getAuthProfileToken(): string|Data|null |
| 365 | + { |
| 366 | + return $this->data['auth_profile_token'] ?? null; |
| 367 | + } |
| 368 | + |
| 369 | + public function getDeauthProfileToken(): string|Data|null |
| 370 | + { |
| 371 | + return $this->data['deauth_profile_token'] ?? null; |
| 372 | + } |
| 373 | + |
342 | 374 | public function getName(): string
|
343 | 375 | {
|
344 | 376 | return 'security';
|
|
0 commit comments