Interface SingleUseObjectProvider

All Superinterfaces:
Provider
All Known Implementing Classes:
InfinispanSingleUseObjectProvider, JpaSingleUseObjectProvider, RemoteInfinispanSingleUseObjectProvider

public interface SingleUseObjectProvider extends Provider
Provides a cache to store data for single-use use case or the details about used action tokens.
Author:
Marek Posolda
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Suffix appended to a key to indicate that a token is considered revoked.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Checks if there is a record in the store for the given key.
    get(String key)
    Gets data associated with the given key.
    void
    put(String key, long lifespanSeconds, Map<String,String> notes)
    Stores the given data and guarantees that data should be available in the store for at least the time specified by lifespanSeconds parameter.
    boolean
    putIfAbsent(String key, long lifespanInSeconds)
    Tries to put the key into the store.
    Returns data only if the removal was successful.
    boolean
    replace(String key, Map<String,String> notes)
    Replaces data associated with the given key in the store if the store contains the key.

    Methods inherited from interface org.keycloak.provider.Provider

    close
  • Field Details

  • Method Details

    • put

      void put(String key, long lifespanSeconds, Map<String,String> notes)
      Stores the given data and guarantees that data should be available in the store for at least the time specified by lifespanSeconds parameter.
      Parameters:
      key - identifier for the single-use object. Must not be null.
      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 - if key is null.
      IllegalArgumentException - if lifespanSeconds is not positive.
    • get

      Map<String,String> get(String key)
      Gets data associated with the given key.
      Parameters:
      key - identifier for the single-use object. Must not be null.
      Returns:
      data associated with the given key, or null if there is no associated data.
      Throws:
      NullPointerException - if key is null.
    • remove

      Map<String,String> remove(String key)
      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) call remove(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 be null.
      Returns:
      context data associated with the key, or null if there is no context data available.
      Throws:
      NullPointerException - if key is null.
    • replace

      boolean replace(String key, Map<String,String> notes)
      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 be null.
      notes - new data to be stored.
      Returns:
      true if the store contains the key and data was replaced, otherwise false.
      Throws:
      NullPointerException - if key is null.
    • putIfAbsent

      boolean putIfAbsent(String key, long lifespanInSeconds)
      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 be null.
      lifespanInSeconds - minimum lifespan for which the key will be kept in the store. Must be positive.
      Returns:
      true if the key was successfully put into the store, meaning the same key wasn't in the store before.
      Throws:
      NullPointerException - if key is null.
      IllegalArgumentException - if lifespanInSeconds is not positive.
    • contains

      boolean contains(String key)
      Checks if there is a record in the store for the given key.
      Parameters:
      key - identifier for the single-use object. Must not be null.
      Returns:
      true if the record is present in the store, false otherwise.
      Throws:
      NullPointerException - if key is null.