Skip to content

SecurityEvents::INTERACTIVE_LOGIN → AuthenticationTokenCreatedEvent#3243

Draft
adriendupuis wants to merge 5 commits into
user_auth_5.0from
user_auth_5.0-alt2
Draft

SecurityEvents::INTERACTIVE_LOGIN → AuthenticationTokenCreatedEvent#3243
adriendupuis wants to merge 5 commits into
user_auth_5.0from
user_auth_5.0-alt2

Conversation

@adriendupuis

Copy link
Copy Markdown
Contributor
Question Answer
JIRA Ticket
Versions
Edition

Related PR: #3087

Checklist

  • Text renders correctly
  • Text has been checked with vale
  • Description metadata is up to date
  • Redirects cover removed/moved pages
  • Code samples are working
  • PHP code samples have been fixed with PHP CS fixer
  • Added link to this PR in relevant JIRA ticket or code PR

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

Preview of modified files

Preview of modified Markdown:

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

code_samples/ change report

Before (on target branch)After (in current PR)

code_samples/user_management/in_memory/config/services.yaml

docs/users/user_authentication.md@55:``` yaml
docs/users/user_authentication.md@56:[[= include_file('code_samples/user_management/in_memory/config/services.yaml') =]]
docs/users/user_authentication.md@57:```

001⫶services:

code_samples/user_management/in_memory/config/services.yaml

docs/users/user_authentication.md@55:``` yaml
docs/users/user_authentication.md@56:[[= include_file('code_samples/user_management/in_memory/config/services.yaml') =]]
docs/users/user_authentication.md@57:```

001⫶services:
002⫶    App\EventSubscriber\InteractiveLoginSubscriber:
002⫶    App\EventSubscriber\AuthenticationTokenCreatedSubscriber:
003⫶        arguments:
004⫶ $userMap:
005⫶ from_memory_user: generic_customer
006⫶ from_memory_admin: admin


code_samples/user_management/in_memory/src/EventSubscriber/AuthenticationTokenCreatedSubscriber.php

003⫶        arguments:
004⫶ $userMap:
005⫶ from_memory_user: generic_customer
006⫶ from_memory_admin: admin


code_samples/user_management/in_memory/src/EventSubscriber/AuthenticationTokenCreatedSubscriber.php


code_samples/user_management/in_memory/src/EventSubscriber/InteractiveLoginSubscriber.php

docs/users/user_authentication.md@38:``` php
docs/users/user_authentication.md@38:``` php
docs/users/user_authentication.md@39:[[= include_file('code_samples/user_management/in_memory/src/EventSubscriber/InteractiveLoginSubscriber.php') =]]
docs/users/user_authentication.md@39:[[= include_file('code_samples/user_management/in_memory/src/EventSubscriber/AuthenticationTokenCreatedSubscriber.php') =]]
docs/users/user_authentication.md@40:```

001⫶<?php declare(strict_types=1);
002⫶
003⫶namespace App\EventSubscriber;
004⫶
005⫶use Ibexa\Contracts\Core\Repository\UserService;
006⫶use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
007⫶//use Ibexa\Core\MVC\Symfony\Security\User;
008⫶use Ibexa\Core\MVC\Symfony\Security\UserWrapped;
009⫶use Symfony\Component\EventDispatcher\EventSubscriberInterface;
010⫶use Symfony\Component\Security\Core\User\InMemoryUser;
docs/users/user_authentication.md@40:```

