【问题标题】:Symfony easy admin Bundle setting/assigning user rolesSymfony easy admin Bundle 设置/分配用户角色
【发布时间】:2020-02-07 06:40:49
【问题描述】:

我正在尝试配置简单的管理员配置。

这是我与用户的数据库结构。

user (Table)
_____
id
username
password
email

现在,当我尝试登录时,我了解到该构造需要/需要某种用户角色。 既然出现这个错误

传递给 Symfony\Component\Security\Guard\Token\PostAuthenticationGuardToken::__construct() 的参数 3 必须是数组类型,给定 null,在第 37 行的 \AbstractGuardAuthenticator.php 中调用

所以我的问题是如何为我的用户分配角色?

这是我的配置。

在我的security.yml 文件中,我有这些配置。

security:
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
    in_memory: { memory: null }
firewalls:
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false
    main:
        anonymous: true
        guard:
            authenticators:
                - App\Security\AuthAuthenticator
        logout:
            path: app_logout
            # where to redirect after logout
            # target: app_any_route

        # activate different ways to authenticate
        # https://symfony.com/doc/current/security.html#firewalls-authentication

        # https://symfony.com/doc/current/security/impersonating_user.html
        # switch_user: true

# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
     - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
     - { path: ^/, roles: IS_AUTHENTICATED_FULLY }

我的easy_admin.yml 是空的。

如果您需要任何其他信息,请告诉我。

谢谢。

【问题讨论】:

  • 用户注册时是否有角色?
  • 没有注册,我只是将它们添加到数据库中。
  • 只需在数据库中的字段角色中添加[“ROLE_USER”]
  • 我没有角色字段...这就是问题所在。我自动生成了表格,但我没有得到任何角色字段。
  • 这很奇怪php bin/console make:user字段角色应该是自动创建的

标签: php symfony authentication easyadmin


【解决方案1】:

您应该按照 Symfony 安全文档中的说明将“roles”属性添加到 User 表中:

【讨论】:

    猜你喜欢
    • 2019-05-19
    • 1970-01-01
    • 1970-01-01
    • 2019-06-04
    • 2013-04-24
    • 1970-01-01
    • 1970-01-01
    • 2019-05-17
    • 1970-01-01
    相关资源
    最近更新 更多