Package org.gcube.common.security
Class AuthorizedTasks
java.lang.Object
org.gcube.common.security.AuthorizedTasks
A utility class for managing and executing tasks with specific authorization contexts.
This class provides static methods to bind
Callable and Runnable
tasks to a specific Secret context. It ensures that the correct secret
is set before the task runs and is properly reset afterward, preventing
secrets from leaking into unintended scopes.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic RunnableBinds aRunnabletask to the current authorization context.static <V> Callable<V>Binds aCallabletask to the current authorization context.static voidexecuteSafely(Runnable task, Secret secret) Executes aRunnabletask immediately within a specific secret context.static <T> TexecuteSafely(Callable<T> task, Secret secret) Executes aCallabletask immediately within a specific secret context.
-
Constructor Details
-
AuthorizedTasks
public AuthorizedTasks()
-
-
Method Details
-
bind
Binds aCallabletask to the current authorization context. This method captures the current secret fromSecretManagerProviderand returns a newCallablethat will automatically set that secret before executing the original task and reset it afterward. This is useful for delegating tasks to a different thread or for asynchronous execution while maintaining the correct authorization context. -
bind
Binds aRunnabletask to the current authorization context. Similar to thebind(Callable)method, this captures the current secret and returns a newRunnablethat will set the secret before execution and reset it upon completion. -
executeSafely
Executes aRunnabletask immediately within a specific secret context. This method temporarily sets a specified secret, executes the task, and then restores the previous secret, guaranteeing that the original secret is always put back in place, even if the task throws an exception. -
executeSafely
-