Apache Solr open-source search software
SOLR-18167: Fix deprecated sysprop migration for camelCase flags (#4507)
Utsav81599b4081c5
diff --git a/changelog/unreleased/SOLR-18167-old-to-new-prop.yml b/changelog/unreleased/SOLR-18167-old-to-new-prop.ymlnew file mode 100644index 00000000000..0d0718e20b3--- /dev/null+++ b/changelog/unreleased/SOLR-18167-old-to-new-prop.yml@@ -0,0 +1,7 @@+title: "Solr 9 to 10 upgrade: old JWT property solr.auth.jwt.allowOutboundHttp set via SOLR_OPTS now correctly maps to solr.auth.jwt.outbound.http.enabled, fixing a startup failure when connecting to an HTTP identity provider."+type: fixed+authors:+ - name: Utsav Parmar+links:+ - name: SOLR-18167+ url: https://issues.apache.org/jira/browse/SOLR-18167diff --git a/solr/solrj/src/java/org/apache/solr/common/util/EnvUtils.java b/solr/solrj/src/java/org/apache/solr/common/util/EnvUtils.javaindex d557f726b97..d0b24ca0f31 100644--- a/solr/solrj/src/java/org/apache/solr/common/util/EnvUtils.java+++ b/solr/solrj/src/java/org/apache/solr/common/util/EnvUtils.java@@ -216,34 +216,40 @@ public class EnvUtils {}}- // Convert deprecated keys to non deprecated versions- for (String key : sysProperties.stringPropertyNames()) {- if (DEPRECATED_MAPPINGS.containsKey(key) || DEPRECATED_MAPPINGS.containsKey("!" + key)) {- String deprecatedKey = key;- boolean invertValue = false;- key = DEPRECATED_MAPPINGS.get(deprecatedKey);- if (key == null) {- key = DEPRECATED_MAPPINGS.get("!" + deprecatedKey);- invertValue = true;- }- log.warn(- "You are passing in deprecated system property {} and should upgrade to using {} instead. The deprecated property support will be removed in future version of Solr.",- deprecatedKey,- key);-- if (invertValue) {- log.warn(- "Converting from legacy system property {} to modern equivalent {} by inverting the boolean value.",- deprecatedKey,- key);- setProperty(key, String.valueOf(!Boolean.getBoolean(deprecatedKey)));- } else {- setProperty(key, sysProperties.getProperty(deprecatedKey));- }+ for (String deprecatedKey : sysProperties.stringPropertyNames()) {+ String lookupKey = findDeprecatedMappingKey(deprecatedKey);+ if (lookupKey != null) {+ applyDeprecatedPropertyMapping(deprecatedKey, lookupKey, sysProperties);}}}+ // "-D" flags land in system properties as typed - often camelCase - but our mapping file uses+ // dot-separated keys, so normalise before looking up.+ private static String findDeprecatedMappingKey(String sysPropKey) {+ var dotKey = camelCaseToDotSeparated(sysPropKey);+ return isInDeprecatedMappings(dotKey) ? dotKey : null;+ }++ private static boolean isInDeprecatedMappings(String key) {+ return DEPRECATED_MAPPINGS.containsKey(key) || DEPRECATED_MAPPINGS.containsKey("!" + key);+ }++ private static void applyDeprecatedPropertyMapping(+ String deprecatedKey, String lookupKey, Properties sysProperties) {+ var newPropName =+ DEPRECATED_MAPPINGS.getOrDefault(lookupKey, DEPRECATED_MAPPINGS.get("!" + lookupKey));+ var newValue =+ DEPRECATED_MAPPINGS.containsKey(lookupKey)+ ? sysProperties.getProperty(deprecatedKey)+ : String.valueOf(!Boolean.getBoolean(deprecatedKey));+ log.warn(+ "Deprecated system property {} has been replaced by {}. Support for the old property will be removed in a future version of Solr.",+ deprecatedKey,+ newPropName);+ setProperty(newPropName, newValue);+ }+protected static String envNameToSyspropName(String envName) {return CUSTOM_MAPPINGS.containsKey(envName)? CUSTOM_MAPPINGS.get(envName)diff --git a/solr/solrj/src/test/org/apache/solr/common/util/EnvUtilsTest.java b/solr/solrj/src/test/org/apache/solr/common/util/EnvUtilsTest.javaindex 7b360dd49cf..cce0a483bcb 100644--- a/solr/solrj/src/test/org/apache/solr/common/util/EnvUtilsTest.java+++ b/solr/solrj/src/test/org/apache/solr/common/util/EnvUtilsTest.java@@ -110,6 +110,14 @@ public class EnvUtilsTest extends SolrTestCase {assertEquals("xml,json,jar", EnvUtils.getProperty("solr.configset.forbidden.file.types"));}+ @Test+ public void deprecatedCamelCaseDFlagIsTranslatedToCurrentPropertyName() {+ Properties sysprops = new Properties();+ sysprops.setProperty("solr.auth.jwt.allowOutboundHttp", "true");+ EnvUtils.init(false, Map.of(), sysprops);+ assertTrue(EnvUtils.getPropertyAsBool("solr.auth.jwt.outbound.http.enabled"));+ }+@Testpublic void testFlippingDisabledToEnabledPropertyName() {