Symfony 2.3 FOSUserBundle does not find security.context

£可爱£侵袭症+ 提交于 2019-12-08 11:42:24

问题


I installed the FOS Bundle like mentioned in: https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.md

After installation with composer and setting up the user class i always get:

[Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException]
 The service "fos_user.security.login_manager" has a dependency on a non-exi
 stent service "security.context".

I checked the existence of the path and there is the contextinterface that is included in the fosuserbundle... Using the console always aborts with the same error. Anyone?

I enabled the bundle in appKernel (where the security bundle also is activated):

        ...
        new Symfony\Bundle\SecurityBundle\SecurityBundle(),
        ...
        new FOS\UserBundle\FOSUserBundle(),
        ...

I added the config to the config.yml:

# fos UserBundle config
fos_user:
    db_driver: orm
    firewall_name: main
    user_class: SDDB\MainBundle\Entity\User

I extended the routing.yml:

# USER AUTH STUFF

fos_user_security:
    resource: "@FOSUserBundle/Resources/config/routing/security.xml"

fos_user_profile:
    resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
    prefix: /profile

fos_user_register:
    resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
    prefix: /register

fos_user_resetting:
    resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
    prefix: /resetting

fos_user_change_password:
    resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
    prefix: /profile

and the security.yml:

security:
encoders:
    FOS\UserBundle\Model\UserInterface: sha512

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: ROLE_ADMIN

providers:
    fos_userbundle:
        id: fos_user.user_provider.username

firewalls:
    main:
        pattern: ^/
        form_login:
            provider: fos_userbundle
            csrf_provider: form.csrf_provider
        logout:       true
        anonymous:    true

access_control:
    - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/admin/, role: ROLE_ADMIN }

回答1:


Ok i found the solution with help of a developer of FOS Bundle.

If you have a simmilar problem go through some basic stuff:

  1. Is the FOS Bundle version fitting for your Symfony version?
  2. Is security bundle proper installed?
  3. Is it activated in the appkernel?
  4. Is there a configuration file for it (security.yml)?
  5. Is it inlcuded properly in the (main)config.yml?

I had a dumb typo in the include line at point (4)...




回答2:


Add :
- { resource: security.yml } to the import section in the main config.yml, it solved the problem for me




回答3:


  1. Check whether the service file exists (SecurityBundle\Resources\config\security.xml)
  2. Check whether the service file is loaded (SecurityBundle\DependencyInjection\SecurityExtension.php)


来源:https://stackoverflow.com/questions/18126393/symfony-2-3-fosuserbundle-does-not-find-security-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!