Class DisabledUserSessionPersisterProvider

java.lang.Object
org.keycloak.models.session.DisabledUserSessionPersisterProvider
All Implemented Interfaces:
UserSessionPersisterProvider, UserSessionPersisterProviderFactory, org.keycloak.provider.Provider, org.keycloak.provider.ProviderFactory<UserSessionPersisterProvider>

public class DisabledUserSessionPersisterProvider extends Object implements UserSessionPersisterProviderFactory, UserSessionPersisterProvider
Persistence of userSessions is disabled . Useful just if you never need survive of userSessions/clientSessions among server restart. Offline sessions / offline tokens will be invalid after server restart as well,
Author:
Marek Posolda
  • Field Details

  • Constructor Details

    • DisabledUserSessionPersisterProvider

      public DisabledUserSessionPersisterProvider()
  • Method Details

    • create

      public UserSessionPersisterProvider create(org.keycloak.models.KeycloakSession session)
      Specified by:
      create in interface org.keycloak.provider.ProviderFactory<UserSessionPersisterProvider>
    • init

      public void init(org.keycloak.Config.Scope config)
      Specified by:
      init in interface org.keycloak.provider.ProviderFactory<UserSessionPersisterProvider>
    • postInit

      public void postInit(org.keycloak.models.KeycloakSessionFactory factory)
      Specified by:
      postInit in interface org.keycloak.provider.ProviderFactory<UserSessionPersisterProvider>
    • close

      public void close()
      Specified by:
      close in interface org.keycloak.provider.Provider
      Specified by:
      close in interface org.keycloak.provider.ProviderFactory<UserSessionPersisterProvider>
    • getId

      public String getId()
      Specified by:
      getId in interface org.keycloak.provider.ProviderFactory<UserSessionPersisterProvider>
    • createUserSession

      public void createUserSession(org.keycloak.models.UserSessionModel userSession, boolean offline)
      Specified by:
      createUserSession in interface UserSessionPersisterProvider
    • createClientSession

      public void createClientSession(org.keycloak.models.AuthenticatedClientSessionModel clientSession, boolean offline)
      Specified by:
      createClientSession in interface UserSessionPersisterProvider
    • removeUserSession

      public void removeUserSession(String userSessionId, boolean offline)
      Specified by:
      removeUserSession in interface UserSessionPersisterProvider
    • removeClientSession

      public void removeClientSession(String userSessionId, String clientUUID, boolean offline)
      Specified by:
      removeClientSession in interface UserSessionPersisterProvider
    • onRealmRemoved

      public void onRealmRemoved(org.keycloak.models.RealmModel realm)
      Specified by:
      onRealmRemoved in interface UserSessionPersisterProvider
    • onClientRemoved

      public void onClientRemoved(org.keycloak.models.RealmModel realm, org.keycloak.models.ClientModel client)
      Specified by:
      onClientRemoved in interface UserSessionPersisterProvider
    • onUserRemoved

      public void onUserRemoved(org.keycloak.models.RealmModel realm, org.keycloak.models.UserModel user)
      Specified by:
      onUserRemoved in interface UserSessionPersisterProvider
    • updateLastSessionRefreshes

      public void updateLastSessionRefreshes(org.keycloak.models.RealmModel realm, int lastSessionRefresh, Collection<String> userSessionIds, boolean offline)
      Specified by:
      updateLastSessionRefreshes in interface UserSessionPersisterProvider
    • removeExpired

      public void removeExpired(org.keycloak.models.RealmModel realm)
      Specified by:
      removeExpired in interface UserSessionPersisterProvider
    • loadUserSession

      public org.keycloak.models.UserSessionModel loadUserSession(org.keycloak.models.RealmModel realm, String userSessionId, boolean offline)
      Description copied from interface: UserSessionPersisterProvider
      Loads the user session with the given userSessionId.
      Specified by:
      loadUserSession in interface UserSessionPersisterProvider
      Returns:
    • loadUserSessionsStream

      public Stream<org.keycloak.models.UserSessionModel> loadUserSessionsStream(org.keycloak.models.RealmModel realm, org.keycloak.models.ClientModel client, boolean offline, Integer firstResult, Integer maxResults)
      Description copied from interface: UserSessionPersisterProvider
      Loads the user sessions for the given ClientModel in the given RealmModel if present.
      Specified by:
      loadUserSessionsStream in interface UserSessionPersisterProvider
      Returns:
    • loadUserSessionsStream

      public Stream<org.keycloak.models.UserSessionModel> loadUserSessionsStream(org.keycloak.models.RealmModel realm, org.keycloak.models.UserModel user, boolean offline, Integer firstResult, Integer maxResults)
      Description copied from interface: UserSessionPersisterProvider
      Loads the user sessions for the given UserModel in the given RealmModel if present.
      Specified by:
      loadUserSessionsStream in interface UserSessionPersisterProvider
      Returns:
    • loadUserSessionsStream

      public Stream<org.keycloak.models.UserSessionModel> loadUserSessionsStream(Integer firstResult, Integer maxResults, boolean offline, String lastUserSessionId)
      Description copied from interface: UserSessionPersisterProvider
      Called during startup. For each userSession, it loads also clientSessions.
      Specified by:
      loadUserSessionsStream in interface UserSessionPersisterProvider
      Parameters:
      firstResult - Integer Index of the first desired user session. Ignored if negative or null.
      maxResults - Integer Maximum number of returned user sessions. Ignored if negative or null.
      offline - boolean Flag to include offline sessions.
      lastUserSessionId - String Id of the user session. It will return only user sessions with id's lexicographically greater than this. it will compare the id in dictionary order and takes only those created later.
      Returns:
      Stream of UserSessionModel. Never returns null.
    • loadClientSession

      public org.keycloak.models.AuthenticatedClientSessionModel loadClientSession(org.keycloak.models.RealmModel realm, org.keycloak.models.ClientModel client, org.keycloak.models.UserSessionModel userSession, boolean offline)
      Description copied from interface: UserSessionPersisterProvider
      Loads client session from the db by provided user session and client.
      Specified by:
      loadClientSession in interface UserSessionPersisterProvider
      Parameters:
      realm - RealmModel Realm for the associated client session.
      client - ClientModel Client used for the creation of client session.
      userSession - UserSessionModel User session for the associated client session.
      offline - boolean Flag that indicates the client session should be online/offline.
      Returns:
      Client session according the provided criteria or null if not found.
    • getUserSessionsCount

      public int getUserSessionsCount(boolean offline)
      Description copied from interface: UserSessionPersisterProvider
      Retrieves the count of user sessions for all realms.
      Specified by:
      getUserSessionsCount in interface UserSessionPersisterProvider
      Returns:
    • getUserSessionsCount

      public int getUserSessionsCount(org.keycloak.models.RealmModel realm, org.keycloak.models.ClientModel clientModel, boolean offline)
      Description copied from interface: UserSessionPersisterProvider
      Retrieves the count of user client-sessions for the given client
      Specified by:
      getUserSessionsCount in interface UserSessionPersisterProvider
      Returns:
    • getUserSessionsCountsByClients

      public Map<String,Long> getUserSessionsCountsByClients(org.keycloak.models.RealmModel realm, boolean offline)
      Description copied from interface: UserSessionPersisterProvider
      Returns a Map containing the number of user-sessions aggregated by client id for the given realm.
      Specified by:
      getUserSessionsCountsByClients in interface UserSessionPersisterProvider
      Returns:
      the count Map with clientId as key and session count as value
    • readOnlyUserSessionStream

      public Stream<org.keycloak.models.UserSessionModel> readOnlyUserSessionStream(org.keycloak.models.RealmModel realm, boolean offline)
      Description copied from interface: UserSessionPersisterProvider
      Stream all the sessions belonging to the realm.

      The returned UserSessionModel instances are immutable. More precisely, the entity is not tracked by the JPA and any modification may throw an UnsupportedOperationException.

      Specified by:
      readOnlyUserSessionStream in interface UserSessionPersisterProvider
      Parameters:
      realm - The RealmModel instance.
      offline - If true, it streams the offline sessions, otherwise the regular sessions.
      Returns:
      A Stream for all the sessions in the realm.
    • readOnlyUserSessionStream

      public Stream<org.keycloak.models.UserSessionModel> readOnlyUserSessionStream(org.keycloak.models.RealmModel realm, org.keycloak.models.ClientModel client, boolean offline, int skip, int maxResults)
      Description copied from interface: UserSessionPersisterProvider
      Stream all the sessions belonging to the realm and having a client session from the client.

      The returned UserSessionModel instances are immutable. More precisely, the entity is not tracked by the JPA and any modification may throw an UnsupportedOperationException.

      The skip and maxResults parameters control how many sessions should be streamed. A negative value for either parameter is ignored (no skip/limit applied). If maxResults is zero, an empty stream is returned.

      Specified by:
      readOnlyUserSessionStream in interface UserSessionPersisterProvider
      Parameters:
      realm - The RealmModel instance.
      client - The ClientModel instance.
      offline - If true, it streams the offline sessions, otherwise the regular sessions.
      skip - The number of leading elements to skip.
      maxResults - The number of elements the stream should be limited to.
      Returns:
      A Stream for all the sessions matching the parameters.