获取security.yml中的当前URL

时间:2015-01-12 08:40:01

标签: php symfony symfony-security

在我的要求中,用户收到带有网址的电子邮件,一旦他点击该用户,将通过身份验证过程导航到该网址。

所以要将用户重定向到点击的网址,我正在使用此处提到的方法(Pass parameters when redirect),我打算将重定向网址作为参数传递,如

login_path: %accounts_host%/signin?redirect=%need_current_url_here%

security.yml

并捕获$url=$_GET['redirect'];并相应地提供重定向。

我的查询是如何从security.yml中访问当前网址,以便我可以将其附加到login_path

我对此很新,非常感谢任何示例/文档。 :)

PS

身份验证在另一个symonfy2应用程序中完成,此时我无法使用referer命令,因为它将为null。这就是我试图将重定向url作为参数传递的原因。 :)

1 个答案:

答案 0 :(得分:2)

我建议使用入口点和成功处理程序。

security.yml:

firewalls:            # Required
    # Examples:
    somename:
        entry_point: some.service.id
        ...
        form_login:
            ...
            success_handler: some.service.id

SuccessHandler(source):

<?php
namespace StatSidekick\UserBundle\Handler;

use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler;
use Symfony\Component\Security\Http\HttpUtils;

class AuthenticationSuccessHandler extends DefaultAuthenticationSuccessHandler {

    public function __construct( HttpUtils $httpUtils, array $options ) {
        parent::__construct( $httpUtils, $options );
    }

    public function onAuthenticationSuccess( Request $request, TokenInterface $token ) {
        // Create if necessary a redirect response otherwise use the parent one with
        // $response = parent::onAuthenticationSuccess( $request, $token );

        return $response;
    }
}

入口点(source):

  

当用户根本未经过身份验证时(即,当令牌存储时)   还没有令牌),防火墙的入口点将被调用   &#34;开始&#34;身份验证过程。应该实施切入点   AuthenticationEntryPointInterface,只有一个方法:start()...

相关问题