diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/store/NativeRolesStore.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/store/NativeRolesStore.java index cbc66235d305b..4f596878bc2a8 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/store/NativeRolesStore.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/store/NativeRolesStore.java @@ -114,9 +114,12 @@ public void accept(Set names, ActionListener listen * Retrieve a list of roles, if rolesToGet is null or empty, fetch all roles */ public void getRoleDescriptors(Set names, final ActionListener listener) { - if (securityIndex.indexExists() == false) { + final SecurityIndexManager frozenSecurityIndex = this.securityIndex.freeze(); + if (frozenSecurityIndex.indexExists() == false) { // TODO remove this short circuiting and fix tests that fail without this! listener.onResponse(RoleRetrievalResult.success(Collections.emptySet())); + } else if (frozenSecurityIndex.isAvailable() == false) { + listener.onResponse(RoleRetrievalResult.failure(frozenSecurityIndex.getUnavailableReason())); } else if (names == null || names.isEmpty()) { securityIndex.checkIndexVersionThenExecute(listener::onFailure, () -> { QueryBuilder query = QueryBuilders.termQuery(RoleDescriptor.Fields.TYPE.getPreferredName(), ROLE_TYPE); @@ -311,17 +314,20 @@ public String toString() { } private void getRoleDescriptor(final String roleId, ActionListener resultListener) { - if (securityIndex.indexExists() == false) { + final SecurityIndexManager frozenSecurityIndex = this.securityIndex.freeze(); + if (frozenSecurityIndex.indexExists() == false) { // TODO remove this short circuiting and fix tests that fail without this! resultListener.onResponse(RoleRetrievalResult.success(Collections.emptySet())); + } else if (frozenSecurityIndex.isAvailable() == false) { + resultListener.onResponse(RoleRetrievalResult.failure(frozenSecurityIndex.getUnavailableReason())); } else { - securityIndex.prepareIndexIfNeededThenExecute(e -> resultListener.onResponse(RoleRetrievalResult.failure(e)), () -> - executeGetRoleRequest(roleId, new ActionListener() { + securityIndex.checkIndexVersionThenExecute(e -> resultListener.onResponse(RoleRetrievalResult.failure(e)), + () -> executeGetRoleRequest(roleId, new ActionListener() { @Override public void onResponse(GetResponse response) { final RoleDescriptor descriptor = transformRole(response); - resultListener.onResponse(RoleRetrievalResult.success( - descriptor == null ? Collections.emptySet() : Collections.singleton(descriptor))); + resultListener.onResponse(RoleRetrievalResult + .success(descriptor == null ? Collections.emptySet() : Collections.singleton(descriptor))); } @Override