|
@@ -114,9 +114,12 @@ public class NativeRolesStore implements BiConsumer<Set<String>, ActionListener<
|
|
|
* Retrieve a list of roles, if rolesToGet is null or empty, fetch all roles
|
|
|
*/
|
|
|
public void getRoleDescriptors(Set<String> names, final ActionListener<RoleRetrievalResult> 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 class NativeRolesStore implements BiConsumer<Set<String>, ActionListener<
|
|
|
}
|
|
|
|
|
|
private void getRoleDescriptor(final String roleId, ActionListener<RoleRetrievalResult> 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<GetResponse>() {
|
|
|
+ securityIndex.checkIndexVersionThenExecute(e -> resultListener.onResponse(RoleRetrievalResult.failure(e)),
|
|
|
+ () -> executeGetRoleRequest(roleId, new ActionListener<GetResponse>() {
|
|
|
@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
|