2016-12-07 9 views
0

Symfony2.8으로 FOSOAuthServerBundle을 성공적으로 구현했으며 작동했습니다. Symfony3.2에서 작동하려고했을 때 오류가 발생했습니다 :FOSOAuthServerBundle 대 Symfony3 보안 하우 토

"Symfony \ Component \ Security \ Core"네임 스페이스에서 "SecurityContext"클래스를로드하려고 시도했습니다. 다른 네임 스페이스에 "사용"문을 잊어 버렸습니까?

그래서 저는 이제 Google 검색을 통해 이제 SecurityContext가 Symofny 3.2에 더 이상 존재하지 않는다는 것을 알게되었습니다. 그러나 FOSOAuthServerBundle의 공식 문서 "보안에 대한 참고 사항"은 여전히 ​​symfony2에서만 간결하게 기능하는 loginAction() 함수입니다.

질문 : - Symfony 3.2에서이 번들을 사용할 수 있습니까? - 그렇다면 문서 작성 방법이나 더 나은 예가 있습니까?

당신에게 자세히 FOSOAuthServerBundle을 몰라 답변

답변

1

주셔서 대단히 감사합니다. 하지만 번들 설명서의 예제는 a_note_about_security이라고 생각됩니다.

symfony 2.6 이후 security.context 서비스가 더 이상 사용되지 않았습니다. 당신은 내가 그것을 알아 냈 \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

0

\Symfony\Component\Security\Core\SecurityContext를 교체 시도 할 수 symfony.com/blog/new-in-symfony-2-6-security-component-improvements

: 여기 당신은 변경에 대한 설명을 찾을 수 있습니다. 아마 누군가를 도울 수 있습니다.

public function loginAction(Request $request) { 

    $authenticationUtils = $this->get('security.authentication_utils'); 

    $error = $authenticationUtils->getLastAuthenticationError(); 
    $lastUsername = $authenticationUtils->getLastUsername(); 

    return $this->render('AppBundle:Security:login.html.twig', array(
       'last_username' => $lastUsername 
       , 'error' => $error 
    )); 
}