Uploaded image for project: 'eZ Platform Enterprise Edition'
  1. eZ Platform Enterprise Edition
  2. EZEE-1782

eZ Recommendation - login fails when using multiple user providers

    XMLWordPrintable

Details

    • Sprint 4

    Description

      When using eZ Recommendation Bundle 2.0.0 and multiple user providers (https://doc.ezplatform.com/en/latest/cookbook/authenticating_a_user_with_multiple_user_providers/), the external user (loaded from another provider) login attempt fails because eZ Recommendation tries to load user by the login. In this case though, the login comes from the external provider, so it cannot be found by the user service.
      Related code fragment in the eZ Recommendation Bundle: https://github.com/ezsystems/EzSystemsRecommendationBundle/commit/15bdfb4bb21a26ba302f2f36420dd0fc8f8f33e9#diff-773a07b6ffb9dbdbc2f69e67b9c1f032R85
      Similar code can be found here, so it probably should be also fixed: https://github.com/ezsystems/EzSystemsRecommendationBundle/commit/7bf0541a7a96fb1bc0a00261c3f6596711771253#diff-6ce4da54a9caaac043f943c0333e49a5R335
      The login attempt ends with an error "An unexpected error occurred" on a login screen. In the "Network tab" in the browser's developer tools there is a /api/ezp/v2/user/sessions request with 404 response code and the following response body:

      {
          "ErrorMessage": {
              "_media-type": "application\/vnd.ez.api.ErrorMessage+json",
              "errorCode": 404,
              "errorMessage": "Not Found",
              "errorDescription": "Could not find 'user' with identifier 'user'",
              "trace": "#0 xxx\\ezplatform\\app\\cache\\dev\\appDevDebugProjectContainer.php(40097): eZ\\Publish\\Core\\Persistence\\Legacy\\User\\Handler->loadByLogin('user')\n#1 xxx\\ezplatform\\vendor\\ezsystems\\ezpublish-kernel\\eZ\\Publish\\Core\\Persistence\\Cache\\UserHandler.php(55): eZPublishCorePersistenceLegacyUserHandler_000000000e400a22000000005da4eb2c86b4e9c06d7d9d156c88b8c3cd5f614d->loadByLogin('user')\n#2 xxx\\ezplatform\\vendor\\ezsystems\\ezpublish-kernel\\eZ\\Publish\\Core\\Repository\\UserService.php(604): eZ\\Publish\\Core\\Persistence\\Cache\\UserHandler->loadByLogin('user')\n#3 xxx\\ezplatform\\app\\cache\\dev\\appDevDebugProjectContainer.php(33779): eZ\\Publish\\Core\\Repository\\UserService->loadUserByLogin('user', Array)\n#4 xxx\\ezplatform\\vendor\\ezsystems\\ezpublish-kernel\\eZ\\Publish\\Core\\SignalSlot\\UserService.php(293): eZPublishCoreRepositoryUserService_000000000e400425000000005da4eb2c86b4e9c06d7d9d156c88b8c3cd5f614d->loadUserByLogin('user', Array)\n#5 xxx\\ezplatform\\vendor\\ezsystems\\recommendation-bundle\\EventListener\\Login.php(89): eZ\\Publish\\Core\\SignalSlot\\UserService->loadUserByLogin('user')\n#6 [internal function]: EzSystems\\RecommendationBundle\\EventListener\\Login->onSecurityInteractiveLogin(Object(Symfony\\Component\\Security\\Http\\Event\\InteractiveLoginEvent), 'security.intera...', Object(Symfony\\Component\\HttpKernel\\Debug\\TraceableEventDispatcher))\n#7 xxx\\ezplatform\\vendor\\symfony\\symfony\\src\\Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener.php(61): call_user_func(Array, Object(Symfony\\Component\\Security\\Http\\Event\\InteractiveLoginEvent), 'security.intera...', Object(Symfony\\Component\\HttpKernel\\Debug\\TraceableEventDispatcher))\n#8 [internal function]: Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener->__invoke(Object(Symfony\\Component\\Security\\Http\\Event\\InteractiveLoginEvent), 'security.intera...', Object(Symfony\\Component\\EventDispatcher\\ContainerAwareEventDispatcher))\n#9 xxx\\ezplatform\\vendor\\symfony\\symfony\\src\\Symfony\\Component\\EventDispatcher\\EventDispatcher.php(184): call_user_func(Object(Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener), Object(Symfony\\Component\\Security\\Http\\Event\\InteractiveLoginEvent), 'security.intera...', Object(Symfony\\Component\\EventDispatcher\\ContainerAwareEventDispatcher))\n#10 xxx\\ezplatform\\vendor\\symfony\\symfony\\src\\Symfony\\Component\\EventDispatcher\\EventDispatcher.php(46): Symfony\\Component\\EventDispatcher\\EventDispatcher->doDispatch(Array, 'security.intera...', Object(Symfony\\Component\\Security\\Http\\Event\\InteractiveLoginEvent))\n#11 xxx\\ezplatform\\vendor\\symfony\\symfony\\src\\Symfony\\Component\\EventDispatcher\\Debug\\TraceableEventDispatcher.php(138): Symfony\\Component\\EventDispatcher\\EventDispatcher->dispatch('security.intera...', Object(Symfony\\Component\\Security\\Http\\Event\\InteractiveLoginEvent))\n#12 xxx\\ezplatform\\vendor\\ezsystems\\ezpublish-kernel\\eZ\\Publish\\Core\\REST\\Server\\Security\\RestAuthenticator.php(134): Symfony\\Component\\EventDispatcher\\Debug\\TraceableEventDispatcher->dispatch('security.intera...', Object(Symfony\\Component\\Security\\Http\\Event\\InteractiveLoginEvent))\n#13 xxx\\ezplatform\\vendor\\ezsystems\\ezpublish-kernel\\eZ\\Publish\\Core\\REST\\Server\\Controller\\SessionController.php(81): eZ\\Publish\\Core\\REST\\Server\\Security\\RestAuthenticator->authenticate(Object(Symfony\\Component\\HttpFoundation\\Request))\n#14 [internal function]: eZ\\Publish\\Core\\REST\\Server\\Controller\\SessionController->createSessionAction(Object(Symfony\\Component\\HttpFoundation\\Request))\n#15 xxx\\ezplatform\\vendor\\symfony\\symfony\\src\\Symfony\\Component\\HttpKernel\\HttpKernel.php(142): call_user_func_array(Array, Array)\n#16 xxx\\ezplatform\\vendor\\symfony\\symfony\\src\\Symfony\\Component\\HttpKernel\\HttpKernel.php(62): Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw(Object(Symfony\\Component\\HttpFoundation\\Request), 1)\n#17 xxx\\ezplatform\\vendor\\symfony\\symfony\\src\\Symfony\\Component\\HttpKernel\\DependencyInjection\\ContainerAwareHttpKernel.php(67): Symfony\\Component\\HttpKernel\\HttpKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#18 xxx\\ezplatform\\vendor\\symfony\\symfony\\src\\Symfony\\Component\\HttpKernel\\Kernel.php(183): Symfony\\Component\\HttpKernel\\DependencyInjection\\ContainerAwareHttpKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#19 xxx\\ezplatform\\web\\app.php(70): Symfony\\Component\\HttpKernel\\Kernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request))\n#20 {main}",
              "file": "xxx\\ezplatform\\vendor\\ezsystems\\ezpublish-kernel\\eZ\\Publish\\Core\\Persistence\\Legacy\\User\\Handler.php",
              "line": 121
          }
      }
      

      Previous versions of eZ Recommendation Bundle don't have this issue.

      Steps to reproduce

      1. Create new eZ Platform 1.11 installation.
      2. Configure new user provider, as in the example here: https://doc.ezplatform.com/en/latest/cookbook/authenticating_a_user_with_multiple_user_providers/#example
        • In the app/config/security, change the security.providers to the following:
          security:
              providers:
                  # Chaining in_memory and ezpublish user providers
                  chain_provider:
                      chain:
                          providers: [in_memory, ezpublish]
                  ezpublish:
                      id: ezpublish.security.user_provider
                  in_memory:
                      memory:
                          users:
                              # You will then be able to login with username "user" and password "userpass"
                              user:  { password: userpass, roles: [ 'ROLE_USER' ] }
              encoders:
                  Symfony\Component\Security\Core\User\User: plaintext
          
        • Add the AppBundle from the attachment with implemented listener.
      3. Add eZ Recommendation Bundle, using the "Step 1: installation" from the documentation: https://github.com/ezsystems/EzSystemsRecommendationBundle#step-1-installation
      4. Login to the back-office using username "user" and password "userpass". The error described above will be presented to you.

      Attachments

        Activity

          People

            Unassigned Unassigned
            jacek.foremski-obsolete@ez.no Jacek Foremski (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: