Class InMemoryApiKeyStore
java.lang.Object
com.svenruppert.jsentinel.authentication.InMemoryApiKeyStore
- All Implemented Interfaces:
ApiKeyStore
@ExperimentalJSentinelApi
public final class InMemoryApiKeyStore
extends Object
implements ApiKeyStore
In-memory
ApiKeyStore backed by a
LinkedHashMap so listBySubject(TenantId, SubjectId)
preserves insertion order. Read-write lock keeps mutations atomic
while letting concurrent lookups proceed.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleandeleteByHash(String keyHash) Removes the record forkeyHash.findByHash(String keyHash) Looks up an API-key record by its hash.listBySubject(TenantId tenant, SubjectId subjectId) Returns every record (active, revoked, or expired) belonging tosubjectIdwithintenant, in insertion order (oldest first).booleanUpdates theApiKeyRecord.lastUsedAt()timestamp of the record forkeyHash.intpurgeExpired(Instant now) Drops every record whoseApiKeyRecord.expiresAt()is at or beforenow.booleanMarks the record forkeyHashrevoked atat.voidsave(ApiKeyRecord record) Persists or replaces the supplied record.
-
Constructor Details
-
InMemoryApiKeyStore
public InMemoryApiKeyStore()Creates an empty store.
-
-
Method Details
-
findByHash
Description copied from interface:ApiKeyStoreLooks up an API-key record by its hash.- Specified by:
findByHashin interfaceApiKeyStore- Parameters:
keyHash- key hash; must not benullor blank- Returns:
- the record, if present
-
save
Description copied from interface:ApiKeyStorePersists or replaces the supplied record. Keyed onApiKeyRecord.keyHash().- Specified by:
savein interfaceApiKeyStore- Parameters:
record- record to persist; must not benull
-
listBySubject
Description copied from interface:ApiKeyStoreReturns every record (active, revoked, or expired) belonging tosubjectIdwithintenant, in insertion order (oldest first). Used by an "manage my API keys" UI.- Specified by:
listBySubjectin interfaceApiKeyStore- Parameters:
tenant- tenant scope; must not benullsubjectId- subject; must not benull- Returns:
- immutable list of records; empty when none exist
-
markUsed
Description copied from interface:ApiKeyStoreUpdates theApiKeyRecord.lastUsedAt()timestamp of the record forkeyHash.- Specified by:
markUsedin interfaceApiKeyStore- Parameters:
keyHash- key hash; must not benullor blankat- instant of use; must not benull- Returns:
trueif the record existed and was updated,falsewhen no such key existed
-
revoke
Description copied from interface:ApiKeyStoreMarks the record forkeyHashrevoked atat. No-op on an already-revoked record.- Specified by:
revokein interfaceApiKeyStore- Parameters:
keyHash- key hash; must not benullor blankat- instant of revocation; must not benull- Returns:
trueif a not-yet-revoked record was marked,falsewhen no such key existed or when it was already revoked
-
deleteByHash
Description copied from interface:ApiKeyStoreRemoves the record forkeyHash.- Specified by:
deleteByHashin interfaceApiKeyStore- Parameters:
keyHash- key hash; must not benullor blank- Returns:
truewhen a record was removed
-
purgeExpired
Description copied from interface:ApiKeyStoreDrops every record whoseApiKeyRecord.expiresAt()is at or beforenow.- Specified by:
purgeExpiredin interfaceApiKeyStore- Parameters:
now- retention boundary; must not benull- Returns:
- number of records purged
-