Beispiel #1
0
 /**
  * Call this to transform a system setting to a more appropriate value. Importantly, this
  * (de)obfuscates the password fields as they go from and to the DB. We use the @{link
  * PicketBoxObfuscator} so that people are able encode their passwords in the system settings
  * export files using the "rhq-encode-password.sh" script.
  */
 private String transformSystemConfigurationPropertyFromDb(
     SystemSetting prop, String value, boolean unobfuscate) {
   // to support Oracle (whose booleans may be 1 or 0) transform the boolean settings properly
   switch (prop) {
     case LDAP_BASED_JAAS_PROVIDER:
       if (RHQConstants.JDBCJAASProvider.equals(value)) {
         return Boolean.toString(false);
       } else if (RHQConstants.LDAPJAASProvider.equals(value)) {
         return Boolean.toString(true);
       } else {
         return value == null ? "" : value;
       }
     case USE_SSL_FOR_LDAP:
       if (RHQConstants.LDAP_PROTOCOL_SECURED.equals(value)) {
         return Boolean.toString(true);
       } else {
         return Boolean.toString(false);
       }
     default:
       switch (prop.getType()) {
         case BOOLEAN:
           if ("0".equals(value)) {
             return Boolean.FALSE.toString();
           } else if ("1".equals(value)) {
             return Boolean.TRUE.toString();
           } else {
             return value == null ? Boolean.FALSE.toString() : value;
           }
         case PASSWORD:
           if (unobfuscate && value != null && value.trim().length() > 0) {
             return PicketBoxObfuscator.decode(value);
           } else {
             return value == null ? "" : value;
           }
         default:
           if (value == null) {
             switch (prop.getType()) {
               case DOUBLE:
               case FLOAT:
               case INTEGER:
               case LONG:
                 value = "0";
                 break;
               default:
                 value = "";
             }
           }
           return value;
       }
   }
 }
Beispiel #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
                  + "].";
      }
    }
  }