-
Notifications
You must be signed in to change notification settings - Fork 81
Update "User authentication" customization example (5.0) #3087
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 5.0
Are you sure you want to change the base?
Changes from all commits
96a7f2f
f2d32a3
d6d7933
8e2f619
9f61b09
0e6a2a6
a1cb9a9
8b944e2
0e5516e
aab4c05
d846a46
c6ef3c5
9db8d05
daec0d1
4a37250
5cae73e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| security: | ||
| password_hashers: | ||
| # The in-memory provider requires an encoder | ||
| Symfony\Component\Security\Core\User\InMemoryUser: plaintext | ||
| Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto' | ||
|
|
||
| # https://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded | ||
| providers: | ||
| in_memory: | ||
| memory: | ||
| users: | ||
| from_memory_user: { password: from_memory_pass, roles: [ 'ROLE_USER' ] } | ||
| from_memory_admin: { password: from_memory_publish, roles: [ 'ROLE_USER' ] } | ||
| ibexa: | ||
| id: ibexa.security.user_provider | ||
| # Chaining in_memory and ibexa user providers | ||
| chained: | ||
| chain: | ||
| providers: [ in_memory, ibexa ] | ||
|
|
||
| firewalls: | ||
| # … | ||
| ibexa_front: | ||
| pattern: ^/ | ||
| provider: chained | ||
| user_checker: Ibexa\Core\MVC\Symfony\Security\UserChecker | ||
| context: ibexa | ||
| form_login: | ||
| enable_csrf: true | ||
| login_path: login | ||
| check_path: login_check | ||
| custom_authenticators: | ||
| - Ibexa\PageBuilder\Security\EditorialMode\FragmentAuthenticator | ||
| entry_point: form_login | ||
| logout: | ||
| path: logout |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| services: | ||
| App\EventSubscriber\InteractiveLoginSubscriber: | ||
| arguments: | ||
| $userMap: | ||
| from_memory_user: customer | ||
| from_memory_admin: admin |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,37 @@ | ||||||||||
| <?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(): array | ||||||||||
| { | ||||||||||
| return [ | ||||||||||
| SecurityEvents::INTERACTIVE_LOGIN => 'onInteractiveLogin', | ||||||||||
| ]; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public function onInteractiveLogin(InteractiveLoginEvent $event): void | ||||||||||
| { | ||||||||||
| $tokenUser = $event->getAuthenticationToken()->getUser(); | ||||||||||
| if ($tokenUser instanceof InMemoryUser) { | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| $userLogin = $this->userMap[$event->getAuthenticationToken()->getUserIdentifier()] ?? 'anonymous'; | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might also use the configured anonymous id for fetching user: |
||||||||||
| $ibexaUser = $this->userService->loadUserByLogin($userLogin); | ||||||||||
| $event->getAuthenticationToken()->setUser(new User($ibexaUser)); | ||||||||||
|
Comment on lines
+33
to
+34
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could use
Suggested change
See #3088 for complete integration of this idea. Pros:
Cons:
it's still out of |
||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.