現在、2.0.* プロジェクトを Symfony の現在の 2.1 ベータ版に移行中です。
私の機能テストでは、現在、認証を使用してクライアントを作成するための次のコードがあります。
$client = // create a normal test client
$role = 'ROLE_USER';
$firewallName = 'main';
$user = // pull a user from db
$client->getCookieJar()->set(new \Symfony\Component\BrowserKit\Cookie(session_name(), true));
$token = new UsernamePasswordToken($user, null, $firewallName, array($role));
self::$kernel->getContainer()->get('session')->set('_security_' . $firewallName,
serialize($token));
これは 2.0.* では期待どおりに機能しますが、2.1 では機能しません。データはセッションに設定されません。
何か案は?
編集(さらに情報を追加):
問題はメソッド「onKernelResponse 」のファイル「Symfony\Component\Security\Http\Firewall\ContextListener 」にあるようです。このコードがあります:
if ((null === $token = $this->context->getToken()) || ($token instanceof AnonymousToken)) {
$session->remove('_security_'.$this->contextKey);
} else {
$session->set('_security_'.$this->contextKey, serialize($token));
}
私の場合、「$token instanceof AnonymousToken」が true の場合、そのためセッション キーが削除されます。そのコードをコメントアウトすると、すべてが期待どおりに機能します。
だから私は私の新しい質問は次のとおりだと思います: トークンを匿名にするにはどうすればよいですか?