wrap system properties instead of direct modification

This commit is contained in:
Armin Schrenk
2026-02-11 14:36:55 +01:00
parent 5db05d8bc7
commit cff47b1c73
2 changed files with 10 additions and 8 deletions

View File

@@ -53,23 +53,25 @@ class AdminPropertiesSetter {
static Properties adjustSystemProperties() {
var systemProps = System.getProperties();
final String systemPropertyDefinedAdminFile = System.getProperty(ADMIN_PROP_FILE_KEY);
if (systemPropertyDefinedAdminFile == null) {
final String adminCfgPath = System.getProperty(ADMIN_PROP_FILE_KEY);
if (adminCfgPath == null) {
LOG.debug("Path to admin properties file is not defined.");
return systemProps;
}
var adminProps = loadAdminProperties(Path.of(systemPropertyDefinedAdminFile));
var adminProps = loadAdminProperties(Path.of(adminCfgPath));
var newSystemProps = new Properties(systemProps);
for (var key : adminProps.stringPropertyNames()) {
if (ALLOWED_OVERRIDES.contains(key)) {
var value = adminProps.getProperty(key);
LOG.info("Overwriting {} with value {} from admin properties.", key, value);
systemProps.setProperty(key, value);
LOG.info("Overwriting {} with value {} from admin config.", key, value);
newSystemProps.setProperty(key, value);
} else {
LOG.debug("Property {} in admin properties is not supported for override.", key);
LOG.debug("Property {} in admin config is not supported for override.", key);
}
}
return systemProps;
System.setProperties(newSystemProps);
return newSystemProps;
}
//visible for testing

View File

@@ -79,7 +79,7 @@ public class AdminPropertiesSetterTest {
}
@Test
@DisplayName("If system property for config path is null, skip do not load anything")
@DisplayName("If system property for config path is null, skip loading and replacing")
void skipAdjustSystemPropertiesOnUndefinedProperty() {
Assertions.assertNull(System.getProperty("cryptomator.adminConfigPath"));