0

カスタム データを使用してセキュリティ コンテキストを設定する方法があります。

$userEntity = new User();
$userEntity->fromArray($user);

$token           = new UsernamePasswordToken($userEntity, $userEntity->getPassword(), 'secured_area', $userEntity->getRoles());
$session = $this->container->get('session');
$session->set('_security_secured_area', serialize($token));

$this->container->get('security.authentication.manager')->authenticate($token);
$this->container->get('security.context')->setToken($token);

curl を使用して別のアプリケーションからユーザー データを取得し、それをローカルの「ログに記録されたユーザー」として保存したいと考えています。動作しますが、security.context でページをリロード/リダイレクトした後、同じ ID を持つユーザーのローカル データベースから新しいデータを取得します。

複雑に見えるかもしれないと思うので、質問は次のとおりです。

$this->get('security.context')->getToken()->getUser()Symfonyを実行すると、セッションからではなく、データベースからユーザーを取得するのはなぜですか?

4

0 に答える 0