Skip to content

SecurityEvents::INTERACTIVE_LOGIN → AuthenticationTokenCreatedEvent#3243

Merged
adriendupuis merged 10 commits into
user_auth_5.0from
user_auth_5.0-alt2
Jun 9, 2026
Merged

SecurityEvents::INTERACTIVE_LOGIN → AuthenticationTokenCreatedEvent#3243
adriendupuis merged 10 commits into
user_auth_5.0from
user_auth_5.0-alt2

Conversation

@adriendupuis

@adriendupuis adriendupuis commented Jun 8, 2026

Copy link
Copy Markdown
Contributor
Question Answer
JIRA Ticket
Versions
Edition

Related PR: #3087

Preview: https://ez-systems-developer-documentation--3243.com.readthedocs.build/en/3243/users/user_authentication/

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:

@adriendupuis adriendupuis marked this pull request as ready for review June 9, 2026 07:19
@adriendupuis adriendupuis requested a review from konradoboza June 9, 2026 07:19
Comment thread docs/users/user_authentication.md Outdated
Comment thread deptrac.baseline.yaml
}
//$event->getAuthenticationToken()->setUser(new User($ibexaUser));
$event->getAuthenticationToken()->setUser(new UserWrapped($tokenUser, $ibexaUser));
$token->setUser(new UserWrapped($tokenUser, $ibexaUser));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@konradoboza Did you mean something like this?:

Suggested change
$token->setUser(new UserWrapped($tokenUser, $ibexaUser));
$this->permissionResolver->setCurrentUserReference($ibexaUser);
$token->setUser(new UserWrapped($tokenUser, $ibexaUser));

(after injecting the PermissionResolver in constructor as well)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I am not sure about the priority. It would be good to check if this comes before OnAuthenticationTokenCreatedRepositoryUserSubscriber so setting the repository user isn't needed here as it will be done anyway.

@github-actions

github-actions Bot commented Jun 9, 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;
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⫶}
007⫶use Ibexa\Core\MVC\Symfony\Security\UserWrapped;
008⫶use Symfony\Component\EventDispatcher\EventSubscriberInterface;
009⫶use Symfony\Component\Security\Core\User\InMemoryUser;
010⫶use Symfony\Component\Security\Http\Event\AuthenticationTokenCreatedEvent;
011⫶
012⫶final readonly class AuthenticationTokenCreatedSubscriber implements EventSubscriberInterface
013⫶{
014⫶ /** @param array<string, string> $userMap */
015⫶ public function __construct(
016⫶ private readonly ConfigResolverInterface $configResolver,
017⫶ private readonly UserService $userService,
018⫶ private readonly array $userMap = [],
019⫶ ) {
020⫶ }
021⫶
022⫶ public static function getSubscribedEvents(): array
023⫶ {
024⫶ return [
025⫶ AuthenticationTokenCreatedEvent::class => ['onAuthenticationTokenCreated', 11],
026⫶ ];
027⫶ }
028⫶
029⫶ public function onAuthenticationTokenCreated(AuthenticationTokenCreatedEvent $event): void
030⫶ {
031⫶ $token = $event->getAuthenticatedToken();
032⫶ $tokenUser = $token->getUser();
033⫶ if (!$tokenUser instanceof InMemoryUser) {
034⫶ return;
035⫶ }
036⫶ $userIdentifier = $token->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⫶ $token->setUser(new UserWrapped($tokenUser, $ibexaUser));
046⫶ }
047⫶}


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


Download colorized diff

@adriendupuis adriendupuis merged commit 1f7e81c into user_auth_5.0 Jun 9, 2026
8 of 9 checks passed
@adriendupuis adriendupuis deleted the user_auth_5.0-alt2 branch June 9, 2026 08:40
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.

2 participants