dtxs9017 2015-01-12 08:40
浏览 47

获取security.yml中的当前URL

In my requirement, a user receives an email with a url, once he clicks the user will be navigated to the url via an authentication process.

So to redirect the user to the clicked url I am using the method mentioned here ( Pass parameters when redirect ) where I intend to pass the redirect url as parameter like

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

within the security.yml and capture as such $url=$_GET['redirect']; and provide the redirection accordingly.

My query is how can I access the current url from within the security.yml so that I can attach it to the login_path.

I am quite new to this and any example/ document is very much appreciated. :)

PS

The authentication is done within another symonfy2 application at which point, I cant use referer command as it will be null. That is why I am trying to pass thee redirect url as a parameter. :)

  • 写回答

1条回答 默认 最新

  • dozxos6346 2015-01-13 07:50
    关注

    I would suggest to use an entry point and a success handler.

    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;
        }
    }
    

    Entry point (source):

    When the user is not authenticated at all (i.e. when the token storage has no token yet), the firewall's entry point will be called to "start" the authentication process. An entry point should implement AuthenticationEntryPointInterface, which has only one method: start() ...

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型