Interface CredentialStore
- All Known Implementing Classes:
InMemoryCredentialStore
public interface CredentialStore
Persistence-neutral credential store.
The store is the only place that knows how credentials are persisted — file, RDBMS, key-value store. The security-core uses it exclusively through this interface so the core never gains a production database dependency.
Updates are compare-and-swap: the caller supplies a witness (the encoded hash or status it just read) and the store only applies the change if the witness still matches the persisted value (CWE-362 / CWE-367 / CWE-667). Blind overwrites are not supported — callers must re-read, decide and retry.
-
Method Summary
Modifier and TypeMethodDescriptionfindByUsername(String username) Looks up the credential row forusername.updateHashIfCurrent(String username, String expectedEncodedHash, String newEncodedHash, Instant when) Atomically replaces the stored hash if it still matchesexpectedEncodedHash.updateStatusIfCurrent(String username, CredentialStatus expectedStatus, CredentialStatus newStatus, Instant when) Atomically replaces the stored status if it still matchesexpectedStatus.
-
Method Details
-
findByUsername
Looks up the credential row forusername. ReturnsOptional.empty()when the username is unknown. -
updateHashIfCurrent
CredentialUpdateResult updateHashIfCurrent(String username, String expectedEncodedHash, String newEncodedHash, Instant when) Atomically replaces the stored hash if it still matchesexpectedEncodedHash.- Parameters:
username- credential identifierexpectedEncodedHash- witness; usually theencodedHashthatfindByUsernamejust returnednewEncodedHash- new envelope to persistwhen- timestamp forupdatedAt; the store does not callInstant.now()itself so callers can inject a clock
-
updateStatusIfCurrent
CredentialUpdateResult updateStatusIfCurrent(String username, CredentialStatus expectedStatus, CredentialStatus newStatus, Instant when) Atomically replaces the stored status if it still matchesexpectedStatus.
-