Symfony无法识别提供者属性

时间:2018-06-13 15:24:17

标签: php symfony

当我尝试使用symfony(3.4)的in_memory提供程序时,我遇到了问题。

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 }

当我正在推动该项目时,我收到了此错误

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

密码属性似乎已被识别。

我的用户实体中有一个fullname属性,所以我不明白这个问题。

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

2 个答案:

答案 0 :(得分:2)

当您使用in_memory提供商时,您将收到Symfony\Component\Security\Core\User\User的实例。此类没有fullname,因此会引发错误。

答案 1 :(得分:2)

用户提供商不处理额外数据 - 只是用户名(此处您提供了' admin')和密码 - 可选的一个或一个或更多角色。

# 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'