Package org.keycloak.models
Interface SingleUseObjectProvider
- All Superinterfaces:
Provider
- All Known Implementing Classes:
InfinispanSingleUseObjectProvider,JpaSingleUseObjectProvider,RemoteInfinispanSingleUseObjectProvider
Provides a cache to store data for single-use use case or the details about used action tokens.
- Author:
- Marek Posolda
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringSuffix appended to a key to indicate that a token is considered revoked. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if there is a record in the store for the given key.Gets data associated with the given key.voidStores the given data and guarantees that data should be available in the store for at least the time specified bylifespanSecondsparameter.booleanputIfAbsent(String key, long lifespanInSeconds) Tries to put the key into the store.Returns data only if the removal was successful.booleanReplaces data associated with the given key in the store if the store contains the key.
-
Field Details
-
REVOKED_KEY
Suffix appended to a key to indicate that a token is considered revoked. For revoked tokens, only the methodsput(java.lang.String, long, java.util.Map<java.lang.String, java.lang.String>)andcontains(java.lang.String)must be used.- See Also:
-
-
Method Details
-
put
Stores the given data and guarantees that data should be available in the store for at least the time specified bylifespanSecondsparameter.- Parameters:
key- identifier for the single-use object. Must not benull.lifespanSeconds- minimum lifespan for which the key will be kept in the store. Must be positive.notes- data to associate with the key. For revoked tokens, this must be an empty Map.- Throws:
NullPointerException- ifkeyisnull.IllegalArgumentException- iflifespanSecondsis not positive.
-
get
Gets data associated with the given key.- Parameters:
key- identifier for the single-use object. Must not benull.- Returns:
- data associated with the given key, or
nullif there is no associated data. - Throws:
NullPointerException- ifkeyisnull.
-
remove
Returns data only if the removal was successful. Implementations must guarantee that removal is single-use: if two threads (even on different cluster nodes or different multi-site nodes) callremove(key)concurrently, only one of them is allowed to succeed and return data. It must not happen that both succeed.- Parameters:
key- identifier for the single-use object. Must not benull.- Returns:
- context data associated with the key, or
nullif there is no context data available. - Throws:
NullPointerException- ifkeyisnull.
-
replace
Replaces data associated with the given key in the store if the store contains the key.- Parameters:
key- identifier for the single-use object. Must not benull.notes- new data to be stored.- Returns:
trueif the store contains the key and data was replaced, otherwisefalse.- Throws:
NullPointerException- ifkeyisnull.
-
putIfAbsent
Tries to put the key into the store. It will succeed only if the key is not already present.- Parameters:
key- identifier for the single-use object. Must not benull.lifespanInSeconds- minimum lifespan for which the key will be kept in the store. Must be positive.- Returns:
trueif the key was successfully put into the store, meaning the same key wasn't in the store before.- Throws:
NullPointerException- ifkeyisnull.IllegalArgumentException- iflifespanInSecondsis not positive.
-
contains
Checks if there is a record in the store for the given key.- Parameters:
key- identifier for the single-use object. Must not benull.- Returns:
trueif the record is present in the store,falseotherwise.- Throws:
NullPointerException- ifkeyisnull.
-