Symfony无法识别的选项" csrf_token_generator"在" security.firewalls.main"

时间:2017-09-26 06:02:23

标签: php symfony fosuserbundle symfony-2.8

此问题已在stackoverflow上提出。我正在实施symfony的FOSUserBundle。我已根据这些问题的解决方案配置了所有内容,但我在运行时仍然遇到此错误

datwe[v] <- lapply(datwe[v],
                   function(x){ifelse(x=="FoO","4",
                                      ifelse(x=="XYZ","5",
                                             ifelse(strtrim(x,3)=="ABC","-100",x)))})

security.yml

php app/console doctrine:schema:update --force

 [Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]
  Unrecognized option "csrf_token_generator" under "security.firewalls.main"

config.yml

security:

encoders:
    FOS\UserBundle\Model\UserInterface: bcrypt
role_hierarchy:
    ROLE_ADMIN:       ROLE_USER    
# https://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded
providers:
    fos_userbundle:
        id: fos_user.user_provider.username

firewalls:
    # disables authentication for assets and the profiler, adapt it according to your needs
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false

    main:
        form_login:
            login_path: login
            check_path: login
        pattern:    ^/
        http_basic: ~
        provider: fos_userbundle
        csrf_token_generator: security.csrf.token_manager
        # activate different ways to authenticate

        # https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate
        #http_basic: ~

        # https://symfony.com/doc/current/security/form_login_setup.html
        #form_login: ~
        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 }        

AppKernel.php

framework:
#esi: ~
#translator: { fallbacks: ['%locale%'] }
translator: ~
secret: '%secret%'
router:
    resource: '%kernel.root_dir%/config/routing.yml'
    strict_requirements: ~
form: ~
csrf_protection: 
    enabled: true
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
    engines: ['twig']
default_locale: '%locale%'
trusted_hosts: ~
trusted_proxies: ~
session:
    # handler_id set to null will use default session handler from php.ini
    handler_id: ~
fragments: ~
http_method_override: true

我有什么遗漏的吗?非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

属性csrf_token_generator: security.csrf.token_manager应放在form_login

下方
firewalls:
    main:
        form_login:
            login_path: login
            check_path: login
            csrf_token_generator: security.csrf.token_manager