Class InMemoryCredentialStore
java.lang.Object
com.svenruppert.jsentinel.credential.store.InMemoryCredentialStore
- All Implemented Interfaces:
CredentialStore
In-memory
CredentialStore backed by
ConcurrentHashMap, suitable for tests, demos and small
single-node deployments.
The CAS is implemented through
ConcurrentHashMap.replace(Object, Object, Object) which uses
the record's identity comparison — record equality is value-based,
so two records with the same field values are considered equal.
That means concurrent updates pinning the same witness deterministically
resolve to a single winner (CWE-362).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfindByUsername(String username) Looks up the credential row forusername.register(CredentialRecord record) Inserts a new record.intsize()Test/demo helper: number of records currently held.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.
-
Constructor Details
-
InMemoryCredentialStore
public InMemoryCredentialStore()
-
-
Method Details
-
register
Inserts a new record. Throws when a record under the same username already exists; the test fixtures expect callers to be explicit. -
findByUsername
Description copied from interface:CredentialStoreLooks up the credential row forusername. ReturnsOptional.empty()when the username is unknown.- Specified by:
findByUsernamein interfaceCredentialStore
-
updateHashIfCurrent
public CredentialUpdateResult updateHashIfCurrent(String username, String expectedEncodedHash, String newEncodedHash, Instant when) Description copied from interface:CredentialStoreAtomically replaces the stored hash if it still matchesexpectedEncodedHash.- Specified by:
updateHashIfCurrentin interfaceCredentialStore- 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
public CredentialUpdateResult updateStatusIfCurrent(String username, CredentialStatus expectedStatus, CredentialStatus newStatus, Instant when) Description copied from interface:CredentialStoreAtomically replaces the stored status if it still matchesexpectedStatus.- Specified by:
updateStatusIfCurrentin interfaceCredentialStore
-
size
public int size()Test/demo helper: number of records currently held.
-