Interface UserSessionProvider

All Superinterfaces:
Provider
All Known Implementing Classes:
InfinispanUserSessionProvider, PersistentUserSessionProvider, RemoteUserSessionProvider

public interface UserSessionProvider extends Provider
Version:
$Revision: 1 $
Author:
Bill Burke
  • Method Details

    • getKeycloakSession

      @Deprecated(since="26.4", forRemoval=true) KeycloakSession getKeycloakSession()
      Deprecated, for removal: This API element is subject to removal in a future version.
      for removal.
      Returns currently used Keycloak session.
      Returns:
      KeycloakSession
    • createClientSession

      AuthenticatedClientSessionModel createClientSession(RealmModel realm, ClientModel client, UserSessionModel userSession)
    • getClientSession

      @Deprecated(since="26.4", forRemoval=true) default AuthenticatedClientSessionModel getClientSession(UserSessionModel userSession, ClientModel client, UUID clientSessionId, boolean offline)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getClientSession

      @Deprecated(since="26.4", forRemoval=true) default AuthenticatedClientSessionModel getClientSession(UserSessionModel userSession, ClientModel client, String clientSessionId, boolean offline)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getClientSession

      AuthenticatedClientSessionModel getClientSession(UserSessionModel userSession, ClientModel client, boolean offline)
      Gets the authenticated client session for a given user session and client.
      Parameters:
      userSession - The user's session model.
      client - The client model.
      offline - If true, retrieves the offline session; otherwise, retrieves the online session.
      Returns:
      The authenticated client session, or null if it doesn't exist.
    • createUserSession

      @Deprecated(forRemoval=true) default UserSessionModel createUserSession(RealmModel realm, UserModel user, String loginUsername, String ipAddress, String authMethod, boolean rememberMe, String brokerSessionId, String brokerUserId)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • createUserSession

      UserSessionModel createUserSession(String id, RealmModel realm, UserModel user, String loginUsername, String ipAddress, String authMethod, boolean rememberMe, String brokerSessionId, String brokerUserId, UserSessionModel.SessionPersistenceState persistenceState)
      Creates a new user session with the given parameters.
      Parameters:
      id - identifier. Is generated if null
      realm - the realm
      user - user associated with the created user session
      loginUsername -
      ipAddress -
      authMethod -
      rememberMe -
      brokerSessionId -
      brokerUserId -
      persistenceState -
      Returns:
      Model of the created user session
    • getUserSession

      UserSessionModel getUserSession(RealmModel realm, String id)
    • getUserSessionsStream

      Stream<UserSessionModel> getUserSessionsStream(RealmModel realm, UserModel user)
      Obtains the online user sessions associated with the specified user.
      Parameters:
      realm - a reference to the realm.
      user - the user whose sessions are being searched.
      Returns:
      a non-null Stream of online user sessions.
    • getUserSessionsStream

      Stream<UserSessionModel> getUserSessionsStream(RealmModel realm, ClientModel client)
      Obtains the online user sessions associated with the specified client.
      Parameters:
      realm - a reference to the realm.
      client - the client whose user sessions are being searched.
      Returns:
      a non-null Stream of online user sessions.
    • getUserSessionsStream

      Stream<UserSessionModel> getUserSessionsStream(RealmModel realm, ClientModel client, Integer firstResult, Integer maxResults)
      Obtains the online user sessions associated with the specified client, starting from the firstResult and containing at most maxResults.
      Parameters:
      realm - a reference to the realm.
      client - the client whose user sessions are being searched.
      firstResult - first result to return. Ignored if negative or null.
      maxResults - maximum number of results to return. Ignored if negative or null.
      Returns:
      a non-null Stream of online user sessions.
    • getUserSessionByBrokerUserIdStream

      Stream<UserSessionModel> getUserSessionByBrokerUserIdStream(RealmModel realm, String brokerUserId)
      Obtains the online user sessions associated with the user that matches the specified brokerUserId.
      Parameters:
      realm - a reference to the realm.
      brokerUserId - the id of the broker user whose sessions are being searched.
      Returns:
      a non-null Stream of online user sessions.
    • getUserSessionByBrokerSessionId

      UserSessionModel getUserSessionByBrokerSessionId(RealmModel realm, String brokerSessionId)
    • getUserSessionWithPredicate

      UserSessionModel getUserSessionWithPredicate(RealmModel realm, String id, boolean offline, Predicate<UserSessionModel> predicate)
      Return userSession of specified ID as long as the predicate passes. Otherwise, returns null. If predicate doesn't pass, implementation can do some best-effort actions to try to have predicate passing (e.g. download userSession from other DC)
    • getActiveUserSessions

      long getActiveUserSessions(RealmModel realm, ClientModel client)
    • getActiveClientSessionStats

      Map<String,Long> getActiveClientSessionStats(RealmModel realm, boolean offline)
      Returns a summary of client sessions key is client.getId()
      Parameters:
      realm -
      offline -
      Returns:
    • removeUserSession

      void removeUserSession(RealmModel realm, UserSessionModel session)
      This will remove attached ClientLoginSessionModels too
    • removeUserSessions

      void removeUserSessions(RealmModel realm, UserModel user)
    • removeAllExpired

      @Deprecated(since="26.5", forRemoval=true) default void removeAllExpired()
      Deprecated, for removal: This API element is subject to removal in a future version.
      to be removed without replacement. The providers are responsible for purging the expired entries themselves.
      Remove expired user sessions and client sessions in all the realms
    • removeExpired

      @Deprecated(since="26.5", forRemoval=true) default void removeExpired(RealmModel realm)
      Deprecated, for removal: This API element is subject to removal in a future version.
      to be removed without replacement. The providers are responsible for purging the expired entries themselves.
      Removes expired user sessions owned by this realm from this provider. If this `UserSessionProvider` uses `UserSessionPersister`, the removal of the expired user sessions is also propagated to relevant `UserSessionPersister`.
      Parameters:
      realm - RealmModel Realm where all the expired user sessions to be removed from.
    • removeUserSessions

      void removeUserSessions(RealmModel realm)
      Removes all user sessions (regular and offline) from the specified realm.
      Parameters:
      realm - the realm whose sessions are to be removed.
    • onRealmRemoved

      void onRealmRemoved(RealmModel realm)
      Callback method invoked when a realm is removed. Implementations should clear any sessions associated with the removed realm.
      Parameters:
      realm - a reference to the realm being removed.
    • onClientRemoved

      void onClientRemoved(RealmModel realm, ClientModel client)
      Callback method invoked when a client is removed. Implementations should clear any sessions associated with the removed client.
      Parameters:
      realm - a reference to the realm.
      client - a reference to the client being removed.
    • createOfflineUserSession

      UserSessionModel createOfflineUserSession(UserSessionModel userSession)
      Newly created userSession won't contain attached AuthenticatedClientSessions
    • getOfflineUserSession

      UserSessionModel getOfflineUserSession(RealmModel realm, String userSessionId)
    • removeOfflineUserSession

      void removeOfflineUserSession(RealmModel realm, UserSessionModel userSession)
      Removes the attached clientSessions as well
    • createOfflineClientSession

      AuthenticatedClientSessionModel createOfflineClientSession(AuthenticatedClientSessionModel clientSession, UserSessionModel offlineUserSession)
      Will automatically attach newly created offline client session to the offlineUserSession
    • getOfflineUserSessionsStream

      Stream<UserSessionModel> getOfflineUserSessionsStream(RealmModel realm, UserModel user)
      Obtains the offline user sessions associated with the specified user.
      Parameters:
      realm - a reference to the realm.
      user - the user whose offline sessions are being searched.
      Returns:
      a non-null Stream of offline user sessions.
    • getOfflineUserSessionByBrokerUserIdStream

      Stream<UserSessionModel> getOfflineUserSessionByBrokerUserIdStream(RealmModel realm, String brokerUserId)
      Obtains the offline user sessions associated with the user that matches the specified brokerUserId.
      Parameters:
      realm - a reference to the realm.
      brokerUserId - the id of the broker user whose sessions are being searched.
      Returns:
      a non-null Stream of offline user sessions.
    • getOfflineSessionsCount

      long getOfflineSessionsCount(RealmModel realm, ClientModel client)
    • getOfflineUserSessionsStream

      Stream<UserSessionModel> getOfflineUserSessionsStream(RealmModel realm, ClientModel client, Integer firstResult, Integer maxResults)
      Obtains the offline user sessions associated with the specified client, starting from the firstResult and containing at most maxResults.
      Parameters:
      realm - a reference to the realm.
      client - the client whose user sessions are being searched.
      firstResult - first result to return. Ignored if negative or null.
      maxResults - maximum number of results to return. Ignored if negative or null.
      Returns:
      a non-null Stream of offline user sessions.
    • importUserSessions

      @Deprecated(since="26.4", forRemoval=true) default void importUserSessions(Collection<UserSessionModel> persistentUserSessions, boolean offline)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Deprecated as offline session preloading was removed in KC25. This method will be removed in KC27.
      Triggered by persister during pre-load. It imports authenticatedClientSessions too.
    • close

      void close()
      Specified by:
      close in interface Provider
    • getStartupTime

      int getStartupTime(RealmModel realm)
    • migrate

      default void migrate(String modelVersion)
    • getUserSessionIfClientExists

      default UserSessionModel getUserSessionIfClientExists(RealmModel realm, String userSessionId, boolean offline, String clientUUID)
      Returns the UserSessionModel if the user session with ID userSessionId exist, and it has an AuthenticatedClientSessionModel from a ClientModel with ID clientUUID.

      If the AuthenticatedClientSessionModel from the client or the UserSessionModel does not exist, this method returns null.

      Parameters:
      realm - The RealmModel where the session belongs to.
      userSessionId - The ID of the UserSessionModel.
      offline - If true, it fetches an offline session and, if false, an online session.
      clientUUID - The ClientModel.getId().
      Returns:
      The UserSessionModel if it has a session from the clientUUID.
    • readOnlyStreamUserSessions

      default Stream<UserSessionModel> readOnlyStreamUserSessions(RealmModel realm)
      Stream all the regular sessions in the realm.

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

      Parameters:
      realm - The RealmModel instance.
      Returns:
      A Stream for all the sessions in the realm.
    • readOnlyStreamOfflineUserSessions

      default Stream<UserSessionModel> readOnlyStreamOfflineUserSessions(RealmModel realm)
      Stream all the offline sessions in the realm.

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

      Parameters:
      realm - The RealmModel instance.
      Returns:
      A Stream for all the sessions in the realm.
    • readOnlyStreamUserSessions

      default Stream<UserSessionModel> readOnlyStreamUserSessions(RealmModel realm, ClientModel client)
      Stream all the regular 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 transaction and any modification may throw an UnsupportedOperationException.

      Parameters:
      realm - The RealmModel instance.
      client - The ClientModel instance.
      Returns:
      A Stream for all the sessions matching the parameters.
    • readOnlyStreamOfflineUserSessions

      default Stream<UserSessionModel> readOnlyStreamOfflineUserSessions(RealmModel realm, ClientModel client)
      Stream all the offline 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 transaction and any modification may throw an UnsupportedOperationException.

      Parameters:
      realm - The RealmModel instance.
      client - The ClientModel instance.
      Returns:
      A Stream for all the sessions matching the parameters.