-
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
Open
adriendupuis
wants to merge
10
commits into
5.0
Choose a base branch
from
user_auth_5.0
base: 5.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+102
−83
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
96a7f2f
user_authentication.md: fixes, encoders → password_hashers
adriendupuis f2d32a3
user_authentication.md: fix subscriber
adriendupuis d6d7933
user_authentication.md: move code to external files
adriendupuis 8e2f619
user_authentication.md: start to update explanations
adriendupuis 9f61b09
InteractiveLoginSubscriber::onInteractiveLogin() return type
adriendupuis 0e6a2a6
PHP & JS CS Fixes
adriendupuis a1cb9a9
user_authentication.md: Rewrite example description
adriendupuis 8b944e2
PHP & JS CS Fixes
adriendupuis 0e5516e
InteractiveLoginSubscriber: Fix missingType.iterableValue
adriendupuis aab4c05
InteractiveLoginSubscriber: No need to return the event
adriendupuis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
code_samples/user_management/in_memory/config/packages/security.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| App\EventSubscriber\InteractiveLoginSubscriber: | ||
| arguments: | ||
| $userMap: | ||
| from_memory_user: customer | ||
| from_memory_admin: admin |
37 changes: 37 additions & 0 deletions
37
code_samples/user_management/in_memory/src/EventSubscriber/InteractiveLoginSubscriber.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | ||
| { | ||
| return [ | ||
| SecurityEvents::INTERACTIVE_LOGIN => 'onInteractiveLogin', | ||
| ]; | ||
| } | ||
|
|
||
| public function onInteractiveLogin(InteractiveLoginEvent $event): void | ||
| { | ||
| $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)); | ||
|
Check failure on line 34 in code_samples/user_management/in_memory/src/EventSubscriber/InteractiveLoginSubscriber.php
|
||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
I could use
Ibexa\Core\MVC\Symfony\Security\User\UsernameProvider::loadUserByIdentifier()to get the repo user already wrapped:but it's still out of
Contractsnamespace.