Interface SecretStore
- All Known Implementing Classes:
EnvVarSecretStore,InMemorySecretStore,KeychainSecretStore
PropertySource.
Where a PropertySource is a read-only source of ordinary configuration values, a SecretStore
adds write/delete plus sensitivity semantics. The SPI is deliberately narrow — it
deals only in a String key and a char[] secret, with no dependency on any particular backend.
Sensitivity is intrinsic. Secret values are held as char[] rather than String so they can
be explicitly zeroed and do not linger in the string pool. An implementation must never toString(), log,
or otherwise dump a secret value. Callers are responsible for zeroing the arrays they pass to store(java.lang.String, char[])
and receive from find(java.lang.String) once done with them.
Three-state presence model. The three operations together model a clean present-with-value / present-without-materializing / absent distinction:
find(String)— returns the secret value when present (Optionalofchar[]), orOptional.empty()when absent. This is the only method that materializes the value.exists(String)— reports whether a secret is stored under the key without retrieving (and, for backends that decrypt on read, without decrypting) it. Prefer this overfind(java.lang.String)when only presence matters, so the secret is never pulled into memory needlessly.- absent —
find(java.lang.String)returns empty andexists(java.lang.String)returnsfalse .
Backend-unavailable behavior is a consumer decision. The built-in InMemorySecretStore and
EnvVarSecretStore never fail on a well-formed call, so they simply throw on a genuine error. Network- or
OS-backed implementations (for example an OS-keychain-backed store in a separate module) should let the consumer
pick fail-open vs fail-closed via a FailMode rather than baking a policy into the SPI.
See Also:
- Since:
- 10.0.0
-
Method Summary
Modifier and TypeMethodDescriptionbooleanDeletes the secret stored under the specified key.booleanReturns whether a secret is stored under the specified key without materializing its value.Optional<char[]>Returns the secret stored under the specified key.voidStores a secret under the specified key, replacing any existing value.
-
Method Details
-
store
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.- Parameters:
key- The key under which to store the secret. Must not benull .secret- The secret value. Must not benull .- Throws:
UnsupportedOperationException- If this store is read-only.
-
find
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.
- Parameters:
key- The key to look up. Must not benull .- Returns:
- The secret value, or
Optional.empty()if no secret is stored under the key.
-
exists
Returns whether a secret is stored under the specified key without materializing its value.- Parameters:
key- The key to check. Must not benull .- Returns:
true if a secret is stored under the key.
-
delete
Deletes the secret stored under the specified key.- Parameters:
key- The key to delete. Must not benull .- Returns:
true if a secret was present and removed;false if the key was already absent.- Throws:
UnsupportedOperationException- If this store is read-only.
-