Class SecretManagerProvider

java.lang.Object
org.gcube.common.security.providers.SecretManagerProvider

public class SecretManagerProvider extends Object
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)
  • Constructor Details

    • SecretManagerProvider

      public SecretManagerProvider()
  • Method Details

    • get

      public static Secret get()
      Retrieves the Secret associated with the current thread.
      Returns:
      The Secret object for the current thread, or null if no secret has been set.
    • set

      public static void set(Secret secret)
      Sets the Secret for the current thread.

      This secret will be accessible by the current thread and any child threads it creates.

      Parameters:
      secret - The Secret object to be set.
    • reset

      public static void reset()
      Resets the Secret for 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.