Controller アクションがあります (Controller はJMSDiExtraBundle 経由で$this->securityContext
設定されています):$this->get('security.context')
$user = $this->securityContext->getToken()->getUser();
$groupRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Group');
if ($this->securityContext->isGranted('ROLE_ADMIN') === false) {
$myGroups = $groupRepo->findByLeader($user);
} else {
$myGroups = $groupRepo->findAll();
}
環境にログインしてdev
プロファイラーを確認すると、ROLE_ADMIN
ロールが付与されていることがわかりますが、フィルタリングされたグループのリストが表示されます。
Controller と Symfony のRoleVoter.php
. コントローラー ( $this->securityContext->getToken()
)内のトークンの文字列表現と 内のトークンの文字列表現RoleVoter.php
は同じですが、 を使用する$token->getRoles()
と、2 つの異なる配列が得られます。
マイ ユーザーとロールは、ユーザー エンティティとロール エンティティを介してデータベースに保存されます。これは私が見つけたバグですか、それとも何か間違っていますか?