其中一个中出现Symfony2多个防火墙循环错误

时间:2015-08-14 10:34:48

标签: symfony

我的申请有问题。我为每个部分设置了三个防火墙。一个用于后端,一个用于前端,一个用于外部网。他们都有相同的用户提供商(FOSUserBundle),并且在我添加新的防火墙(外联网)之前它工作正常。现在,在这个防火墙中,当我尝试访问domain.com/extranet/时,我得到一个无限循环,但其他防火墙工作正常。

这是我的配置:

security.yml

firewalls:
extranet:
    pattern: /extranet(.*)
    form_login:
        provider: fos_userbundle
        login_path:     extranet_login
        check_path:     extranet_login_check
        default_target_path: extranet_home
    logout:
        path:           extranet_login_logout
        target:         page_home
    anonymous:    false
    security:     true
    context:      application
    remember_me:
        key: XXXXXXX
        lifetime: 86400
admin:
    pattern: /admin(.*)
    form_login:
        provider: fos_userbundle
        login_path:     admin_login
        check_path:     admin_login_check
        default_target_path: admin_home
    logout:
        path:           admin_logout
        target:         page_home
    anonymous:    true
    security:     true
    context:      application
    remember_me:
        key: XXXXXXX
        lifetime: 86400
main:
    pattern: ^/
    form_login:
        provider: fos_userbundle
        csrf_provider: form.csrf_provider
    logout:       true
    anonymous:    true
    security:     true
    context: application
    remember_me:
        key: XXXXXXX
        lifetime: 86400

ACCESS_CONTROL:

- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }

- { path: ^/extranet/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/extranet/logout$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/extranet/login_check$, role: IS_AUTHENTICATED_ANONYMOUSLY }

- { path: ^/admin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/logout$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/login_check$, role: IS_AUTHENTICATED_ANONYMOUSLY }

- { path: ^/admin/, role: ROLE_ADMIN }
- { path: ^/extranet/, role: ROLE_DISTRIBUTOR }

的routing.yml

    #Login
login_check:
    pattern: /login_check

logout:
    pattern: /logout

#extranet login
extranet_login:
    pattern:  /extranet/login
    defaults: { _controller: FOSUserBundle:Security:login }

extranet_login_check:
    pattern:  /extranet/login_check
    defaults: { _controller: FOSUserBundle:Security:check }

extranet_logout:
    pattern:  /extranet/logout
    defaults: { _controller: FOSUserBundle:Security:logout }

#admin login
admin_login:
    pattern:  /admin/login
    defaults: { _controller: FOSUserBundle:Security:login }

admin_login_check:
    pattern:  /admin/login_check
    defaults: { _controller: FOSUserBundle:Security:check }

admin_logout:
    pattern:  /admin/logout
    defaults: { _controller: FOSUserBundle:Security:logout }

最后,我的安全控制器。

class SecurityController extends BaseController
{
    /**
     * {@inheritDoc}
     */
    public function renderLogin(array $data)
    {
        $requestAttributes = $this->container->get('request')->attributes;

        if ('admin_login' === $requestAttributes->get('_route')) {
            $template = sprintf('WebBundle:Backend:login.html.twig');
        } elseif ('extranet_login' === $requestAttributes->get('_route')) {
            $template = sprintf('WebBundle:Extranet:login.html.twig');
        } else {
            $template = sprintf('FOSUserBundle:Security:login.html.twig');
        }

        return $this->container->get('templating')->renderResponse($template, $data);
    }
}

可能有什么不对?我尝试了很多改变,但是当我解决这个问题时,另一个改变了......

提前谢谢!

1 个答案:

答案 0 :(得分:2)

正如Dan Mironis所说,问题是我在外网防火墙中设置了匿名:false。我把它改成了真的,现在看起来它正在发挥作用。谢谢!