Authentication 如果登录检查失败,返回503服务不可用状态-symfony2
我正在开发一个以Symfony2为框架的web应用程序,用户需要登录才能使用其余的服务。我正在使用symfony的防火墙对用户进行身份验证 防火墙代码是Authentication 如果登录检查失败,返回503服务不可用状态-symfony2,authentication,symfony,firewall,Authentication,Symfony,Firewall,我正在开发一个以Symfony2为框架的web应用程序,用户需要登录才能使用其余的服务。我正在使用symfony的防火墙对用户进行身份验证 防火墙代码是 firewalls: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false login: pattern: ^/login$ security: false secured_
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服务不可用
状态,并再次进入登录页面
但是如果我刷新空页面,它就会显示登录页面
有人能找出我做错了什么吗
编辑1-输出
编辑2
如果我在前面的控制器app.php
上注释掉以下行
$kernel = new AppCache($kernel);
然后返回的状态更改为200
,但等待时间较长,响应为空。我发现的另一件事是,如果我试图在登录控制器中打印symfony会话变量
$request = $this->getRequest();
$session = $request->getSession();
echo '<pre>';
print_r($session);
echo '</pre>';
$request=$this->getRequest();
$session=$request->getSession();
回声';
打印(会话);
回声';
它需要太多的时间和记忆,而且永远不会结束。这会导致浏览器冻结。我找不出原因
p.S:我正在使用symfony标准发行版尝试从
^/login$
模式中删除$
,使其匹配以/login
否开头的所有内容,然后它将抛出无法找到路径的控制器“/login\u check”
异常。顺便说一句,我很高兴地说,我正在使用您的河豚编码器包
作为我项目中的编码器。出现503错误时显示的url是什么?@CarlosGranados查看我的更新图像OK,因此重定向工作正常。您是否可以尝试使用防火墙的“use_forward”配置选项,看看这是否不会产生错误?此选项使防火墙不发送重定向,而是将请求转发到相应的控制器,请参见@CarlosGranados相同的结果,无改进您如何处理“error”变量?你在展示它吗?你能试着删除出错的代码,看看503是否还在吗?