-
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
Merged
Merged
Changes from 18 commits
Commits
Show all changes
41 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 d846a46
services.yaml: Format
adriendupuis c6ef3c5
user_authentication.md: closer to reality
adriendupuis 9db8d05
user_authentication.md: wording
adriendupuis daec0d1
deptrac.baseline.yaml: Ignore InteractiveLoginSubscriber Security\User
adriendupuis 4a37250
InteractiveLoginSubscriber: typehint
adriendupuis 5cae73e
Merge branch '5.0' into user_auth_5.0
adriendupuis fccf5cb
Apply suggestion from @konradoboza
adriendupuis 924405f
readability around instanceof test
adriendupuis 88a7d34
Use anonymous_user_id
adriendupuis 9b561aa
UserWrapped and more about example users
adriendupuis a6804bd
UserWrapped and more about example users
adriendupuis b420efb
UserWrapped and more about example users
adriendupuis 929ff6f
SecurityEvents::INTERACTIVE_LOGIN → AuthenticationTokenCreatedEvent
adriendupuis dd5fadd
Merge branch '5.0' into user_auth_5.0
adriendupuis 2aa888f
Merge branch 'user_auth_5.0' into user_auth_5.0-alt2
adriendupuis ef889f0
Fix deptrac
adriendupuis 02a1999
Fix deptrac
adriendupuis 203a5d4
Fix deptrac
adriendupuis 152729f
Fix deptrac
adriendupuis 4eed19b
Merge branch 'user_auth_5.0' into user_auth_5.0-alt2
adriendupuis d7de84e
Fix deptrac
adriendupuis 2e39549
Apply suggestion from @adriendupuis
adriendupuis f3f7786
AuthenticationTokenCreatedSubscriber: facto, clean-up
adriendupuis 32693c6
Apply suggestion from @adriendupuis
adriendupuis 1d35a77
AuthenticationTokenCreatedSubscriber: increase priority
adriendupuis 1f7e81c
user_authentication.md: about priority
adriendupuis 29f48b8
Merge branch '5.0' into user_auth_5.0
adriendupuis feec9ce
user_authentication.md month_change: true
adriendupuis 8bc4c2e
Merge branch '5.0' into user_auth_5.0
adriendupuis e05f9ea
Apply suggestions from code review
adriendupuis e3ca1de
Update docs/users/user_authentication.md
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
Some comments aren't visible on the classic Files Changed page.
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,6 @@ | ||
| services: | ||
| App\EventSubscriber\InteractiveLoginSubscriber: | ||
| arguments: | ||
| $userMap: | ||
| from_memory_user: customer | ||
| from_memory_admin: admin |
38 changes: 38 additions & 0 deletions
38
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,38 @@ | ||
| <?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; | ||
|
|
||
| final readonly 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) { | ||
| return; | ||
| } | ||
| $userLogin = $this->userMap[$event->getAuthenticationToken()->getUserIdentifier()] ?? 'anonymous'; | ||
| $ibexaUser = $this->userService->loadUserByLogin($userLogin); | ||
| $event->getAuthenticationToken()->setUser(new User($ibexaUser)); | ||
| } | ||
| } |
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
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.