From 84c0cc3324dfc66bc12a5c6e9f8eb5594eda8b68 Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Fri, 16 Aug 2024 14:29:48 -0400 Subject: [PATCH] Make runAs generic Signed-off-by: Craig Perkins --- server/src/main/java/org/opensearch/identity/Subject.java | 3 ++- .../java/org/opensearch/identity/noop/NoopPluginSubject.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/opensearch/identity/Subject.java b/server/src/main/java/org/opensearch/identity/Subject.java index a6bd7f9777481..349ce120244e4 100644 --- a/server/src/main/java/org/opensearch/identity/Subject.java +++ b/server/src/main/java/org/opensearch/identity/Subject.java @@ -36,7 +36,8 @@ public interface Subject { /** * runAs allows the caller to run a callable function as this subject */ - default void runAs(Callable callable) throws Exception { + default T runAs(Callable callable) throws Exception { callable.call(); + return null; }; } diff --git a/server/src/main/java/org/opensearch/identity/noop/NoopPluginSubject.java b/server/src/main/java/org/opensearch/identity/noop/NoopPluginSubject.java index f2d79d8a35d89..b8e25a1107afb 100644 --- a/server/src/main/java/org/opensearch/identity/noop/NoopPluginSubject.java +++ b/server/src/main/java/org/opensearch/identity/noop/NoopPluginSubject.java @@ -45,9 +45,10 @@ public void authenticate(AuthToken token) { } @Override - public void runAs(Callable callable) throws Exception { + public T runAs(Callable callable) throws Exception { try (ThreadContext.StoredContext ctx = threadPool.getThreadContext().stashContext()) { callable.call(); } + return null; } }