2016-06-30 11 views
1

私のアプリケーションがAJAX呼び出しをいくつか行っているので、symfonyのセキュリティでログインターゲットのパスを操作しようとしています。私はthis documentation articleに従ったが、何も起こらなかった(だから私はsecurity.exception_listener.classが正しくフックしなかったと仮定した)。私は私が提供されるドキュメントに解決策を主張githubの上の2015年からthis issueはsymfonyの> = 3Symfony3 security.exception_listener.classが動作しない

に無効になりたGoogleで検索すると今、私はただ思ったんだけど - リンクドキュメントが古く、実際にあるならば誰もが知っています(これは私のためにはうまくいかないようですが)、symfony 3でどのように同じことを達成していますか?

+0

あなたは(3.4アウトになるまで、少なくともそれは、LTSされ、現在は3 *よりも優れている)のSymfony 2.8で試すことができます。あなたのcomposer.jsonの "symfony/symfony"の制約を "2.8。*"に置き換えて、コンポーザのアップデートを実行してください。 –

+0

確かに魅力的ではありませんが、それはオプションだと思います。しかし、彼らはそのような重要な機能を削除することはできませんか? –

+0

あなたはこれに対する解決策を見つけましたか?私は問題のコメントに示された解決策を試してみて、それは私のために働く。しかし、パラメータを好むだろう。 –

答えて

0

のSymfony 2.7のドキュメントは、コンパイラパスを使用するように更新されました:https://symfony.com/doc/2.7/security/target_path.html

私は、この変更はすぐにドキュメントのそれ以降のバージョンに流れることになることを想像してみてください。

// src/AppBundle/Security/Firewall/ExceptionListener.php 
namespace AppBundle\Security\Firewall; 

use Symfony\Component\HttpFoundation\Request; 
use Symfony\Component\Security\Http\Firewall\ExceptionListener as BaseExceptionListener; 

class ExceptionListener extends BaseExceptionListener 
{ 
    protected function setTargetPath(Request $request) 
    { 
     // Do not save target path for XHR requests 
     // You can add any more logic here you want 
     // Note that non-GET requests are already ignored 
     if ($request->isXmlHttpRequest()) { 
      return; 
     } 

     parent::setTargetPath($request); 
    } 
} 
// src/AppBundle/DependencyInjection/Compiler/ExceptionListenerPass.php 
namespace AppBundle\DependencyInjection\Compiler; 

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; 
use Symfony\Component\DependencyInjection\ContainerBuilder; 
use AppBundle\Security\Firewall\ExceptionListener; 

class ExceptionListenerPass implements CompilerPassInterface 
{ 
    public function process(ContainerBuilder $container) 
    { 
     // Use the name of your firewall for the suffix e.g. 'secured_area' 
     $definition = $container->getDefinition('security.exception_listener.secured_area'); 
     $definition->setClass(ExceptionListener::class); 
    } 
} 
// src/AppBundle/AppBundle.php 
namespace AppBundle; 

use AppBundle\DependencyInjection\Compiler\ExceptionListenerPass; 

class AppBundle extends Bundle 
{ 
    public function build(ContainerBuilder $container) 
    { 
     $container->addCompilerPass(new ExceptionListenerPass()); 
    } 
} 
関連する問題