Class SecretManagerProvider
java.lang.Object
org.gcube.common.security.providers.SecretManagerProvider
Provides a thread-safe way to manage and access a
Secret object
within the current execution thread.
This class uses an InheritableThreadLocal to ensure that a secret
set in a parent thread is automatically inherited by any child threads
that are created, which is crucial for managing authorization contexts
in asynchronous or multi-threaded environments.
- Author:
- Luca Frosini (ISTI - CNR)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringMDC key used to store the current gcube security context in the logging context.static final StringMDC key used to store the identifier of the owner of the current secret (the user or the client that makes the request, or the container in its own tasks) in the logging context; absent when no secret is set in the current thread. -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
MDC_CONTEXT_KEY
MDC key used to store the current gcube security context in the logging context.- See Also:
-
MDC_USER_KEY
MDC key used to store the identifier of the owner of the current secret (the user or the client that makes the request, or the container in its own tasks) in the logging context; absent when no secret is set in the current thread.- See Also:
-
-
Constructor Details
-
SecretManagerProvider
public SecretManagerProvider()
-
-
Method Details
-
get
Retrieves theSecretassociated with the current thread.- Returns:
- The
Secretobject for the current thread, ornullif no secret has been set.
-
set
Sets theSecretfor the current thread.This secret will be accessible by the current thread and any child threads it creates.
- Parameters:
secret- TheSecretobject to be set.
-
reset
public static void reset()Resets theSecretfor the current thread, effectively removing it.This method should be called to clean up the thread-local secret, especially after a task is completed, to prevent security issues.
-