Class EnvVarSecretStore

java.lang.Object
org.apache.juneau.commons.secret.EnvVarSecretStore
All Implemented Interfaces:
SecretStore

public class EnvVarSecretStore extends Object implements SecretStore
A read-only SecretStore backed by System.getenv(String).

Gives 12-factor deployments a zero-dependency way to feed secrets in as environment variables: find(java.lang.String) and exists(java.lang.String) resolve straight from the process environment. Because the environment is immutable from within the process, the mutating operations are unsupported:

Note that environment variables are inherently more exposed than a dedicated secret backend (they are visible to child processes and to anything that can read the process environment), so this store trades secrecy strength for deployment simplicity. The retrieved value is never toString()'d, logged, or dumped by this class.

Since:
10.0.0
  • Constructor Details

  • Method Details

    • store

      public void store(String key, char[] secret)
      Description copied from interface: SecretStore
      Stores a secret under the specified key, replacing any existing value.

      The caller retains ownership of secret and may zero it after this call returns; an implementation that needs to retain the value must copy it.

      Specified by:
      store in interface SecretStore
      Parameters:
      key - The key under which to store the secret. Must not be null.
      secret - The secret value. Must not be null.
    • find

      public Optional<char[]> find(String key)
      Description copied from interface: SecretStore
      Returns the secret stored under the specified key.

      The returned array is the caller's to own and zero; it is not a live view of the store's internal state.

      Specified by:
      find in interface SecretStore
      Parameters:
      key - The key to look up. Must not be null.
      Returns:
      The secret value, or Optional.empty() if no secret is stored under the key.
    • exists

      public boolean exists(String key)
      Description copied from interface: SecretStore
      Returns whether a secret is stored under the specified key without materializing its value.
      Specified by:
      exists in interface SecretStore
      Parameters:
      key - The key to check. Must not be null.
      Returns:
      true if a secret is stored under the key.
    • delete

      public boolean delete(String key)
      Description copied from interface: SecretStore
      Deletes the secret stored under the specified key.
      Specified by:
      delete in interface SecretStore
      Parameters:
      key - The key to delete. Must not be null.
      Returns:
      true if a secret was present and removed; false if the key was already absent.