4

我正在尝试使用 symfony 2 设置一个非常简单的 http-basic 身份验证。不幸的是,我不断收到 500 HTTP 错误代码AccessDeniedException: Access Denied,而不是 401,这将迫使浏览器显示用户名/密码框。

这是我的security.yml:

jms_security_extra:
    secure_all_services: false
    expressions: true

security:
    firewalls:
        secured_area:
            pattern:    ^/
            anonymous: ~
            http_basic:
                realm: "Flow"

    access_control:
        - { path: ^/flow/checkout/, roles: ROLE_USER }

    providers:
        in_memory:
            memory:
                users:
                    user:  { password: userpass, roles: ROLE_USER }
                    admin: { password: kitten, roles: ROLE_ADMIN }

    encoders:
        Symfony\Component\Security\Core\User\User: plaintext

有什么想法有什么问题吗?

这是我正在调用的 URL:http://local.shop/web/app_dev.php/flow/checkout

这就是我得到的答案: 在此处输入图像描述

4

1 回答 1

0

你试过pattern: .*吗?

security:
    firewalls:
        secured_area:
            pattern: .*
            anonymous: ~
            http_basic:
                realm: "Flow"

我想您的防火墙被绕过了,并且您尝试直接访问应用程序的“部分”,如果您没有经过身份验证,您将无法访问

使用您的“旧”路径,仅当该请求针对 url 时,您才要求防火墙“考虑请求” /(这意味着 /foo 或 /foo/bar 或 /foo/bar/foobar 未被拦截)

更新

[2013-03-18 09:20:48] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest". [] []
[2013-03-18 09:20:48] security.INFO: Populated SecurityContext with an anonymous Token [] []
[2013-03-18 09:20:48] security.INFO: No expression found; abstaining from voting. [] []
[2013-03-18 09:20:48] event.DEBUG: Notified event "kernel.exception" to listener "Symfony\Component\Security\Http\Firewall\ExceptionListener::onKernelException". [] []
[2013-03-18 09:20:48] security.DEBUG: Access is denied (user is not fully authenticated) by "/var/www/html/cm/vendor/symfony/symfony/src/Symfony/Component/Security/Http/Firewall/AccessListener.php" at line 73; redirecting to authentication entry point [] []
[2013-03-18 09:20:48] security.DEBUG: Calling Authentication entry point [] []

这是一个日志示例,当内核拦截对“必须拥有的”资源的请求时

于 2013-03-08T11:52:44.213 回答