How can I get the user object from a service in Symfony2
Posted
by
pogo
on Stack Overflow
See other posts from Stack Overflow
or by pogo
Published on 2011-06-17T15:36:33Z
Indexed on
2011/06/27
16:22 UTC
Read the original article
Hit count: 296
symfony-2.0
My site is using a third party service for authentication as well as other bits of functionality so I have setup a service that does all the API calls for me and it's this service that I need to be able to access the user object. I've tried injecting the security.context service into my API service but I get a ServiceCircularReferenceException because my user authentication provider references the API service (it has to in order to authenticate the user). So I get a chain of
security.context -> authentication provider ->
user provider -> API service -> security.context
I'm struggling to this of another way of getting the user object and I can't see any obvious way of splitting up this chain.
My configs are all defined in config.yml, here are the relevant bits
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"
myapp.user_provider is the service that I've defined as my user provider service in security.yml which I presume is how it's being referenced by security.context
© Stack Overflow or respective owner