in src/main/java/org/opensearch/security/configuration/PrivilegesInterceptorImpl.java [221:332]
private CreateIndexRequestBuilder replaceIndex(final ActionRequest request, final String oldIndexName, final String newIndexName, final String action) {
boolean kibOk = false;
CreateIndexRequestBuilder createIndexRequestBuilder = null;
if (log.isDebugEnabled()) {
log.debug("{} index will be replaced with {} in this {} request", oldIndexName, newIndexName, request.getClass().getName());
}
//handle msearch and mget
//in case of GET change the .kibana index to the userskibanaindex
//in case of Search add the usersDashboardsindex
//if (request instanceof CompositeIndicesRequest) {
String[] newIndexNames = new String[] { newIndexName };
// CreateIndexRequest
if (request instanceof CreateIndexRequest) {
String concreteName = getConcreteIndexName(newIndexName, clusterService.state().getMetadata().getIndicesLookup());
if (concreteName != null) {
// use new name for alias and suffixed index name
((CreateIndexRequest) request).index(concreteName).alias(new Alias(newIndexName));
} else {
((CreateIndexRequest) request).index(newIndexName);
}
kibOk = true;
} else if (request instanceof BulkRequest) {
BulkRequest bulkRequest = (BulkRequest) request;
for (DocWriteRequest<?> ar : bulkRequest.requests()) {
if (ar instanceof DeleteRequest) {
((DeleteRequest) ar).index(newIndexName);
}
if (ar instanceof IndexRequest) {
((IndexRequest) ar).index(newIndexName);
}
if (ar instanceof UpdateRequest) {
((UpdateRequest) ar).index(newIndexName);
}
}
// Please see comment for DeleteRequest below. Multi-tenant index may be auto created for any type of
// DocWriteRequest
if (!bulkRequest.requests().isEmpty()) {
createIndexRequestBuilder = newCreateIndexRequestBuilderIfAbsent(newIndexName);
}
kibOk = true;
} else if (request instanceof MultiGetRequest) {
for (Item item : ((MultiGetRequest) request).getItems()) {
item.index(newIndexName);
}
kibOk = true;
} else if (request instanceof MultiSearchRequest) {
for (SearchRequest ar : ((MultiSearchRequest) request).requests()) {
ar.indices(newIndexNames);
}
kibOk = true;
} else if (request instanceof MultiTermVectorsRequest) {
for (TermVectorsRequest ar : (Iterable<TermVectorsRequest>) () -> ((MultiTermVectorsRequest) request).iterator()) {
ar.index(newIndexName);
}
kibOk = true;
} else if (request instanceof UpdateRequest) {
((UpdateRequest) request).index(newIndexName);
createIndexRequestBuilder = newCreateIndexRequestBuilderIfAbsent(newIndexName);
kibOk = true;
} else if (request instanceof IndexRequest) {
createIndexRequestBuilder = newCreateIndexRequestBuilderIfAbsent(newIndexName);
((IndexRequest) request).index(newIndexName);
kibOk = true;
} else if (request instanceof DeleteRequest) {
((DeleteRequest) request).index(newIndexName);
// Usually only IndexRequest and UpdateRequest auto create index if it does not exist,
// but custom DeleteRequest can also auto create index (see TransportBulkAction.doInternalExecute()).
// It should be OK to create the index in a rare cases where it would not be created otherwise to minimize
// the risk of auto create that will create the tenant index without the alias.
createIndexRequestBuilder = newCreateIndexRequestBuilderIfAbsent(newIndexName);
kibOk = true;
} else if (request instanceof SingleShardRequest) {
((SingleShardRequest<?>) request).index(newIndexName);
kibOk = true;
} else if (request instanceof RefreshRequest) {
((RefreshRequest) request).indices(newIndexNames); //???
kibOk = true;
} else if (request instanceof ReplicationRequest) {
((ReplicationRequest<?>) request).index(newIndexName);
kibOk = true;
} else if (request instanceof Replaceable) {
Replaceable replaceableRequest = (Replaceable) request;
replaceableRequest.indices(newIndexNames);
kibOk = true;
} else if (request instanceof GetFieldMappingsIndexRequest || request instanceof GetFieldMappingsRequest) {
kibOk = true;
} else {
log.warn("Dont know what to do (1) with {}", request.getClass());
}
if (!kibOk) {
log.warn("Dont know what to do (2) with {}", request.getClass());
}
return createIndexRequestBuilder;
}