Package org.keycloak.models.jpa.session
Class JpaUserSessionPersisterProvider
java.lang.Object
org.keycloak.models.jpa.session.JpaUserSessionPersisterProvider
- All Implemented Interfaces:
UserSessionPersisterProvider
,Provider
- Author:
- Marek Posolda
-
Constructor Summary
ConstructorDescriptionJpaUserSessionPersisterProvider
(KeycloakSession session, jakarta.persistence.EntityManager em) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
createClientSession
(AuthenticatedClientSessionModel clientSession, boolean offline) void
createUserSession
(UserSessionModel userSession, boolean offline) int
getUserSessionsCount
(boolean offline) Retrieves the count of user sessions for all realms.int
getUserSessionsCount
(RealmModel realm, ClientModel clientModel, boolean offline) Retrieves the count of user client-sessions for the given clientgetUserSessionsCountsByClients
(RealmModel realm, boolean offline) Returns aMap
containing the number of user-sessions aggregated by client id for the given realm.loadClientSession
(RealmModel realm, ClientModel client, UserSessionModel userSession, boolean offline) Loads client session from the db by provided user session and client.loadUserSession
(RealmModel realm, String userSessionId, boolean offline) Loads the user session with the given userSessionId.loadUserSessionsStream
(Integer firstResult, Integer maxResults, boolean offline, String lastUserSessionId) Called during startup.loadUserSessionsStream
(RealmModel realm, ClientModel client, boolean offline, Integer firstResult, Integer maxResults) Loads the user sessions for the givenClientModel
in the givenRealmModel
if present.loadUserSessionsStream
(RealmModel realm, UserModel user, boolean offline, Integer firstResult, Integer maxResults) Loads the user sessions for the givenUserModel
in the givenRealmModel
if present.loadUserSessionsStreamByBrokerSessionId
(RealmModel realm, String brokerSessionId, boolean offline) void
onClientRemoved
(RealmModel realm, ClientModel client) void
onRealmRemoved
(RealmModel realm) void
onUserRemoved
(RealmModel realm, UserModel user) void
removeClientSession
(String userSessionId, String clientUUID, boolean offline) void
removeExpired
(RealmModel realm) void
removeUserSession
(String userSessionId, boolean offline) void
removeUserSessions
(RealmModel realm, boolean offline) Remove the online user sessions for this realm.void
updateLastSessionRefreshes
(RealmModel realm, int lastSessionRefresh, Collection<String> userSessionIds, boolean offline)
-
Constructor Details
-
JpaUserSessionPersisterProvider
public JpaUserSessionPersisterProvider(KeycloakSession session, jakarta.persistence.EntityManager em)
-
-
Method Details
-
createUserSession
- Specified by:
createUserSession
in interfaceUserSessionPersisterProvider
-
createClientSession
- Specified by:
createClientSession
in interfaceUserSessionPersisterProvider
-
removeUserSession
- Specified by:
removeUserSession
in interfaceUserSessionPersisterProvider
-
removeClientSession
- Specified by:
removeClientSession
in interfaceUserSessionPersisterProvider
-
onRealmRemoved
- Specified by:
onRealmRemoved
in interfaceUserSessionPersisterProvider
-
onClientRemoved
- Specified by:
onClientRemoved
in interfaceUserSessionPersisterProvider
-
onUserRemoved
- Specified by:
onUserRemoved
in interfaceUserSessionPersisterProvider
-
updateLastSessionRefreshes
public void updateLastSessionRefreshes(RealmModel realm, int lastSessionRefresh, Collection<String> userSessionIds, boolean offline) - Specified by:
updateLastSessionRefreshes
in interfaceUserSessionPersisterProvider
-
removeExpired
- Specified by:
removeExpired
in interfaceUserSessionPersisterProvider
-
getUserSessionsCountsByClients
Description copied from interface:UserSessionPersisterProvider
Returns aMap
containing the number of user-sessions aggregated by client id for the given realm.- Specified by:
getUserSessionsCountsByClients
in interfaceUserSessionPersisterProvider
- Returns:
- the count
Map
with clientId as key and session count as value
-
loadUserSession
Description copied from interface:UserSessionPersisterProvider
Loads the user session with the given userSessionId.- Specified by:
loadUserSession
in interfaceUserSessionPersisterProvider
- Returns:
-
loadUserSessionsStreamByBrokerSessionId
public UserSessionModel loadUserSessionsStreamByBrokerSessionId(RealmModel realm, String brokerSessionId, boolean offline) - Specified by:
loadUserSessionsStreamByBrokerSessionId
in interfaceUserSessionPersisterProvider
-
loadUserSessionsStream
public Stream<UserSessionModel> loadUserSessionsStream(RealmModel realm, ClientModel client, boolean offline, Integer firstResult, Integer maxResults) Description copied from interface:UserSessionPersisterProvider
Loads the user sessions for the givenClientModel
in the givenRealmModel
if present.- Specified by:
loadUserSessionsStream
in interfaceUserSessionPersisterProvider
- Returns:
-
loadUserSessionsStream
public Stream<UserSessionModel> loadUserSessionsStream(RealmModel realm, UserModel user, boolean offline, Integer firstResult, Integer maxResults) Description copied from interface:UserSessionPersisterProvider
Loads the user sessions for the givenUserModel
in the givenRealmModel
if present.- Specified by:
loadUserSessionsStream
in interfaceUserSessionPersisterProvider
- Returns:
-
loadUserSessionsStream
public Stream<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 interfaceUserSessionPersisterProvider
- Parameters:
firstResult
-Integer
Index of the first desired user session. Ignored if negative ornull
.maxResults
-Integer
Maximum number of returned user sessions. Ignored if negative ornull
.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 returnsnull
.
-
loadClientSession
public AuthenticatedClientSessionModel loadClientSession(RealmModel realm, ClientModel client, 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 interfaceUserSessionPersisterProvider
- 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 interfaceUserSessionPersisterProvider
- Returns:
-
getUserSessionsCount
Description copied from interface:UserSessionPersisterProvider
Retrieves the count of user client-sessions for the given client- Specified by:
getUserSessionsCount
in interfaceUserSessionPersisterProvider
- Returns:
-
removeUserSessions
Description copied from interface:UserSessionPersisterProvider
Remove the online user sessions for this realm.- Specified by:
removeUserSessions
in interfaceUserSessionPersisterProvider
-
close
public void close()
-