Class InMemoryRefreshTokenStore
java.lang.Object
com.svenruppert.jsentinel.authentication.InMemoryRefreshTokenStore
- All Implemented Interfaces:
RefreshTokenStore
@ExperimentalJSentinelApi
public final class InMemoryRefreshTokenStore
extends Object
implements RefreshTokenStore
In-memory
RefreshTokenStore backed by a
ConcurrentHashMap. Atomic mutations through
compute/computeIfPresent.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintdeleteBySubject(TenantId tenant, SubjectId subjectId) Drops every token (active, replaced or revoked) issued tosubjectIdwithintenant.findByHash(String tokenHash) Looks up a record by its hash.booleanmarkReplaced(String oldHash, String newHash, Instant at) LinksoldHashas replaced bynewHashatat.booleanmarkRevoked(String tokenHash, Instant at) Marks the record fortokenHashrevoked atat.intpurgeExpired(Instant now) Drops every record whoseRefreshTokenRecord.expiresAt()is at or beforenow.voidsave(RefreshTokenRecord record) Persists or replaces the supplied record.
-
Constructor Details
-
InMemoryRefreshTokenStore
public InMemoryRefreshTokenStore()Creates an empty store.
-
-
Method Details
-
findByHash
Description copied from interface:RefreshTokenStoreLooks up a record by its hash.- Specified by:
findByHashin interfaceRefreshTokenStore- Parameters:
tokenHash- token hash; must not benullor blank- Returns:
- the record, if present
-
save
Description copied from interface:RefreshTokenStorePersists or replaces the supplied record. Keyed onRefreshTokenRecord.tokenHash().- Specified by:
savein interfaceRefreshTokenStore- Parameters:
record- record to persist; must not benull
-
markReplaced
Description copied from interface:RefreshTokenStoreLinksoldHashas replaced bynewHashatat. No-op whenoldHashalready carries a successor.- Specified by:
markReplacedin interfaceRefreshTokenStore- Parameters:
oldHash- hash of the consumed token; non-blanknewHash- hash of the successor; non-blankat- rotation instant; non-null (recorded as the consumed record'srevokedAtis left untouched — replacement is tracked throughreplacedByHashonly)- Returns:
trueif the link was set on a record that previously had no successor;falseotherwise
-
markRevoked
Description copied from interface:RefreshTokenStoreMarks the record fortokenHashrevoked atat. No-op when the record is already revoked.- Specified by:
markRevokedin interfaceRefreshTokenStore- Parameters:
tokenHash- token hash; non-blankat- revocation instant; non-null- Returns:
trueif a not-yet-revoked record was marked
-
deleteBySubject
Description copied from interface:RefreshTokenStoreDrops every token (active, replaced or revoked) issued tosubjectIdwithintenant.- Specified by:
deleteBySubjectin interfaceRefreshTokenStore- Parameters:
tenant- tenant scope; non-nullsubjectId- subject; non-null- Returns:
- number of records removed
-
purgeExpired
Description copied from interface:RefreshTokenStoreDrops every record whoseRefreshTokenRecord.expiresAt()is at or beforenow.- Specified by:
purgeExpiredin interfaceRefreshTokenStore- Parameters:
now- retention boundary; non-null- Returns:
- number of records purged
-