Symfony 6 的 access_control 问题 - is_authenticated_complete 等

att*_*akt 5 authentication access-control symfony

    # set hierarchy for roles?
role_hierarchy: 
    # give admin also the roles inside the array.
    ROLE_ADMIN: [ROLE_USER]
# 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: ^/admin, roles: ROLE_ADMIN }
    # Unless the path is login, user must be authenticated anonymously.
    # This means only page accessible anonymously is login page.
    - { path: ^(/(login|register)),  roles: IS_AUTHENTICATED_ANONYMOUSLY }
    # can visit any other path if authenticated fully
    - { path: ^/, roles: IS_AUTHENTICATED_FULLY }
Run Code Online (Sandbox Code Playgroud)

这个简单的代码似乎不起作用。我无法访问登录或匿名注册。我知道 IS_AUTHENTICATED_FULLY 部分正在工作,因为当我将其注释掉时(并且我已注销,又称匿名身份验证),我可以访问登录和注册之外的其他路径。

即使我只是这样做:

- { path: ^/login,  roles: IS_AUTHENTICATED_ANONYMOUSLY }
Run Code Online (Sandbox Code Playgroud)

它不起作用,我无法访问/login。我究竟做错了什么?

我一直使用此视频作为指南:https://youtu.be/XjbIDOIoXTo ?t=4211

Jul*_* B. 6

Symfony 5.3 已弃用旧的身份验证机制以及 Guard 组件,请参阅https://symfony.com/blog/new-in-symfony-5-3-guard-component-deprecation。默认情况下,新系统不会使用 IS_AUTHENTICATED_ANONYMOUSLY 对用户进行“身份验证”。

匿名用户不再存在

您现在必须使用 PUBLIC_ACCESS 作为注释中指定的@Bossman。https://symfony.com/doc/current/security.html#allowing-unsecured-access-ie-anonymous-users

您链接中的视频清楚地表明该视频是使用 Symfony 5.2 录制的

注意 - 该系列是使用 SYMFONY 5.2 录制的。发生了一些细微的变化,并且一些课程已被删除。您仍然可以遵循本教程,但需要将其与文档的某些部分结合起来。