2016-12-07 24 views
0

私はSymfony2.8でFOSOAuthServerBundleを正常に実装していました。 Symfony3.2で作業しようとしたときにエラーが発生しました:FOSOAuthServerBundle対Symfony3セキュリティハウツ

名前空間 "Symfony \ Component \ Security \ Core"から "SecurityContext"クラスを読み込もうとしました。 別の名前空間に「使用」ステートメントを忘れましたか?

私はグーグルで、今やSecurityContextがもうSymofny 3.2に存在しないことを知っています。しかし、FOSOAuthServerBundleの公式ドキュメンテーション「セキュリティに関する注意」はまだ存在しますsymfony2でコンパイル可能なloginAction()関数です。

質問: - このバンドルをSymfony 3.2で使用できますか? - 「はい」の場合、どのようにそれを行う方法のドキュメントがありますか、それとも良い例ですか?

は答え

答えて

1

いただき、誠にありがとうござい詳しくFOSOAuthServerBundleわかりません。しかし、私はa_note_about_securityのバンドルのドキュメントの例はちょうど時代遅れだと思います。

security.contextサービスは、symfony 2.6以降では廃止されました。あなたが、私はそれを考え出した\Symfony\Component\Security\Core\Security

<?php 
// src/Acme/SecurityBundle/Controller/SecurityController.php 

namespace Acme\SecurityBundle\Controller; 

use Symfony\Bundle\FrameworkBundle\Controller\Controller; 
use Symfony\Component\Security\Core\Security; 

class SecurityController extends Controller 
{ 
    public function loginAction() 
    { 
     $request = $this->getRequest(); 
     $session = $request->getSession(); 

     // get the login error if there is one 
     if ($request->attributes->has(Security::AUTHENTICATION_ERROR)) { 
      $error = $request->attributes->get(Security::AUTHENTICATION_ERROR); 
     } else { 
      $error = $session->get(Security::AUTHENTICATION_ERROR); 
      $session->remove(Security::AUTHENTICATION_ERROR); 
     } 

     // Add the following lines 
     if ($session->has('_security.target_path')) { 
      if (false !== strpos($session->get('_security.target_path'), $this->generateUrl('fos_oauth_server_authorize'))) { 
       $session->set('_fos_oauth_server.ensure_logout', true); 
      } 
     } 

     return $this->render('AcmeSecurityBundle:Security:login.html.twig', array(
      // last username entered by the user 
      'last_username' => $session->get(Security::LAST_USERNAME), 
      'error'   => $error, 
     )); 
    } 
} 
+0

はい、あなたは正しいです、どうすればいいのか分かりません。とにかく、ありがとう。 – milan74sa

関連する問題