私はServiceB(有権者)に循環参照を取得するためにServiceA(is_grantedに基づいてエンティティを取得するために使用される)を挿入しようとしています。この問題を回避するためにとにかくなど循環参照が有権者サービスにセキュリティサービスを注入する
サービスAがロードされたときにそのauthentication_checker依存性がSERVICEAを必要とServiceBを含み、すべての有権者が、ロードしようとするので、私は信じている...
?
YAMLのサービスマッピング:
services:
app.security_service:
class: AppBundle\Service\appSecurityService
arguments: [ "@logger", "@doctrine", "@security.authorization_checker", "@security.token_storage" ]
app.entity_voter:
class: AppBundle\Security\ChargebackNotificationVoter
public: false
tags:
- { name: security.voter }
arguments: [ "@logger", "@doctrine", "@app.security_service" ]
私はSERVICEA
にpublic function getEntitiesForUser(UserInterface $user)
{
$user = $this->tokenStorage->getToken()->getUser();
if($this->authorizationChecker->isGranted('ROLE_SYSTEM_ADMIN')){
//If the user has ROLE_SYSTEM_ADMIN get all the entities
$entitiess = $this->managerRegistry->getRepository('AppBundle:Entities')->findAll();
}elseif($this->authorizationChecker->isGranted('ROLE_ORGANIZATION_ADMIN')){
//ElseIf the user has ROLE_ORGANIZATION_ADMIN get all the entitiess that belong to the organization
$entitiess = $user->getOrganization()->getEntities();
} elseif($this->authorizationChecker->isGranted('ROLE_USER')) {
$entitiess = $this->managerRegistry->getRepository('AppBundle:Entities')->findByUser($user);
} else {
//if ROLE_USER is missing return null
$entitiess = null;
}
return $entities;
}
をやっているものの例は、私がサービスのために検出
循環参照を取得し、エラーを..and "security.authorization_checker"、パス: "twig.controller.exception - > twig - > security.authorization_checker - > security.access.decision_manager - > ccp.chargebacknotification_voter - > ccp.security_service "を参照してください。
を使用
をServiceAのユーザオブジェクトから、そしてin_arrayまたは - > containsをチェックしてロールをチェックすると、security.auth_checkerが必要です。ベストプラクティスのドキュメントではsecurity.auth_checkerを使用してロールをチェックします:/ –
どのSymfonyのバージョンあなたが使う? – xabbuh
symfony3、私はIRCチャンネルでも尋ねました。サービスがsecurity.authentication_checkerに依存している限り、それは有権者に注入することはできません。私の現在の回避策は、ユーザーオブジェクトにhasRoleメソッドを追加し、それを使用してサービスのロールをチェックすることで、security.auth_checkerの依存関係を削除し、問題なく私の投票者に注入できるようにします –