Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
services:
App\EventSubscriber\AuthenticationTokenCreatedSubscriber:
arguments:
$userProvider: '@ibexa.security.user_provider.username'
Comment thread
adriendupuis marked this conversation as resolved.
$userMap:
from_memory_user: generic_customer
from_memory_admin: admin
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@
use Ibexa\Core\MVC\Symfony\Security\UserWrapped;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\User\InMemoryUser;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Http\Event\AuthenticationTokenCreatedEvent;

final readonly class AuthenticationTokenCreatedSubscriber implements EventSubscriberInterface
{
/** @param array<string, string> $userMap */
/**
* @param array<string, string> $userMap
*
* @phpstan-param UserProviderInterface<\Ibexa\Core\MVC\Symfony\Security\UserInterface> $userProvider
*/
public function __construct(
private readonly ConfigResolverInterface $configResolver,
private readonly UserService $userService,
private readonly UserProviderInterface $userProvider,
private readonly array $userMap = [],
) {
}
Expand All @@ -36,12 +42,12 @@
$userIdentifier = $token->getUserIdentifier();
$ibexaUser = null;
if (array_key_exists($userIdentifier, $this->userMap)) {
$ibexaUser = $this->userService->loadUserByLogin($this->userMap[$userIdentifier]);
$ibexaUser = $this->userProvider->loadUserByIdentifier($userIdentifier);
}
if (null === $ibexaUser) {
$anonymousUserId = (int)$this->configResolver->getParameter('anonymous_user_id');
$ibexaUser = $this->userService->loadUser($anonymousUserId);
}
$token->setUser(new UserWrapped($tokenUser, $ibexaUser));

Check failure on line 51 in code_samples/user_management/in_memory/src/EventSubscriber/AuthenticationTokenCreatedSubscriber.php

View workflow job for this annotation

GitHub Actions / Validate code samples (8.3)

Parameter #2 $apiUser of class Ibexa\Core\MVC\Symfony\Security\UserWrapped constructor expects Ibexa\Contracts\Core\Repository\Values\User\User, Ibexa\Contracts\Core\Repository\Values\User\User|Ibexa\Core\MVC\Symfony\Security\UserInterface given.

Check failure on line 51 in code_samples/user_management/in_memory/src/EventSubscriber/AuthenticationTokenCreatedSubscriber.php

View workflow job for this annotation

GitHub Actions / Validate code samples (8.4)

Parameter #2 $apiUser of class Ibexa\Core\MVC\Symfony\Security\UserWrapped constructor expects Ibexa\Contracts\Core\Repository\Values\User\User, Ibexa\Contracts\Core\Repository\Values\User\User|Ibexa\Core\MVC\Symfony\Security\UserInterface given.
}
}
5 changes: 3 additions & 2 deletions docs/users/user_authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
maps memory user to Ibexa repository user,
and [chains]([[= symfony_doc =]]/security/user_providers.html#chain-user-provider) with the Ibexa user provider to be able to use both:

Create as `src/EventSubscriber/AuthenticationTokenCreatedSubscriber.php` subscribing to the `AuthenticationTokenCreatedEvent` event
and mapping when needed an in-memory authenticated user to an Ibexa user:
Create as `src/EventSubscriber/AuthenticationTokenCreatedSubscriber.php` subscribing to the `AuthenticationTokenCreatedEvent` event,
mapping when needed an in-memory authenticated user to an Ibexa user,

Check failure on line 36 in docs/users/user_authentication.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/users/user_authentication.md#L36

[Ibexa.VariablesGlobal] Use global variable '[[= product_name_base =]]' instead of 'Ibexa'
Raw output
{"message": "[Ibexa.VariablesGlobal] Use global variable '[[= product_name_base =]]' instead of 'Ibexa'", "location": {"path": "docs/users/user_authentication.md", "range": {"start": {"line": 36, "column": 59}}}, "severity": "ERROR"}
and using the Ibexa `UsernameProvider` implementation of `UserProviderInterface::loadUserByIdentifier()` to have a repository user wrapped into a security user:

Check notice on line 37 in docs/users/user_authentication.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/users/user_authentication.md#L37

[Ibexa.ByUsing] Prefer 'by using' or 'with' to plain 'using'.
Raw output
{"message": "[Ibexa.ByUsing] Prefer 'by using' or 'with' to plain 'using'.", "location": {"path": "docs/users/user_authentication.md", "range": {"start": {"line": 37, "column": 1}}}, "severity": "INFO"}

``` php
[[= include_file('code_samples/user_management/in_memory/src/EventSubscriber/AuthenticationTokenCreatedSubscriber.php') =]]
Expand Down
Loading