Skip to content
This repository was archived by the owner on Oct 17, 2023. It is now read-only.

Blameable and decoupled user entity and userinterface'd class #12

@danaki

Description

@danaki

Hi, I'm using decoupled Entity and Security user following this article https://stovepipe.systems/post/decoupling-your-security-user

Now my entity looks like:

class Batch {
// ....
    /**
     * @var User
     *
     * @Gedmo\Blameable(on="create")
     * @ORM\ManyToOne(targetEntity="User")
     */
    private $createdBy;
//...

where App\Entity\User is just an Entity and class App\Security\User\SecurityUser implements actual UserInterface.

Now, using Blameable, when I try to save the entity with the current user in related field, it produces error:

The class 'App\Security\User\SecurityUser' was not found in the chain configured namespaces App\Entity

Which is because of this line of code:

        if (null !== $token && $this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
            $this->blameableListener->setUserValue($token->getUser());
        }

$token->getUser() returns an object of class App\Security\User\SecurityUser not the Entity.

Can you please update the Blameable to inject and query Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface or use Symfony\Component\Security\Core\User\UserProviderInterface so that User entity'd be loaded from the database instead (of course if $token->getUser() returns not an entity).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions