1

我的申请分为三个部分:

  • 管理:^/backendIP保护
  • 安全区域:^/member登录保护
  • 公共路线: ^/

一切正常,除了access_denied_url. 我尝试指定一个路由名称以及一个普通路径。

当我/backend从配置的 IP 以外的 IP 访问时,我收到以下消息:

访问此资源需要完全身份验证。 500 内部服务器错误 - InsufficientAuthenticationException 1 链接异常:AccessDeniedException »

在开发环境中,这个异常根本没有被捕获,导致致命错误,但该access_denied_url选项不应该以某种方式重定向到给定的 url 吗?

这是我的security.yml:

security:
    firewalls:
        backend:
            pattern: ^/backend
            anonymous: ~
            access_denied_url: /403

        main:
            pattern: ^/
            anonymous: ~
            form_login:
                success_handler: my_auth_handler
                failure_handler: my_auth_handler
                use_referer: true
                check_path: login_check
            logout:
                path: /logout
                success_handler: my_auth_handler

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

    access_control:
        - { path: ^/backend,    roles: IS_AUTHENTICATED_ANONYMOUSLY, ips: [127.0.0.1] }
        - { path: ^/backend,    roles: ROLE_NO_ACCESS }
        - { path: ^/userlounge, roles: IS_AUTHENTICATED_FULLY }
        - { path: ^/,           roles: IS_AUTHENTICATED_ANONYMOUSLY }

    providers:
        frontend:
            id: my_user_provider

    encoders:
        My\FrontEndBundle\User\MyUser:
            algorithm:        md5
            encode_as_base64: false
            iterations:       1

提前感谢您的帮助!

4

2 回答 2

4

access_denied_url仅当用户的令牌不是匿名且记住我时才有效。

有关更多详细信息,请参阅: https ://github.com/symfony/symfony/blob/2.6/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php#L120 https://github.com/symfony/symfony /blob/2.6/src/Symfony/Component/Security/Core/Authentication/AuthenticationTrustResolver.php#L65

于 2014-11-27T17:17:10.537 回答
1

我认为您应该尝试access_denied_urlsecurity节点上而不是在特定防火墙(backend)上指定选项,因为我认为它可能是另一个防火墙抛出 AccessDenied 异常。

来源:http ://symfony.com/doc/current/reference/configuration/security.html

或者,您可以创建一个 AcccessDeniedListener,请参阅此页面以获取教程: http: //www.insanevisions.com/articles/view/symfony-2-access-denied-listener

于 2014-11-27T15:35:10.523 回答