.setDescription("List settings values.<br>" +
"If no value has been set for a setting, then the default value is returned.<br>" +
"The settings from conf/sonar.properties are excluded from results.<br>" +
- "Requires 'Browse' or 'Execute Analysis' permission when a component is specified.<br/>")
+ "Requires 'Browse' or 'Execute Analysis' permission when a component is specified.<br/>" +
+ "Secured settings are not returned by the endpoint.<br/>")
.setResponseExample(getClass().getResource("values-example.json"))
.setSince("6.3")
.setChangelog(
- new Change("9.1", "The value of secured settings are no longer returned"),
+ new Change("9.1", "The secured settings are no longer returned."),
new Change("7.6", String.format("The use of module keys in parameter '%s' is deprecated", PARAM_COMPONENT)),
new Change("7.1", "The settings from conf/sonar.properties are excluded from results."))
.setHandler(this);
private void processSettings() {
settings.forEach(setting -> {
+ if (isSecured(setting.getKey())) {
+ if (!setting.isDefault()) {
+ valuesWsBuilder.addSetSecuredSettings(setting.getKey());
+ }
+ return;
+ }
Settings.Setting.Builder valueBuilder = getOrCreateValueBuilder(keysToDisplayMap.get(setting.getKey()));
setInherited(setting, valueBuilder);
setValue(setting, valueBuilder);
}
private void setValue(Setting setting, Settings.Setting.Builder valueBuilder) {
- if (isSecured(setting.getKey())) {
- return;
- }
PropertyDefinition definition = setting.getDefinition();
String value = setting.getValue();
if (definition == null) {
ValuesWsResponse result = executeRequestForGlobalProperties();
- assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("foo", "secret.secured");
+ assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("foo");
+ assertThat(result.getSetSecuredSettingsList()).containsOnly("secret.secured");
}
@Test
ValuesWsResponse result = executeRequestForProjectProperties();
- assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("foo", "global.secret.secured", "secret.secured");
+ assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("foo");
+ assertThat(result.getSetSecuredSettingsList()).contains("global.secret.secured", "secret.secured");
}
@Test
ValuesWsResponse result = executeRequestForProjectProperties("not-defined.secured");
- assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("not-defined.secured");
+ assertThat(result.getSetSecuredSettingsList()).containsOnly("not-defined.secured");
}
@Test
ValuesWsResponse result = executeRequestForGlobalProperties();
- assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("foo", "secret.secured");
+ assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("foo");
+ assertThat(result.getSetSecuredSettingsList()).containsOnly("secret.secured");
}
@Test
ValuesWsResponse result = executeRequestForProjectProperties();
List<Settings.Setting> settingsList = result.getSettingsList().stream().sorted(comparing(Settings.Setting::getKey)).collect(Collectors.toList());
- assertThat(settingsList).extracting(Settings.Setting::getKey).containsExactly("foo", "global.secret.secured", "secret.secured");
- assertThat(settingsList).extracting(Settings.Setting::hasValue).containsExactly(true, false, false);
+ assertThat(settingsList).extracting(Settings.Setting::getKey).containsExactly("foo");
+ assertThat(settingsList).extracting(Settings.Setting::hasValue).containsExactly(true);
+ assertThat(result.getSetSecuredSettingsList()).containsOnly("global.secret.secured", "secret.secured");
}
@Test
ValuesWsResponse result = executeRequestForProjectProperties("not-defined.secured");
- assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("not-defined.secured");
+ assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).isEmpty();
+ assertThat(result.getSetSecuredSettingsList()).containsOnly("not-defined.secured");
}
@Test
ValuesWsResponse result = executeRequestForGlobalProperties();
- assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("foo", "secret.secured");
+ assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("foo");
+ assertThat(result.getSetSecuredSettingsList()).containsOnly("secret.secured");
}
@Test
ValuesWsResponse result = executeRequestForProjectProperties();
- assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("foo", "secret.secured");
+ assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).containsOnly("foo");
+ assertThat(result.getSetSecuredSettingsList()).containsOnly("secret.secured");
}
@Test
@Test
public void test_example_json_response() {
- logIn();
+ logInAsAdmin();
definitions.addComponent(PropertyDefinition
.builder("sonar.test.jira")
.defaultValue("abc")
.build());
propertyDb.insertPropertySet("sonar.demo", null, ImmutableMap.of("text", "foo", "boolean", "true"), ImmutableMap.of("text", "bar", "boolean", "false"));
+ definitions.addComponent(PropertyDefinition
+ .builder("email.smtp_port.secured")
+ .defaultValue("25")
+ .build());
+ propertyDb.insertProperties(null, null, null, null,
+ newGlobalPropertyDto().setKey("email.smtp_port.secured").setValue("25"));
+
String result = newTester().newRequest()
- .setParam("keys", "sonar.test.jira,sonar.autogenerated,sonar.demo")
+ .setParam("keys", "sonar.test.jira,sonar.autogenerated,sonar.demo,email.smtp_port.secured")
.setMediaType(JSON)
.execute()
.getInput();
userSession.logIn()
.addPermission(GlobalPermission.SCAN);
response = executeRequest(tester, null, securedDef.key(), standardDef.key());
- assertThat(response.getSettingsList()).extracting(Settings.Setting::getKey).containsExactly("my.password.secured", "my.property");
- assertThat(response.getSettingsList()).extracting(Settings.Setting::hasValue).containsExactly(false, true);
+ assertThat(response.getSetSecuredSettingsList()).contains("my.password.secured");
// global administrator
userSession.logIn()
.addPermission(GlobalPermission.ADMINISTER);
response = executeRequest(tester, null, securedDef.key(), standardDef.key());
- assertThat(response.getSettingsList()).extracting(Settings.Setting::getKey).containsExactly("my.password.secured", "my.property");
- assertThat(response.getSettingsList()).extracting(Settings.Setting::hasValue).containsExactly(false, true);
+ assertThat(response.getSetSecuredSettingsList()).contains("my.password.secured");
// system administrator
userSession.logIn().setSystemAdministrator();
response = executeRequest(tester, null, securedDef.key(), standardDef.key());
- assertThat(response.getSettingsList()).extracting(Settings.Setting::getKey).containsExactly("my.password.secured", "my.property");
- assertThat(response.getSettingsList()).extracting(Settings.Setting::hasValue).containsExactly(false, true);
+ assertThat(response.getSetSecuredSettingsList()).contains("my.password.secured");
}
private ValuesWsResponse executeRequestForComponentProperties(ComponentDto componentDto, String... keys) {