1

我制造了一个

应用程序/前端/配置/security.yml

dev:
 default:
  is_secure: false

prod:
 default:
  is_secure: true

但它不起作用,我错过了什么吗?

4

2 回答 2

3

正如史蒂夫所说, is_secure 不能在每个环境的基础上进行配置。

我的猜测是您正在尝试使用密码保护您的整个开发环境?我建议您使用 .htaccess/.htpasswd 保护或等效保护以这种方式保护站点。

如果您不能或出于任何原因想要在 symfony 中执行此操作,您可以通过创建自定义 sfSecurityConfigHandler.class.php 使 symfony 以这种方式接受配置

配置处理程序中有一个名为 getConfiguration 的方法——它负责获取在各种 yml 文件中设置的值,并在应用了所有覆盖等之后创建最终值的数组。

sfSecurityConfigHander.class.php 有一个这样的 getConfiguration:

static public function getConfiguration(array $configFiles)
{
  $config = self::flattenConfiguration(self::parseYamls($configFiles));

  // change all of the keys to lowercase
  $config = array_change_key_case($config);

  return $config;
}

而依赖于环境的配置,例如 sfDatabaseConfigHandler.class.php 具有这样的配置:

static public function getConfiguration(array $configFiles)
{
  $config = self::replaceConstants(self::flattenConfigurationWithEnvironment(self::parseYamls($configFiles)));

  foreach ($config as $name => $dbConfig)
  {
    if (isset($dbConfig['file']))
    {
      $config[$name]['file'] = self::replacePath($dbConfig['file']);
    }
  }

  return $config;
}

这里的关键区别在于使用 self::flattenConfigurationWithEnvironment 而不是 self::flattenConfiguration。我想如果你扩展 sfSecurityConfigHandler :

class mySecurityConfigHandler extends sfSecurityConfigHandler {
    static public function getConfiguration(array $configFiles)
    {
      $config = self::flattenConfigurationWithEnvironment(self::parseYamls($configFiles));

      // change all of the keys to lowercase
      $config = array_change_key_case($config);

      return $config;
    }
}

然后在你的配置中创建一个 config_handlers.yml 文件,告诉 symfony 使用这个类:

modules/*/config/security.yml:
  class:    sfSecurityConfigHandler
  file:     %sf_lib_dir%/path/to/mySecurityConfigHandler

然后,您应该能够根据问题使用 yml 来配置每个环境的安全性。

于 2010-02-21T14:03:39.117 回答
1

你到底想达到什么目的?我想你可能误解了is_secure财产的目的。

通常,它用于声明应用程序的哪些模块/操作需要身份验证(来自sfGuard等插件),而不是保护整个环境。

于 2010-02-21T11:29:02.673 回答