1

我正在开发一个使用 Symfony2 作为框架的网络应用程序,用户需要登录才能使用其余的服务。我正在使用 symfony 的防火墙对用户进行身份验证。

防火墙代码是

firewalls:
    dev:
        pattern:  ^/(_(profiler|wdt)|css|images|js)/
        security: false

    login:
        pattern:  ^/login$
        security: false

    secured_area:
        pattern:    ^/
        form_login: ~
        logout: ~

控制器代码是

public function indexAction()
{
    return $this->redirect($this->generateUrl('index_search'));
}

public function loginAction() {

    $request = $this->getRequest();
    $session = $request->getSession();

    // get the login error if there is one
    if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
        $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
    } else {
        $error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
        $session->remove(SecurityContext::AUTHENTICATION_ERROR);
    }

    return $this->render('IsBeagleBundle:Auth:login.html.php', array(
        // last username entered by the user
        'last_username' => $session->get(SecurityContext::LAST_USERNAME),
        'error'         => $error,
    ));
}

路线是

$collection->add('index', new Route('/', array(
    '_controller' => 'IsBeagleBundle:Auth:index',
)));

$collection->add('login', new Route('/login', array(
    '_controller' => 'IsBeagleBundle:Auth:login',
)));
$collection->add('login_check', new Route('/login_check', array()));

我面临的问题是

如果防火墙验证通过,重定向工作正常并进入搜索页面,但如果验证失败,它会返回503 Service Unavailable状态,它应该再次进入登录页面。

但是,如果我刷新空白页面,则会显示登录页面。

谁能弄清楚我做错了什么?

编辑 1 - 输出

在此处输入图像描述

编辑 2

如果我在前端控制器上注释掉以下行app.php

$kernel = new AppCache($kernel);

然后返回的状态变为200,但等待时间较长且响应为空。我想出的另一件事是,如果我尝试在登录控制器中打印 symfony 会话变量

$request = $this->getRequest();
$session = $request->getSession();

echo '<pre>';
print_r($session);
echo '</pre>';

它需要太多的时间和记忆,而且永远不会结束。这会导致浏览器冻结。我找不到原因。

PS:我使用的是 symfony 标准发行版

4

1 回答 1

0

尝试$^/login$模式中删除以匹配以 . 开头的所有内容/login

于 2012-08-30T06:37:50.040 回答