Thomas Fournet
Thomas Fournet

Reputation: 700

Symfony unrecognized provider property

I have a problem when I'm trying to use the in_memory provider of symfony (3.4).

security.yml

security:
    encoders:
        Symfony\Component\Security\Core\User\User:
            algorithm: bcrypt
        PortalBundle\Entity\User:
            algorithm: bcrypt

    role_hierarchy:
        !php/const PortalBundle\Utils\UserMetaData::ROLE_GLOBAL_ADMIN: !php/const PortalBundle\Utils\UserMetaData::ROLE_ADMIN

    providers:
        in_memory:
            memory:
                users:
                    admin:
                        fullname: test
                        password: admin

    firewalls:
        # disables authentication for assets and the profiler, adapt it according to your needs
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

        main:
            pattern: ^/
            provider: in_memory
            form_login:
                login_path: login
                check_path: login
            logout: true
            anonymous: ~
            # activate different ways to authenticate


    access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }

When i'm lauching the project, I got this error

 Unrecognized option "fullname" under "security.providers.in_memory.memory.users.admin"

The password property seems to be recognized.

I do have a fullname property in my user entity so I don't understand the problem.

/**
 * Full name of the entity.
 *
 * @var string
 *
 * @Assert\NotBlank()
 * @ORM\Column(name="fullname", type="string", length=255)
 */
private $fullname;

Upvotes: 0

Views: 104

Answers (2)

Alister Bulman
Alister Bulman

Reputation: 35159

The user provider doesn't deal with extra data - just the username (here you've provided it as 'admin'), and a password - with an optional set of one or more roles.

# from https://symfony.com/doc/current/security/multiple_user_providers.html
# config/packages/security.yaml
security:
    providers:
        in_memory:
            memory:
                users:
                    admin:
                        password: kitten
                        roles: 'ROLE_ADMIN'
                    ryan:
                        password: ryanpass
                        roles: 'ROLE_USER'

Upvotes: 2

DonCallisto
DonCallisto

Reputation: 29922

When you use in_memory provider you'll receive back an instance of Symfony\Component\Security\Core\User\User. This class has not fullname so an error is raised.

Upvotes: 2

Related Questions