Skip to content

Commit

Permalink
Make runAs generic
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks committed Aug 16, 2024
1 parent ca1f297 commit 84c0cc3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion server/src/main/java/org/opensearch/identity/Subject.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public interface Subject {
/**
* runAs allows the caller to run a callable function as this subject
*/
default void runAs(Callable<Void> callable) throws Exception {
default <T> T runAs(Callable<T> callable) throws Exception {
callable.call();
return null;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ public void authenticate(AuthToken token) {
}

@Override
public void runAs(Callable<Void> callable) throws Exception {
public <T> T runAs(Callable<T> callable) throws Exception {
try (ThreadContext.StoredContext ctx = threadPool.getThreadContext().stashContext()) {
callable.call();
}
return null;
}
}

0 comments on commit 84c0cc3

Please sign in to comment.