Class PrefixingSecretManager

java.lang.Object
dev.enola.common.secret.PrefixingSecretManager
All Implemented Interfaces:
SecretManager

public class PrefixingSecretManager extends Object implements SecretManager
PrefixingSecretManager is a SecretManager that prefixes all keys with a given prefix.

This is useful, for example, to use a single SecretManager in a server environment for multiple users (or any other Subject), or in a desktop environment to store application-specific secrets on the user's desktop secret manager (like GNOME Keyring or macOS Keychain on Apple's Secure Enclave).

  • Constructor Details

  • Method Details

    • store

      public void store(String key, char[] value) throws IOException
      Description copied from interface: SecretManager
      Stores a secret value associated with a unique key. The sensitive value is provided as a char array. Implementations will zero out the input value array immediately after calling this method for security. If a secret with the same key already exists, its value is overwritten.
      Specified by:
      store in interface SecretManager
      Parameters:
      key - The unique key (name) for the secret.
      value - The sensitive secret value as a character array.
      Throws:
      IOException - If an error occurs while storing the secret.
    • getOptional

      Description copied from interface: SecretManager
      Retrieves a secret by its key, with optionality.
      Specified by:
      getOptional in interface SecretManager
      Parameters:
      key - The unique key (name) of the secret to retrieve.
      Returns:
      An Optional containing the Secret, if found.
      Throws:
      IOException - If an error occurs while retrieving the secret.
    • delete

      public void delete(String key) throws IOException
      Description copied from interface: SecretManager
      Deletes a secret from the manager.
      Specified by:
      delete in interface SecretManager
      Parameters:
      key - The unique key (name) of the secret to delete.
      Throws:
      IOException - If an error occurs while deleting the secret.