11

我已经下载并安装了 Symfony2 标准版。我已经完成了github 自述文件中详述的所有步骤,以删除用作框架演示的 AcmeBundle。尝试访问控制台以仔细检查我的路线时:

$ php app/console router:debug

我收到以下错误:

[Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]  
The child node "providers" at path "security" must be configured. 

当我在我的security.yml文件中取消删除 security.providers 时,我只剩下:

jms_security_extra:
    secure_all_services: false
    expressions: true

security:
    encoders:
        Symfony\Component\Security\Core\User\User: plaintext

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

    providers:
        in_memory:
            memory:
                users:
                    user: { password: userpass, roles: [ 'ROLE_USER' ] }
                    admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }

    firewalls:
        dev:
            pattern:  ^/(_(profiler|wdt)|css|images|js)/
            security: false

    access_control:
        #- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
        #- { path: ^/_internal/secure, roles: IS_AUTHENTICATED_ANONYMOUSLY, ip: 127.0.0.1 }

我得到一个不同但类似的错误:

[InvalidArgumentException]                          
You must at least add one authentication provider.

我不知道该怎么做才能修复它。有什么解决办法吗?

4

2 回答 2

20

你需要提供,像这样的配置:

jms_security_extra:
    secure_all_services: false
    expressions: true

security:
    encoders:
        Symfony\Component\Security\Core\User\User: plaintext

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

    providers:
        in_memory:
            memory:
                users:
                    user:  { password: userpass, roles: [ 'ROLE_USER' ] }
                    admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }

    firewalls:
        dev:
            pattern:  ^/(_(profiler|wdt)|css|images|js)/
            security: false

        login:
            security: false

        secured_area:
            anonymous: ~

    access_control:
        #- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
        #- { path: ^/_internal/secure, roles: IS_AUTHENTICATED_ANONYMOUSLY, ip: 127.0.0.1 }
于 2012-10-23T02:33:41.537 回答
10

对我来说,我可以获得的最小文件无一例外是:

security:
    firewalls:
        anonymous:
            anonymous: ~

    providers:
        in_memory:
            memory:

Symfony 2.3.3。

于 2013-08-26T18:04:52.320 回答