首页 文章

Symfony无法识别提供者属性

提问于
浏览
0

当我尝试使用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 回答

  • 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'
    
  • 2

    当您使用 in_memory 提供程序时,您将收到 Symfony\Component\Security\Core\User\User 的实例 . 这个类没有 fullname 所以会引发错误 .

相关问题