2016-11-02 11 views
0

私はデシベルからユーザーを取得し、彼女をログインしようとloginActionを持っている。ログイン後、Symfony、UsernamePasswordTokenクラスのトークンに対して認証プロバイダが見つかりませんでしたか?

「メイン」ファイアウォールルールはむしろsecure_areaものより使用されているようです。私が得るために:

No Authentication Provider found for token of class "Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken"

i 'がメインの' ファイアウォールルールに

guard: 
     authenticators: 
      - token_authenticator 

を追加した場合、エラーが表示されなくなりますが、token_authenticatorが引き継ぎ、私はすべてのルート上Authentication Requiredを取得

ログイン後に$tokenまたはsessionをダンプすると、そこに自分のユーザーが表示されます。

私は間違って何をしていますか?ここ

public function loginAction(Request $request) 
{ 
    if ($request->isMethod('POST')) { 
     $userManager = $this->container->get('entity.user'); 

     $hasEmail = $this->getDoctrine()->getRepository('AppBundle:User')->findOneBy([ 
      'email' => $request->request->get('email'), 
      'password' => $request->request->get('password'), 
     ]); 

     // if credentials found 
     if ($hasEmail) { 
      // login the user 
      $token = new UsernamePasswordToken($hasEmail, $hasEmail->getPassword(), "secure_area", $hasEmail->getRoles()); 
      $this->get("security.token_storage")->setToken($token); 
      $this->get('session')->set('_security_secure_area', serialize($token)); 


      //$event = new InteractiveLoginEvent($request, $token); 
      //$this->get("event_dispatcher")->dispatch("security.interactive_login", $event); 
     } else { 
      $error = 'invalid credentials'; 
     } 
    } 

    return []; 
} 

は私のファイアウォールのルールです:

firewalls: 
    dev: 
     pattern: ^/(_(profiler|wdt)|css|images|js)/ 
     security: false 
     provider: db_provider 

    main: 
     anonymous: ~ 

    secure_area: 
     pattern: ^/ 
     anonymous: ~ 
     logout: 
      path: /logout 
      target:/
     guard: 
      authenticators: 
       - token_authenticator 

答えて

0

Firewallsは、あなたのルートパラメータのプレフィックスですpatternのセットによって区別されています。したがって、お客様のケースでは、mainファイアウォールが引き継ぐため、に到達します。

同様のパターンのルートを使用すると、/securedまたは/apiのような一意のパターンを使用してファイアウォールを通過できます。

さらに、必要がない限り、明示的にユーザーのログインを処理しないでください。代わりに$authenticationUtilsを使用してください。 this document(for 2.8)に従ってください。

providersfirewallssecurity.ymlに設定することは、アプリケーションにログインできるユーザーのソースによって異なります。これについて言えば、これは少しはっきりします。

希望すると便利です。

関連する問題