User authentication¶
Authenticate user with multiple user providers¶
Symfony provides native support for multiple user providers. This makes it easier to integrate any kind of login handlers, including SSO and existing third party bundles (for example, FR3DLdapBundle, HWIOauthBundle, FOSUserBundle, or BeSimpleSsoAuthBundle).
However, to be able to use external user providers with Cohesivo, a valid Ibexa user needs to be injected into the repository. This is mainly for the kernel to be able to manage content-related permissions (but not limited to this).
Depending on your context, you either want to create and return an Ibexa user, or return an existing user, even a generic one.
Whenever a user is matched and authenticated, Symfony initiates an AuthenticationTokenCreatedEvent.
Every service listening to this event receives an object containing the original security token, which holds the matched user, and a passport.
Then, it's up to a listener to retrieve an Ibexa user from the repository.
This Ibexa user can be:
- embedded into
Ibexa\Core\MVC\Symfony\Security\Userwhile forgetting about the original user - wrapped into
Ibexa\Core\MVC\Symfony\Security\UserWrappedwith the original user if needed
Finally, the user is assigned back into the event's token for the rest of the process.
User mapping example¶
The following example uses the memory user provider, maps memory user to Ibexa repository user, and chains with the Ibexa user provider to be able to use both.
It's possible to customize the user class used by extending Ibexa\Core\MVC\Symfony\Security\EventListener\SecurityListener service, which defaults to Ibexa\Core\MVC\Symfony\Security\EventListener\SecurityListener.
You can override getUser() to return whatever user class you want, as long as it implements Ibexa\Core\MVC\Symfony\Security\UserInterface.
The following is an example of using the in-memory user provider:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |