diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/AuthorizationEngine.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/AuthorizationEngine.java index 091d902014a9f..ba87cf786580f 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/AuthorizationEngine.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/AuthorizationEngine.java @@ -342,6 +342,9 @@ public String getFailureContext() { } public static String getFailureDescription(Collection deniedIndices) { + if (deniedIndices.isEmpty()) { + return null; + } return "on indices [" + Strings.collectionToCommaDelimitedString(deniedIndices) + "]"; } diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizationServiceTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizationServiceTests.java index 548bee8bdd85f..dbc8871e53d86 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizationServiceTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizationServiceTests.java @@ -679,7 +679,7 @@ public void testUnknownRoleCausesDenial() throws IOException { ElasticsearchSecurityException securityException = expectThrows(ElasticsearchSecurityException.class, () -> authorize(authentication, action, request)); assertThat(securityException, - throwableWithMessage(containsString("[" + action + "] is unauthorized for user [test user] on indices ["))); + throwableWithMessage(containsString("[" + action + "] is unauthorized for user [test user],"))); assertThat(securityException, throwableWithMessage(containsString("this action is granted by the index privileges [read,all]"))); verify(auditTrail).accessDenied(eq(requestId), eq(authentication), eq(action), eq(request), authzInfoRoles(Role.EMPTY.names())); @@ -718,7 +718,7 @@ public void testThatRoleWithNoIndicesIsDenied() throws IOException { ElasticsearchSecurityException securityException = expectThrows(ElasticsearchSecurityException.class, () -> authorize(authentication, action, request)); assertThat(securityException, - throwableWithMessage(containsString("[" + action + "] is unauthorized for user [test user] on indices ["))); + throwableWithMessage(containsString("[" + action + "] is unauthorized for user [test user],"))); assertThat(securityException, throwableWithMessage(containsString("this action is granted by the index privileges [read,all]"))); verify(auditTrail).accessDenied(eq(requestId), eq(authentication), eq(action), eq(request),