Authenticating user with multiple user providers¶
Symfony provides native support for multiple user providers. This makes it easy to integrate any kind of login handlers, including SSO and existing third party bundles (e.g. FR3DLdapBundle, HWIOauthBundle, FOSUserBundle, BeSimpleSsoAuthBundle, etc.).
However, to be able to use external user providers with eZ Platform, a valid Platform 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 will either want to create a Platform user, return an existing user, or even always use a generic user.
Whenever an external user is matched (i.e. one that does not come from Platform repository, like coming from LDAP), eZ Platform kernel initiates an
Every service listening to this event will receive an
eZ\Publish\Core\MVC\Symfony\Event\InteractiveLoginEvent object which contains the original security token (that holds the matched user) and the request.
Then, it is up to the listener to retrieve a Platform user from the repository and to assign it back to the event object. This user will be injected into the repository and used for the rest of the request.
If no eZ Platform user is returned, the Anonymous User will be used.
User exposed and security token¶
When an external user is matched, a different token will be injected into the security context, the
This token holds a
UserWrapped instance which contains the originally matched user and the API user (the one from the eZ Platform repository).
Note that the API user is mainly used for permission checks against the repository and thus stays under the hood.
Customizing the User class¶
It is possible to customize the user class used by extending
ezpublish.security.login_listener service, which defaults to
You can override
getUser() to return whatever User class you want, as long as it implements
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
Implementing the listener¶
services.yml file in your AcmeExampleBundle:
1 2 3 4 5 6 7 8 9
Do not mix
MVCEvents::INTERACTIVE_LOGIN event (specific to eZ Platform) and
SecurityEvents::INTERACTIVE_LOGIN event (fired by Symfony security component).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34