我的网站正在使用第三方服务进行身份验证以及其他功能,因此我设置了一项服务,为我执行所有API调用,这是我需要能够访问用户对象的服务.我已经尝试将security.context服务注入到我的API服务中,但是我收到了ServiceCircularReferenceException,因为我的用户身份验证提供程序引用了API服务(它必须为了对用户进行身份验证).所以我得到一个链
security.context -> authentication provider ->
user provider -> API service -> security.context
Run Code Online (Sandbox Code Playgroud)
我正在努力获得另一种获取用户对象的方式,我看不出任何明显的方式来分割这个链.
我的配置都在config.yml中定义,这里是相关的位
myapp.database:
class: Pogo\MyAppBundle\Service\DatabaseService
arguments:
siteid: %siteid%
entityManager: "@doctrine.orm.entity_manager"
myapp.apiservice:
class: Pogo\MyAppBundle\Service\TicketingService
arguments:
entityManager: "@myapp.database"
myapp.user_provider:
class: Pogo\MyAppBundle\Service\APIUserProvider
arguments:
entityManager: "@myapp.database"
ticketingAdapter: "@myapp.apiservice"
securityContext: "@security.context"
myapp.authenticationprovider:
class: Pogo\MyAppBundle\Service\APIAuthenticationProvider
arguments:
userChecker: "@security.user_checker"
encoderFactory: "@security.encoder_factory"
userProvider: "@myapp.user_provider"
Run Code Online (Sandbox Code Playgroud)
myapp.user_provider是我在security.yml中定义为我的用户提供者服务的服务,我认为它是由security.context引用的.
我找到了一个临时的解决方法,但它不是很干净。您可以将整个注入@service_container
到您的服务中并仅从security.context
中使用。但是,您必须将整个容器设置为类属性。如果您仅在构造函数中使用安全上下文,它仍然会抛出循环引用异常。