Skip to content

Commit 81599b4

Browse files
utsav00epugh
andauthored
SOLR-18167: Fix deprecated sysprop migration for camelCase flags (#4507)
Co-authored-by: Eric Pugh <epugh@opensourceconnections.com>
1 parent ddb1923 commit 81599b4

3 files changed

Lines changed: 45 additions & 24 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
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."
2+
type: fixed
3+
authors:
4+
- name: Utsav Parmar
5+
links:
6+
- name: SOLR-18167
7+
url: https://issues.apache.org/jira/browse/SOLR-18167

solr/solrj/src/java/org/apache/solr/common/util/EnvUtils.java

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -216,34 +216,40 @@ static synchronized void init(
216216
}
217217
}
218218

219-
// Convert deprecated keys to non deprecated versions
220-
for (String key : sysProperties.stringPropertyNames()) {
221-
if (DEPRECATED_MAPPINGS.containsKey(key) || DEPRECATED_MAPPINGS.containsKey("!" + key)) {
222-
String deprecatedKey = key;
223-
boolean invertValue = false;
224-
key = DEPRECATED_MAPPINGS.get(deprecatedKey);
225-
if (key == null) {
226-
key = DEPRECATED_MAPPINGS.get("!" + deprecatedKey);
227-
invertValue = true;
228-
}
229-
log.warn(
230-
"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.",
231-
deprecatedKey,
232-
key);
233-
234-
if (invertValue) {
235-
log.warn(
236-
"Converting from legacy system property {} to modern equivalent {} by inverting the boolean value.",
237-
deprecatedKey,
238-
key);
239-
setProperty(key, String.valueOf(!Boolean.getBoolean(deprecatedKey)));
240-
} else {
241-
setProperty(key, sysProperties.getProperty(deprecatedKey));
242-
}
219+
for (String deprecatedKey : sysProperties.stringPropertyNames()) {
220+
String lookupKey = findDeprecatedMappingKey(deprecatedKey);
221+
if (lookupKey != null) {
222+
applyDeprecatedPropertyMapping(deprecatedKey, lookupKey, sysProperties);
243223
}
244224
}
245225
}
246226

227+
// "-D" flags land in system properties as typed - often camelCase - but our mapping file uses
228+
// dot-separated keys, so normalise before looking up.
229+
private static String findDeprecatedMappingKey(String sysPropKey) {
230+
var dotKey = camelCaseToDotSeparated(sysPropKey);
231+
return isInDeprecatedMappings(dotKey) ? dotKey : null;
232+
}
233+
234+
private static boolean isInDeprecatedMappings(String key) {
235+
return DEPRECATED_MAPPINGS.containsKey(key) || DEPRECATED_MAPPINGS.containsKey("!" + key);
236+
}
237+
238+
private static void applyDeprecatedPropertyMapping(
239+
String deprecatedKey, String lookupKey, Properties sysProperties) {
240+
var newPropName =
241+
DEPRECATED_MAPPINGS.getOrDefault(lookupKey, DEPRECATED_MAPPINGS.get("!" + lookupKey));
242+
var newValue =
243+
DEPRECATED_MAPPINGS.containsKey(lookupKey)
244+
? sysProperties.getProperty(deprecatedKey)
245+
: String.valueOf(!Boolean.getBoolean(deprecatedKey));
246+
log.warn(
247+
"Deprecated system property {} has been replaced by {}. Support for the old property will be removed in a future version of Solr.",
248+
deprecatedKey,
249+
newPropName);
250+
setProperty(newPropName, newValue);
251+
}
252+
247253
protected static String envNameToSyspropName(String envName) {
248254
return CUSTOM_MAPPINGS.containsKey(envName)
249255
? CUSTOM_MAPPINGS.get(envName)

solr/solrj/src/test/org/apache/solr/common/util/EnvUtilsTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ public void testDeprecated() {
110110
assertEquals("xml,json,jar", EnvUtils.getProperty("solr.configset.forbidden.file.types"));
111111
}
112112

113+
@Test
114+
public void deprecatedCamelCaseDFlagIsTranslatedToCurrentPropertyName() {
115+
Properties sysprops = new Properties();
116+
sysprops.setProperty("solr.auth.jwt.allowOutboundHttp", "true");
117+
EnvUtils.init(false, Map.of(), sysprops);
118+
assertTrue(EnvUtils.getPropertyAsBool("solr.auth.jwt.outbound.http.enabled"));
119+
}
120+
113121
@Test
114122
public void testFlippingDisabledToEnabledPropertyName() {
115123

0 commit comments

Comments
 (0)