我想解决Symfony 2应用程序中的这种不一致问题:当用户不经过身份验证的路径/app/logout
重定向到/app/login
时。相反,未经过身份验证的用户应该查看错误页面(可能是403)。
这是安全配置。 IS_AUTHENTICATED_FULLY
似乎是强制性的,因为用户只有在以前完全验证后才能注销:
access_control:
- { path: ^/app/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/app/logout, roles: IS_AUTHENTICATED_FULLY }
我AccessController
的退出操作:
/**
* @Extra\Route("logout")
* @Extra\Template
*/
public function logoutAction()
{
// Set the token to null and invalidate the session
$this->getSecurityContext()->setToken(null);
$this->getSession()->invalidate();
// Redirect url and seconds (window.location)
$seconds = 5;
$redirect = $this->getRouter()->generate('access_login');
return array('seconds' => $seconds, 'redirect' => $redirect);
}
一种解决方案是从访问控制中删除路由/app/logout
,然后在用户未完全验证的情况下抛出异常:
if(false === $this->getSecurityContext()->isGranted('IS_AUTHENTICATED_FULLY'))
throw new AccessDeniedException();
但即使是未经过身份验证的用户,也可以访问此方式/app/logout
!谁知道更好的解决方案?
答案 0 :(得分:1)
只需从access_control
删除退出路径即可。如果未经过身份验证的用户进入注销页面,则不会发生任何错误 - 这是安全的。不要过度设计这些东西。 ;)