【问题标题】:Symfony2 Avoiding duplicate/repeated properties in security.yml with multiple firewallsSymfony2 使用多个防火墙避免 security.yml 中的重复/重复属性
【发布时间】:2014-07-16 10:24:57
【问题描述】:

在我的应用程序中,我在 security.yml 中有两个防火墙(示例如下)。如您所见,“admin_secured_area”和“account_secured_area”防火墙具有非常相似的属性,只是偶尔会有所不同。我想知道有没有办法避免输入 2 次常用属性。例如,我可以从基础(父)防火墙继承属性吗?或者我可以从一个位置导入所需的属性吗?还是有其他选择?

  security:
      firewalls:
          admin_secured_area:
              stateless: true
              lexik_jwt:
                  authorization_header:
                      enabled: false
                  query_parameter:
                      enabled: true
                      name:    lexiktoken
                  throw_exceptions: true
                  create_entry_point: true
              entry_point: foobar.authentication_handler
              provider: in_memory
              pattern:    ^/admin
              form_login:
                  username_parameter: username
                  password_parameter: password
                  require_previous_session: false
                  success_handler:          lexik_jwt_authentication.handler.authentication_success
                  failure_handler:          lexik_jwt_authentication.handler.authentication_failure
                  check_path:  /admin/login
              logout:
                  path:   /admin/logout
                  success_handler: foobar.authentication_handler

          account_secured_area:
              stateless: true
              lexik_jwt:
                  authorization_header:
                      enabled: false
                  query_parameter:
                      enabled: true
                      name:    lexiktoken
                  throw_exceptions: true
                  create_entry_point: true
              entry_point: foobar.authentication_handler
              provider:   user_db
              pattern:    ^(/account)|(/reset-password)
              form_login:
                  username_parameter: username
                  password_parameter: password
                  require_previous_session: false
                  success_handler:          lexik_jwt_authentication.handler.authentication_success
                  failure_handler:          lexik_jwt_authentication.handler.authentication_failure
                  check_path:   /account/login
              logout:
                  path:   /account/logout
                  success_handler: foobar.authentication_handler

【问题讨论】:

    标签: symfony yaml


    【解决方案1】:

    应该可以使用参数。有关配置键“lexik_jwt”,请参见我的示例。

      security:
          parameters:
              lexik_jwt_settings: 
                  authorization_header:
                          enabled: false
                      query_parameter:
                          enabled: true
                          name:    lexiktoken
                      throw_exceptions: true
                      create_entry_point: true
          firewalls:
              admin_secured_area:
                  stateless: true
                  lexik_jwt: %lexik_jwt_settings%
                  entry_point: foobar.authentication_handler
                  provider: in_memory
                  pattern:    ^/admin
                  form_login:
                      username_parameter: username
                      password_parameter: password
                      require_previous_session: false
                      success_handler:          lexik_jwt_authentication.handler.authentication_success
                      failure_handler:          lexik_jwt_authentication.handler.authentication_failure
                      check_path:  /admin/login
                  logout:
                      path:   /admin/logout
                      success_handler: foobar.authentication_handler
    
              account_secured_area:
                  stateless: true
                  lexik_jwt: %lexik_jwt_settings%
                  entry_point: foobar.authentication_handler
                  provider:   user_db
                  pattern:    ^(/account)|(/reset-password)
                  form_login:
                      username_parameter: username
                      password_parameter: password
                      require_previous_session: false
                      success_handler:          lexik_jwt_authentication.handler.authentication_success
                      failure_handler:          lexik_jwt_authentication.handler.authentication_failure
                      check_path:   /account/login
                  logout:
                      path:   /account/logout
                      success_handler: foobar.authentication_handler
    

    【讨论】:

    • 感谢您的回复@sebbo,我会执行您的建议。理想情况下,我正在寻找一种解决方案,我可以定义所有“基本”参数,然后为每个单独的防火墙覆盖一些属性。 (类似于 Zend Framework 1 中的 .ini 文件)
    • @Sam 看看这里,我想这就是你要找的东西:rhnh.net/2011/01/31/yaml-tutorial
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多