-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathInteractiveLoginSubscriber.php
More file actions
39 lines (33 loc) · 1.3 KB
/
InteractiveLoginSubscriber.php
File metadata and controls
39 lines (33 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php declare(strict_types=1);
namespace App\EventSubscriber;
use Ibexa\Contracts\Core\Repository\UserService;
use Ibexa\Core\MVC\Symfony\Security\User;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\User\InMemoryUser;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Symfony\Component\Security\Http\SecurityEvents;
class InteractiveLoginSubscriber implements EventSubscriberInterface
{
/** @param array<string, string> $userMap */
public function __construct(
private readonly UserService $userService,
private readonly array $userMap = [],
) {
}
public static function getSubscribedEvents()
{
return [
SecurityEvents::INTERACTIVE_LOGIN => 'onInteractiveLogin',
];
}
public function onInteractiveLogin(InteractiveLoginEvent $event): InteractiveLoginEvent
{
$tokenUser = $event->getAuthenticationToken()->getUser();
if ($tokenUser instanceof InMemoryUser) {
$userLogin = $this->userMap[$event->getAuthenticationToken()->getUserIdentifier()] ?? 'anonymous';
$ibexaUser = $this->userService->loadUserByLogin($userLogin);
$event->getAuthenticationToken()->setUser(new User($ibexaUser));
}
return $event;
}
}