Skip to content

Commit

Permalink
[Security] Make impersonation_path() argument mandatory and add `im…
Browse files Browse the repository at this point in the history
…personation_url()`
  • Loading branch information
alexandre-daubois committed Oct 2, 2023
1 parent 19f0093 commit 5d71d95
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Symfony/Bridge/Twig/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CHANGELOG
* Allow an array to be passed as the first argument to the `importmap()` Twig function
* Add `TemplatedEmail::locale()` to set the locale for the email rendering
* Add `AppVariable::getEnabledLocales()` to retrieve the enabled locales
* Add `impersonation_path()` and `impersonation_url()` Twig functions

6.3
---
Expand Down
12 changes: 11 additions & 1 deletion src/Symfony/Bridge/Twig/Extension/SecurityExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,16 @@ public function getImpersonateExitPath(string $exitTo = null): string
return $this->impersonateUrlGenerator->generateExitPath($exitTo);
}

public function getImpersonatePath(string $identifier = null): string
public function getImpersonateUrl(string $identifier): string
{
if (null === $this->impersonateUrlGenerator) {
return '';
}

return $this->impersonateUrlGenerator->generateImpersonationUrl($identifier);
}

public function getImpersonatePath(string $identifier): string
{
if (null === $this->impersonateUrlGenerator) {
return '';
Expand All @@ -84,6 +93,7 @@ public function getFunctions(): array
new TwigFunction('is_granted', $this->isGranted(...)),
new TwigFunction('impersonation_exit_url', $this->getImpersonateExitUrl(...)),
new TwigFunction('impersonation_exit_path', $this->getImpersonateExitPath(...)),
new TwigFunction('impersonation_url', $this->getImpersonateUrl(...)),
new TwigFunction('impersonation_path', $this->getImpersonatePath(...)),
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,20 @@ public function __construct(RequestStack $requestStack, FirewallMap $firewallMap
$this->firewallMap = $firewallMap;
}

public function generateImpersonationPath(string $identifier = null): string
public function generateImpersonationPath(string $identifier): string
{
return $this->buildPath(null, $identifier);
}

public function generateImpersonationUrl(string $identifier): string
{
if (null === $request = $this->requestStack->getCurrentRequest()) {
return '';
}

return $request->getUriForPath($this->buildPath(null, $identifier));
}

public function generateExitPath(string $targetUri = null): string
{
return $this->buildPath($targetUri);
Expand Down

0 comments on commit 5d71d95

Please sign in to comment.