我可以将单个 URI 端点标记为匿名吗?

Can I mark a single URI endpoint as anonymous?

我已阅读文档并遵循了类似的问题:

Allow anonymous access to specific URL in symfony firewall protected bundle

使用 Symfony 4.1.4 我尝试了以下方法:

access_control:
  - { path: ^/rpi/service/application/quote/approve, roles: IS_AUTHENTICATED_ANONYMOUSLY}
  - { path: ^/rpi, roles: ROLE_USER }
  - { path: ^/erp, roles: ROLE_USER }

然而,当我以匿名身份访问第一个 URI 时,http_basic_ldap 登录屏幕提示我。有什么想法吗?

你需要

anonymous: true

在您的防火墙中,如默认配置 config/packages/security.yml:

security:
    # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
    providers:
        in_memory: { memory: ~ }
    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            anonymous: true

匿名身份验证意味着用户身份验证并且一个令牌,但它是一个匿名令牌。

如果您没有 anonymous: true,AnonymousAuthenticationListener 永远不会 运行 您的防火墙,也永远不会创建匿名令牌。