Symfony2避免使用多个防火墙的security.yml中的重复/重复属性

时间:2014-07-16 10:24:58

标签: symfony yaml

在我的应用程序中,我在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

1 个答案:

答案 0 :(得分:2)

应该可以使用参数。请参阅我的示例以获取配置密钥“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