Skip to content

Commit 78437ea

Browse files
committed
Use getTaskAndCheckAuthentication
1 parent a00558e commit 78437ea

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/async/AsyncTaskIndexService.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,22 @@ public <T extends AsyncTask> T getTaskAndCheckAuthentication(
391391
TaskManager taskManager,
392392
AsyncExecutionId asyncExecutionId,
393393
Class<T> tClass
394+
) throws IOException {
395+
return getTaskAndCheckAuthentication(taskManager, security, asyncExecutionId, tClass);
396+
}
397+
398+
/**
399+
* Returns the {@link AsyncTask} if the provided <code>asyncTaskId</code>
400+
* is registered in the task manager, <code>null</code> otherwise.
401+
*
402+
* This method throws a {@link ResourceNotFoundException} if the authenticated user
403+
* is not the creator of the original task.
404+
*/
405+
public static <T extends AsyncTask> T getTaskAndCheckAuthentication(
406+
TaskManager taskManager,
407+
AsyncSearchSecurity security,
408+
AsyncExecutionId asyncExecutionId,
409+
Class<T> tClass
394410
) throws IOException {
395411
T asyncTask = getTask(taskManager, asyncExecutionId, tClass);
396412
if (asyncTask == null) {

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plugin/TransportEsqlAsyncStopAction.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,7 @@ private void stopQueryAndReturnResult(Task task, AsyncExecutionId asyncId, Actio
130130

131131
private EsqlQueryTask getEsqlQueryTask(AsyncExecutionId asyncId) {
132132
try {
133-
EsqlQueryTask asyncTask = AsyncTaskIndexService.getTask(taskManager, asyncId, EsqlQueryTask.class);
134-
if (asyncTask == null || false == security.currentUserHasAccessToTask(asyncTask)) {
135-
return null;
136-
}
137-
return asyncTask;
133+
return AsyncTaskIndexService.getTaskAndCheckAuthentication(taskManager, security, asyncId, EsqlQueryTask.class);
138134
} catch (IOException e) {
139135
return null;
140136
}

0 commit comments

Comments
 (0)