title: Symfony protect with HTTP Basic Authentication
body: <p>I have an existing site built with Symfony 2.8 and I would like to add an extra layer of security by enabling HTTP Basic Auth <strong>only when a parameter is set to true</strong> in parameters.yml. Is it possible?</p>
  
  <p>The site already has a form login enabled but I would like to <strong>hide the site completely</strong> with basic authentication if the parameter is <code>true</code>.</p>
  
  <p>This is my security.yml:</p>
  
  <pre><code>main:
      pattern:             .*
      context:             user
      form_login:
          provider:       fos_userbundle
          login_path:     /user/login
          use_forward:    false
          check_path:     /user/login_check
          failure_path:   null
          default_target_path: /
      logout:
          path:           /user/logout
          target:         /user/login
      anonymous:          true
  </code></pre>