Symfony 2.3 FOSUserBundle没有找到security.context[英] Symfony 2.3 FOSUserBundle does not find security.context

本文是小编为大家收集整理的关于Symfony 2.3 FOSUserBundle没有找到security.context的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我安装了如下所述的FOS捆绑包: /Resources/doc/index.md

与作曲家安装并设置用户类,我总是得到:

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

我检查了路径的存在,并且有fosuserbundle中包含的上下文表... 使用控制台始终以相同的错误中止. 有人吗?

我启用了AppKernel中的捆绑包(在其中也激活了安全捆绑包):

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

我将配置添加到config.yml:

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

我扩展了路由:

# 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

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 }

推荐答案

好的,我在FOS捆绑包的开发人员的帮助下找到了解决方案.

如果您有一个类似的问题,请通过一些基本内容:

  1. FOS捆绑版版本适合您的Symfony版本?
  2. 安全捆绑包是否适当安装?
  3. 它是否在Appkernel中激活?
  4. 是否有一个配置文件(security.yml)?
  5. 它是否正确地插入了(main)config.yml?

我在(4)...

点的包含行中有一个哑巴错字

其他推荐答案

添加:
- {resource:security.yml}到主config.yml中的导入部分,它解决了我的问题

其他推荐答案

  1. 检查服务文件是否存在(SecurityBundle \ Resources \ Config \ Config \ Security.xml)
  2. 检查服务文件是否已加载(SecurityBundle \ disterencyInjection \ SecurityExtension.php)

本文地址:https://www.itbaoku.cn/post/2090803.html

问题描述

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 }

推荐答案

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)...

其他推荐答案

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

其他推荐答案

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