Interface ExpirationAction

All Known Implementing Classes:
AuthenticationSessionExpirationAction, LoginFailureExpirationAction, RevokedTokenExpirationAction, SingleUseObjectExpirationAction
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface ExpirationAction
A callback that removes expired entries from the database.

Implementations execute the actual deletion logic (e.g. a JPA query) and report how many rows were removed via the removeCount consumer. The framework calls this method inside a transaction, potentially multiple times in a loop to support batched deletions.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    default boolean
    hasWork(KeycloakSession session, String realmId)
    Cheap read-only check if there might be anything to remove for the realm.
    boolean
    removeExpired(KeycloakSession session, String realmId, int currentTime, int maxRemoval, IntConsumer removeCount)
    Removes expired entries from the database.
  • Method Details

    • hasWork

      default boolean hasWork(KeycloakSession session, String realmId)
      Cheap read-only check if there might be anything to remove for the realm.

      Realm-aware tasks call this in a transaction before they claim the realm for the current interval. If it returns false, the realm is skipped without writing anything, so it is checked again on the next run.

      Parameters:
      session - the current Keycloak session, valid for the duration of the enclosing transaction.
      realmId - the realm to check.
      Returns:
      false if the realm has nothing that could expire; true otherwise. Defaults to true.
    • removeExpired

      boolean removeExpired(KeycloakSession session, String realmId, int currentTime, int maxRemoval, IntConsumer removeCount)
      Removes expired entries from the database.

      This method is invoked inside a transaction. It should delete a batch of expired entries whose expiration time is at or before currentTime and report the number of removed rows via removeCount.

      Parameters:
      session - the current Keycloak session, valid for the duration of the enclosing transaction.
      realmId - the realm to clean up, or null for non-realm-aware expiration tasks.
      currentTime - the current time in seconds since epoch, used as the expiration threshold. This value is constant across all batches within a single task run.
      maxRemoval - the maximum number of entries to remove in this batch.
      removeCount - a consumer to report the number of entries removed in this batch.
      Returns:
      true if there are more expired entries to remove (the framework will call this method again in a new transaction); false if all expired entries have been removed.