示例#1
0
 private void transformToSystemSettingsFormat(Map<String, String> map) {
   for (Map.Entry<String, String> e : map.entrySet()) {
     SystemSetting prop = SystemSetting.getByInternalName(e.getKey());
     if (prop != null) {
       // this is a legacy method that supplies values in the DB-specific format.
       // we therefore have to transform the values as if they came from the database.
       String value = transformSystemConfigurationPropertyFromDb(prop, e.getValue(), false);
       e.setValue(value);
     }
   }
 }
示例#2
0
  private void checkFormats(SystemSettings settings, Properties config) {
    assert settings.size() == config.size()
        : "The old and new style system settings differ in size";

    for (String name : config.stringPropertyNames()) {
      SystemSetting setting = SystemSetting.getByInternalName(name);

      String oldStyleValue = config.getProperty(name);
      String newStyleValue = settings.get(setting);

      assert setting != null : "Could not find a system setting called '" + name + "'.";

      switch (setting) {
        case USE_SSL_FOR_LDAP:
          if (RHQConstants.LDAP_PROTOCOL_SECURED.equals(oldStyleValue)) {
            assert Boolean.valueOf(newStyleValue)
                : "Secured LDAP protocol should be represented by a 'true' in new style settings.";
          } else if (RHQConstants.LDAP_PROTOCOL_UNSECURED.equals(oldStyleValue)) {
            assert !Boolean.valueOf(newStyleValue)
                : "Unsecured LDAP protocol should be represented by a 'false' in the new style settings.";
          } else {
            assert false
                : "Unknown value for system setting '" + setting + "': [" + oldStyleValue + "].";
          }
          break;
        case LDAP_BASED_JAAS_PROVIDER:
          if (RHQConstants.LDAPJAASProvider.equals(oldStyleValue)) {
            assert Boolean.valueOf(newStyleValue)
                : "LDAP JAAS provider should be represented by a 'true' in new style settings.";
          } else if (RHQConstants.JDBCJAASProvider.equals(oldStyleValue)) {
            assert !Boolean.valueOf(newStyleValue)
                : "JDBC JAAS provider should be represented by a 'false' in the new style settings.";
          } else {
            assert false
                : "Unknown value for system setting '" + setting + "': [" + oldStyleValue + "].";
          }
          break;
        default:
          assert oldStyleValue != null
                  && newStyleValue != null
                  && oldStyleValue.equals(newStyleValue)
              : "Old and new style values unexpectedly differ for system setting '"
                  + setting
                  + "': old=["
                  + oldStyleValue
                  + "], new=["
                  + newStyleValue
                  + "].";
      }
    }
  }
示例#3
0
  private void fillCache(Collection<SystemConfiguration> configs) {
    SystemSettings settings = new SystemSettings();

    for (SystemConfiguration config : configs) {
      SystemSetting prop = SystemSetting.getByInternalName(config.getPropertyKey());
      if (prop == null) {
        LOG.warn(
            "The database contains unknown system configuration setting ["
                + config.getPropertyKey()
                + "].");
        continue;
      }

      if (config.getPropertyValue() == null) {
        // for some reason, the configuration is not found in the DB, so fallback to the persisted
        // default.
        // if there isn't even a persisted default, just use an empty string.
        String defaultValue = config.getDefaultPropertyValue();
        defaultValue = transformSystemConfigurationPropertyFromDb(prop, defaultValue, true);
        settings.put(prop, defaultValue);
      } else {
        String value = config.getPropertyValue();
        value = transformSystemConfigurationPropertyFromDb(prop, value, true);
        settings.put(prop, value);
      }
    }

    settings.setDriftPlugins(getDriftServerPlugins());

    synchronized (this) {
      // only update the caches if the settings were actually changed
      if (cachedSystemSettings == null
          || !safeEquals(
              cachedSystemSettings.get(SystemSetting.LAST_SYSTEM_CONFIG_UPDATE_TIME),
              settings.get(SystemSetting.LAST_SYSTEM_CONFIG_UPDATE_TIME))) {
        cachedSystemSettings = settings;

        cachedObfuscatedSystemSettings = new SystemSettings(settings);
        for (Map.Entry<SystemSetting, String> entry : cachedObfuscatedSystemSettings.entrySet()) {
          String value = entry.getValue();
          if (value != null && entry.getKey().getType() == PropertySimpleType.PASSWORD) {
            entry.setValue(PicketBoxObfuscator.encode(value));
          }
        }
      }
    }
  }