-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the new actor provider interface
- Loading branch information
Showing
8 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ | |
* Sets the username from the security context by listening on kernel.request | ||
* | ||
* @author David Buchmann <[email protected]> | ||
* | ||
* @deprecated to be removed in 2.0, use the actor provider instead | ||
*/ | ||
class BlameListener implements EventSubscriberInterface | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
* | ||
* @author Christophe Coevoet <[email protected]> | ||
* | ||
* @deprecated to be removed in 2.0, use the actor provider instead | ||
* | ||
* @phpstan-template T of Loggable|object | ||
*/ | ||
class LoggerListener implements EventSubscriberInterface | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<services> | ||
<service id="stof_doctrine_extensions.tool.actor_provider" class="Stof\DoctrineExtensionsBundle\Tool\TokenStorageActorProvider" public="false"> | ||
<argument type="service" id="security.token_storage" on-invalid="null" /> | ||
<argument type="service" id="security.authorization_checker" on-invalid="null" /> | ||
</service> | ||
</services> | ||
</container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Stof\DoctrineExtensionsBundle\Tool; | ||
|
||
use Gedmo\Tool\ActorProviderInterface; | ||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; | ||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; | ||
use Symfony\Component\Security\Core\User\UserInterface; | ||
|
||
/** | ||
* Provides an actor for the extensions using the token storage. | ||
* | ||
* @internal | ||
*/ | ||
final class TokenStorageActorProvider implements ActorProviderInterface | ||
{ | ||
private ?TokenStorageInterface $tokenStorage; | ||
private ?AuthorizationCheckerInterface $authorizationChecker; | ||
|
||
public function __construct(?TokenStorageInterface $tokenStorage = null, ?AuthorizationCheckerInterface $authorizationChecker = null) | ||
{ | ||
$this->tokenStorage = $tokenStorage; | ||
$this->authorizationChecker = $authorizationChecker; | ||
} | ||
|
||
public function getActor(): ?UserInterface | ||
{ | ||
if (null === $this->tokenStorage || null === $this->authorizationChecker) { | ||
return null; | ||
} | ||
|
||
$token = $this->tokenStorage->getToken(); | ||
|
||
if (null === $token || !$this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) { | ||
return null; | ||
} | ||
|
||
return $token->getUser(); | ||
} | ||
} |