-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added listener setting current repository user for all security-relat…
…ed processes
- Loading branch information
1 parent
6572a91
commit fe9da7e
Showing
4 changed files
with
43 additions
and
25 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
39 changes: 39 additions & 0 deletions
39
...y/Authentication/EventSubscriber/OnAuthenticationTokenCreatedRepositoryUserSubscriber.php
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,39 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Core\MVC\Symfony\Security\Authentication\EventSubscriber; | ||
|
||
use Ibexa\Contracts\Core\Repository\PermissionResolver; | ||
use Ibexa\Core\MVC\Symfony\Security\UserInterface as IbexaUser; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\Security\Http\Event\AuthenticationTokenCreatedEvent; | ||
|
||
final readonly class OnAuthenticationTokenCreatedRepositoryUserSubscriber implements EventSubscriberInterface | ||
{ | ||
public function __construct( | ||
private PermissionResolver $permissionResolver, | ||
) { | ||
} | ||
|
||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
AuthenticationTokenCreatedEvent::class => ['onAuthenticationTokenCreated', 10], | ||
]; | ||
} | ||
|
||
public function onAuthenticationTokenCreated(AuthenticationTokenCreatedEvent $event): void | ||
{ | ||
$user = $event->getAuthenticatedToken()->getUser(); | ||
if (!$user instanceof IbexaUser) { | ||
return; | ||
} | ||
|
||
$this->permissionResolver->setCurrentUserReference($user->getAPIUser()); | ||
} | ||
} |