Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public void testDashboardsInfoValidationMessage() throws Exception {
assertThat(response, isOk());
assertThat(response.getTextFromJsonBody("/password_validation_error_message"), equalTo(DEFAULT_PASSWORD_MESSAGE));
assertThat(response.getTextFromJsonBody("/password_validation_regex"), equalTo(DEFAULT_PASSWORD_REGEX));
assertThat(response.getTextFromJsonBody("/api_tokens_enabled"), equalTo("false"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ public void testAuthInfoEndpoint() {
authenticateWithApiToken(authHeader, HttpStatus.SC_OK);
}

@Test
public void testDashboardsInfoReportsApiTokensEnabled() {
try (TestRestClient client = cluster.getRestClient(ADMIN_USER)) {
TestRestClient.HttpResponse response = client.get("_plugins/_security/dashboardsinfo");
response.assertStatusCode(HttpStatus.SC_OK);
assertThat(response.getTextFromJsonBody("/api_tokens_enabled"), equalTo("true"));
}
}

@Test
public void testCallingClusterHealthWithApiToken_success() {
String apiToken = generateApiToken(TEST_TOKEN_PAYLOAD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public void accept(RestChannel channel) throws Exception {
client.settings().get(ConfigConstants.SECURITY_RESTAPI_PASSWORD_VALIDATION_REGEX, DEFAULT_PASSWORD_REGEX)
);
builder.field("resource_sharing_enabled", resourceSharingEnabledSetting.getDynamicSettingValue());
builder.field("api_tokens_enabled", getApiTokensEnabled());
builder.endObject();

response = new BytesRestResponse(RestStatus.OK, builder);
Expand Down Expand Up @@ -191,4 +192,12 @@ private List<DashboardSignInOption> getSignInOptions() {
}
}

private boolean getApiTokensEnabled() {
ConfigV7 generalConfig = configurationRepository.getConfiguration(CType.CONFIG).getCEntry(CType.CONFIG.name());
if (generalConfig != null && generalConfig.dynamic != null && generalConfig.dynamic.api_tokens != null) {
return Boolean.TRUE.equals(generalConfig.dynamic.api_tokens.getEnabled());
}
return false;
}

}
Loading