001⫶<?php declare(strict_types=1);
002⫶
003⫶namespace App\EventSubscriber;
004⫶
005⫶use Ibexa\Contracts\Core\Repository\UserService;
006⫶use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
007⫶//use Ibexa\Core\MVC\Symfony\Security\User;
008⫶use Ibexa\Core\MVC\Symfony\Security\UserWrapped;
009⫶use Symfony\Component\EventDispatcher\EventSubscriberInterface;
010⫶use Symfony\Component\Security\Core\User\InMemoryUser;
011⫶use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
012⫶use Symfony\Component\Security\Http\SecurityEvents;
013⫶
014⫶final readonly class InteractiveLoginSubscriber implements EventSubscriberInterface
015⫶{
016⫶ /** @param array<string, string> $userMap */
017⫶ public function __construct(
018⫶ private readonly ConfigResolverInterface $configResolver,
019⫶ private readonly UserService $userService,
020⫶ private readonly array $userMap = [],
021⫶ ) {
022⫶ }
023⫶
024⫶ public static function getSubscribedEvents(): array
025⫶ {
026⫶ return [
027⫶ SecurityEvents::INTERACTIVE_LOGIN => 'onInteractiveLogin',
028⫶ ];
029⫶ }
030⫶
031⫶ public function onInteractiveLogin(InteractiveLoginEvent $event): void
032⫶ {
033⫶ $tokenUser = $event->getAuthenticationToken()->getUser();
034⫶ if (!$tokenUser instanceof InMemoryUser) {
035⫶ return;
036⫶ }
037⫶ $userIdentifier = $event->getAuthenticationToken()->getUserIdentifier();
038⫶ $ibexaUser = null;
039⫶ if (array_key_exists($userIdentifier, $this->userMap)) {
040⫶ $ibexaUser = $this->userService->loadUserByLogin($this->userMap[$userIdentifier]);
041⫶ }
042⫶ if (null === $ibexaUser) {
043⫶ $anonymousUserId = (int)$this->configResolver->getParameter('anonymous_user_id');
044⫶ $ibexaUser = $this->userService->loadUser($anonymousUserId);
045⫶ }
046⫶ //$event->getAuthenticationToken()->setUser(new User($ibexaUser));
047⫶ $event->getAuthenticationToken()->setUser(new UserWrapped($tokenUser, $ibexaUser));
048⫶ }
049⫶}
011⫶use Symfony\Component\Security\Http\Event\AuthenticationTokenCreatedEvent;
012⫶
013⫶final readonly class AuthenticationTokenCreatedSubscriber implements EventSubscriberInterface
014⫶{
015⫶ /** @param array<string, string> $userMap */
016⫶ public function __construct(
017⫶ private readonly ConfigResolverInterface $configResolver,
018⫶ private readonly UserService $userService,
019⫶ private readonly array $userMap = [],
020⫶ ) {
021⫶ }
022⫶
023⫶ public static function getSubscribedEvents(): array
024⫶ {
025⫶ return [
026⫶ AuthenticationTokenCreatedEvent::class => ['onAuthenticationTokenCreated', 10],
027⫶ ];
028⫶ }
029⫶
030⫶ public function onAuthenticationTokenCreated(AuthenticationTokenCreatedEvent $event): void
031⫶ {
032⫶ $tokenUser = $event->getAuthenticatedToken()->getUser();
033⫶ if (!$tokenUser instanceof InMemoryUser) {
034⫶ return;
035⫶ }
036⫶ $userIdentifier = $event->getAuthenticatedToken()->getUserIdentifier();
037⫶ $ibexaUser = null;
038⫶ if (array_key_exists($userIdentifier, $this->userMap)) {
039⫶ $ibexaUser = $this->userService->loadUserByLogin($this->userMap[$userIdentifier]);
040⫶ }
041⫶ if (null === $ibexaUser) {
042⫶ $anonymousUserId = (int)$this->configResolver->getParameter('anonymous_user_id');
043⫶ $ibexaUser = $this->userService->loadUser($anonymousUserId);
044⫶ }
045⫶ //$event->getAuthenticatedToken()->setUser(new User($ibexaUser));
046⫶ $event->getAuthenticatedToken()->setUser(new UserWrapped($tokenUser, $ibexaUser));
047⫶ }
048⫶}


code_samples/user_management/in_memory/src/EventSubscriber/InteractiveLoginSubscriber.php


Download colorized diff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant