E46B Core User class returning roles as strings instead of Role objects · Issue #13037 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Core User class returning roles as strings instead of Role objects #13037
@turneliusz

Description

@turneliusz

I'm using Symfony 2.6

system_users:
  memory:
    users:
      my_admin: { password: "xxx", roles: 'ROLE_ADMIN' }

for that the container looks like:

    /**
     * Gets the 'security.user.provider.concrete.system_users' service.
     *
     * This service is shared.
     * This method always returns the same instance of the service.
     *
     * This service is private.
     * If you want to be able to request this service from the container directly,
     * make it public, otherwise you might end up with broken code.
     *
     * @param bool    $lazyLoad whether to try lazy-loading the service with a proxy
     *
     * @return \Symfony\Component\Security\Core\User\InMemoryUserProvider A Symfony\Component\Security\Core\User\InMemoryUserProvider instance.
     */
    public function getSecurity_User_Provider_Concrete_SystemUsersService($lazyLoad = true)
    {
        // (...)
        $instance = new \Symfony\Component\Security\Core\User\InMemoryUserProvider();

        $instance->createUser(new \Symfony\Component\Security\Core\User\User('my_admin', 'xxx', array(0 => 'ROLE_ADMIN')));

        return $instance;
    }

which is triggering an exception Call to a member function getRole() on a non-object:

(...)
Dec 19 15:28:54 damian-ThinkPad-T440p [3861]: PHP 18. XXX\Bundle\AdminBundle\Security\Voter\AdminAccessVoter->isGranted($attribute = uninitialized, $object = uninitialized, $user = uninitialized) /home/damian/PhpstormProjects/vendor-backend/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authorization/Voter/AbstractVoter.php:76
Dec 19 15:28:54 damian-ThinkPad-T440p [3861]: PHP 19. Symfony\Component\Security\Core\Role\RoleHierarchy->getReachableRoles($roles = uninitialized) /home/damian/PhpstormProjects/vendor-backend/src/XXX/Bundle/AdminBundle/Security/Voter/AdminAccessVoter.php:65
Dec 19 15:28:54 damian-ThinkPad-T440p [3861]: request.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalErrorException: "Error: Call to a member function getRole() on a non-object" at /home/damian/PhpstormProjects/vendor-backend/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Role/RoleHierarchy.php line 43 {"exception":"[object](Symfony\Component\Debug\Exception\FatalErrorException: Error: Call to a member function getRole%28%29 on a non-object at /home/damian/PhpstormProjects/vendor-backend/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Role/RoleHierarchy.php:43)"} []

as Core User code looks like:

    private $roles;

    public function __construct($username, $password, array $roles = array(), $enabled = true, $userNonExpired = true, $credentialsNonExpired = true, $userNonLocked = true)
    {
        // ...

        $this->roles = $roles;
    }

    /**
     * {@inheritdoc}
     */
    public function getRoles()
    {
        return $this->roles;
    }

UserInterface::getRoles() defines:

    /**
     * Returns the roles granted to the user.
     * (...)
     * @return Role[] The user roles
     */
    public function getRoles();

Am I doing something wrong or it's a bug?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0