[英]symfony logout target never applied
I run first time into a problem with Symfony (2.7) authentication, where I really couldn't find a working solution. 我第一次遇到Symfony(2.7)身份验证问题,我真的找不到可行的解决方案。 Although Symfony has a dedicated configuration option logout -> target , this gets never applied on logouts, I always get directed to /.
虽然Symfony有一个专用的配置选项logout - > target ,但这从未在注销时应用,我总是被定向到/。 I probably missed some constraint on implementing this correctly.
我可能错过了正确实现这一点的一些限制。
Ok, I'm using: 好的,我正在使用:
My config.yml firewall 我的config.yml防火墙
secured_area:
pattern: ^/
stateless: false
form_login:
...
logout:
path: logout
target: /test
success_handler: logout_success_handler
anonymous: ~
For testing I even added 为了测试,我甚至添加了
access_control:
- { path: ^/test, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY }
I'm using route-names for the paths, the route exists and are working ok (I can login , login_check and logout ). 我正在使用路径的路由名称,路由存在并且正常工作(我可以登录 , 登录 _check和注销 )。
My expectation by setting logout -> target , that on logout I get redirected to the page /test. 我希望通过设置logout - > target ,在注销时我会被重定向到页面/测试。 But whatever I tried, until now I'm always on / after logout.
但无论我尝试过什么,直到现在我总是在注销之后。
I would be very glad, if somebody can point me into the correct direction, how to logout to a custom route (I also tried already target with a route name). 我很高兴,如果有人可以指出我正确的方向,如何注销到自定义路线(我也尝试使用路线名称进行目标 )。 Many thanks!
非常感谢!
BTW: BTW:
My logout_success_handler does currently nothing. 我的logout_success_handler目前没有任何功能。 By enabling the dump, I just also see, that the redirection is always going to / and not to /test.
通过启用转储,我也看到,重定向始终是/而不是/ test。
public function onLogoutSuccess(Request $request)
{
$response = parent::onLogoutSuccess($request);
//var_dump($response); die;
return $response;
}
There is no built in logout target. 没有内置的注销目标。 You have to handle it in your handler.
你必须在你的处理程序中处理它。
Step 1 步骤1
Put your logout target into your parameters file 将您的注销目标放入参数文件中
parameters:
logout.target: /test
Step 2 第2步
Modify your service.yml
where you've defined your logout handler to the following: 修改
service.yml
,其中已将logout处理程序定义为以下内容:
some.logout_handler:
class: SomeBundle\Security\YourAuthenticationHandler
arguments: ["@security.context", %logout.target%]
This will inject it into your handler. 这会将其注入您的处理程序。
Step 3 第3步
Finally, in your onLogoutSuccess
method just do 最后,在你的
onLogoutSuccess
方法中做
public function onLogoutSuccess(Request $request)
{
$response = parent::onLogoutSuccess($request);
return new RedirectResponse($this->logoutTarget);
}
And the final method for people having the same issue. 对于人们有同样问题的最终方法。
/**
* LogoutSuccessHandler
*/
class LogoutSuccessHandler extends DefaultLogoutSuccessHandler implements LogoutSuccessHandlerInterface
{
/**
* @var string
*/
private $logout_route;
/**
* Constructor
*
* @param RouterInterface $router
* @param EntityManager $em
*/
public function __construct(HttpUtils $httpUtils, $logoutRoute)
{
$this->logout_route = $logoutRoute;
parent::__construct( $httpUtils );
}
/**
* @param Request $request
* @return Response
*/
public function onLogoutSuccess(Request $request)
{
return $this->httpUtils->createRedirectResponse($request, $this->logout_route);
}
}
I'd like to use httpUtils as the createRedirectResponse understands paths and route-names. 我想使用httpUtils,因为createRedirectResponse了解路径和路由名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.