Class JpaSingleUseObjectProvider

java.lang.Object
org.keycloak.singleobject.jpa.JpaSingleUseObjectProvider
All Implemented Interfaces:
SingleUseObjectProvider, Provider

public class JpaSingleUseObjectProvider extends Object implements SingleUseObjectProvider
JPA-based SingleUseObjectProvider that stores single-use objects in a relational database.

Expired entries are not removed on access; a periodic ExpirationTask handles cleanup. Read operations filter out expired rows via query predicates.

  • Constructor Details

    • JpaSingleUseObjectProvider

      public JpaSingleUseObjectProvider(KeycloakSession session)
  • Method Details

    • put

      public void put(String key, long lifespanSeconds, Map<String,String> notes)
      Description copied from interface: SingleUseObjectProvider
      Stores the given data and guarantees that data should be available in the store for at least the time specified by lifespanSeconds parameter.
      Specified by:
      put in interface SingleUseObjectProvider
      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.
    • get

      public Map<String,String> get(String key)
      Description copied from interface: SingleUseObjectProvider
      Gets data associated with the given key.
      Specified by:
      get in interface SingleUseObjectProvider
      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.
    • remove

      public Map<String,String> remove(String key)
      Description copied from interface: SingleUseObjectProvider
      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.
      Specified by:
      remove in interface SingleUseObjectProvider
      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.
    • replace

      public boolean replace(String key, Map<String,String> notes)
      Description copied from interface: SingleUseObjectProvider
      Replaces data associated with the given key in the store if the store contains the key.
      Specified by:
      replace in interface SingleUseObjectProvider
      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.
    • putIfAbsent

      public boolean putIfAbsent(String key, long lifespanInSeconds)
      Description copied from interface: SingleUseObjectProvider
      Tries to put the key into the store. It will succeed only if the key is not already present.
      Specified by:
      putIfAbsent in interface SingleUseObjectProvider
      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.
    • contains

      public boolean contains(String key)
      Description copied from interface: SingleUseObjectProvider
      Checks if there is a record in the store for the given key.
      Specified by:
      contains in interface SingleUseObjectProvider
      Parameters:
      key - identifier for the single-use object. Must not be null.
      Returns:
      true if the record is present in the store, false otherwise.
    • close

      public void close()
      Specified by:
      close in interface Provider