我将 FosUserBundle 登录嵌入到我的主页中,我已经覆盖了 fos 的安全控制器并更改了 renderLogin() 操作,我必须放置一个if
使用以下条件重定向到上次访问的页面referers , that was一切都很好,但我现在意识到 HTTP 协议不需要 HTTP Referer 标头,并且可以通过浏览器设置等完全跳过甚至欺骗它。它不可靠!
但如果 symfony 框架可以保证 $request->server->get('HTTP_REFERER')
or $request->headers->get('referer')
将被设置。我可以毫不费力地使用这些
我的问题
- symfony 请求对象的引用者是否 100% 可靠?
- 有什么区别
$request->server->get('HTTP_REFERER')
and $request->headers->get('referer')
?
- 如果它们不可靠,可以有什么替代方案?
(P.S)
在交响乐中docs
如果用户要求http://www.example.com/admin/post/18/edit,那么他们登录成功后,最终会被发送回http://www.example.com/admin/post/18/edit。这是通过将请求的 URL 存储在会话中来完成的。
但他们没有解释其内部工作原理。如果referers最终被证明是不可靠的,那么我的替代方案如下,欢迎任何建议
1)。注册监听器并添加属性last_path
2)。存储会话变量last_path
在 security.yml 中
main:
pattern: ^/
logout: true
form_login:
provider: fos_userbundle
login_path: /login
success_handler: authentication_handler
failure_handler: authentication_handler
remember_me:
key: secret
lifetime: 604800
path: /
domain: yourdomain.com
anonymous: true
logout:
path: /logout
target: /
handler: authentication_handler
在config.yml中
services:
authentication_handler:
class: YourBundle\UserBundle\Security\AuthenticationHandler
AuthentificationHandler 类
<?PHP
Namespace YourBundle\UserBundle\Security;
class AuthenticationHandler implements
AuthenticationFailureHandlerInterface, AuthenticationSuccessHandlerInterface, LogoutSuccessHandlerInterface {
public function onAuthenticationFailure(Request $request, AuthenticationException $exception) {
$referer = $request->headers->get('referer');
$request->getSession()->setFlash('LoginError', $exception->getMessage());
return new RedirectResponse($referer);
}
public function onAuthenticationSuccess(Request $request, \Symfony\Component\Security\Core\Authentication\Token\TokenInterface $token) {
$referer = $request->headers->get('referer');
$request->getSession()->setFlash('LoginError', "success");
return new RedirectResponse($referer);
}
public function onLogoutSuccess(Request $request) {
$referer = $request->headers->get('referer');
return new RedirectResponse($referer);
}
}
?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)