子节点"秘密"在路径" security.firewalls.main.remember_me"必须配置

时间:2015-10-07 13:42:21

标签: php symfony login remember-me

我在SO上看过类似的问题,但找不到我的问题的答案。 Symfony2 documentation解释了如何实现记住我的功能。

这是我的parameters.yml

# This file is auto-generated during the composer install parameters:
database_host: 127.0.0.1
database_port: null
database_name: symfony
database_user: root
database_password: null
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null

# A secret key that's used to generate certain security-related tokens
secret: DSHJLREYQF98321BN23B1100F

这是我的security.yml

security:

    providers:
        in_memory:
            memory:
                users:
                    user1:
                        password: user1
                        roles: 'ROLE_USER'
                    user2:
                        password: user2
                        roles: 'ROLE_USER'
                    admin:
                        password: admin
                        roles: 'ROLE_ADMIN'

    firewalls:
        default:
            remember_me:
                key:      "%secret%"
                lifetime: 604800 # 1 week in seconds
                path:     /

        # Need to create route in routing.yml, but no need in a controller
        secured_area:
            logout:
                path:   /logout
                target: /

        # disables authentication for js,css, images, etc...
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

        # fallback -> types of authentication
        main:
            anonymous: ~
            form_login:
                login_path: homepage
                check_path: login_check
                default_target_path: homepage
                failure_path: homepage
            remember_me:
                key:      "%secret%"
                lifetime: 604800 # 1 week in seconds
                path:     /

    encoders:
        # algorithm to encode passwords
        Symfony\Component\Security\Core\User\User: plaintext

    role_hierarchy:
        # admin is user too
        ROLE_ADMIN:       ROLE_USER

    access_control:
        # require ROLE_ADMIN for admin page 
        - { path: ^/restricted/admin, roles: ROLE_ADMIN }
        # require ROLE_USER for user pages
        - { path: ^/restricted/user, roles: ROLE_USER }
        # The login form is embedded in the home page
        - { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY }

但是我收到以下错误消息:

InvalidConfigurationException in ArrayNode.php line 237:
The child node "secret" at path "security.firewalls.main.remember_me" must be configured.

我做错了什么?

更新

我已将key: "%secret%"更改为secret: "%secret%"。错误消失了,但抛出了一个新错误:

You must configure at least one remember-me aware listener
(such as form-login) for each firewall that has remember-me enabled.

我通过移动remember_me:防火墙下的main配置解决了这个问题。

    main:
        anonymous: ~
        form_login:
            login_path: homepage
            check_path: login_check
            default_target_path: homepage
            failure_path: homepage
        logout:
            path:   /logout
            target: /
        remember_me:
            secret:      "%secret%"
            lifetime: 604800 # 1 week in seconds
            path:     /

1 个答案:

答案 0 :(得分:4)

key参数在2.8版本的某个地方未经文档重命名为secret ...所以你应该这样做:

    remember_me:
        secret:      "%secret%"
        lifetime: 604800 # 1 week in seconds
        path:     /

请参阅https://github.com/symfony/symfony-docs/pull/5761