Skip to content

The firewall user shoyld be reloaded from the client entity manager #482

@soullivaneuh

Description

@soullivaneuh

The user used on makeClient with createUserToken is loaded from fixtures and is not managed by the client entity manager.

This cause issue during test because doctrine considers it a new not managed entity,

Preconditions

  1. Have a user on fixtures

Steps to reproduce

  1. Authenticate your client with loginAs and a user from your fixtures
  2. Create the client
  3. Make a request on a simple controller doing, for example, a refresh of the user got from the token.

Expected result

  1. The refresh should work and any save with user association should be ok.

Actual result

  1. An error telling the entity is not managed by doctrine.

If I add a line to reload the user from the client doctrine service, it works:

foreach ($this->firewallLogins as $firewallName => $user) {
    // OVERRIDE
    $user = $client->getContainer()->get('doctrine')->getRepository(User::class)->find($user->getId());
    // END OVERRIDE
    $token = $this->createUserToken($user, $firewallName);

    $tokenStorage = $client->getContainer()->get('security.token_storage');

    $tokenStorage->setToken($token);
    $session->set('_security_'.$firewallName, serialize($token));
}

But I don't know how to do it properly.

Three possible solutions:

  1. Make this bundle reloading the user from the client all the time
  2. If not possible for some cases, make an option for that
  3. If it's a too much specific case for you, make the override easier with a method like setupFirewalls with the client as parameter.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions