Package org.keycloak.models
Interface UserSessionProvider
- All Superinterfaces:
Provider
- All Known Implementing Classes:
InfinispanUserSessionProvider,PersistentUserSessionProvider,RemoteUserSessionProvider
- Version:
- $Revision: 1 $
- Author:
- Bill Burke
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()createClientSession(RealmModel realm, ClientModel client, UserSessionModel userSession) createOfflineClientSession(AuthenticatedClientSessionModel clientSession, UserSessionModel offlineUserSession) Will automatically attach newly created offline client session to the offlineUserSessioncreateOfflineUserSession(UserSessionModel userSession) Newly created userSession won't contain attached AuthenticatedClientSessionscreateUserSession(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.default UserSessionModelcreateUserSession(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.getActiveClientSessionStats(RealmModel realm, boolean offline) Returns a summary of client sessions key is client.getId()longgetActiveUserSessions(RealmModel realm, ClientModel client) getClientSession(UserSessionModel userSession, ClientModel client, boolean offline) Gets the authenticated client session for a given user session and client.default AuthenticatedClientSessionModelgetClientSession(UserSessionModel userSession, ClientModel client, String clientSessionId, boolean offline) Deprecated, for removal: This API element is subject to removal in a future version.default AuthenticatedClientSessionModelgetClientSession(UserSessionModel userSession, ClientModel client, UUID clientSessionId, boolean offline) Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.for removal.longgetOfflineSessionsCount(RealmModel realm, ClientModel client) getOfflineUserSession(RealmModel realm, String userSessionId) getOfflineUserSessionByBrokerUserIdStream(RealmModel realm, String brokerUserId) Obtains the offline user sessions associated with the user that matches the specifiedbrokerUserId.getOfflineUserSessionsStream(RealmModel realm, ClientModel client, Integer firstResult, Integer maxResults) Obtains the offline user sessions associated with the specified client, starting from thefirstResultand containing at mostmaxResults.getOfflineUserSessionsStream(RealmModel realm, UserModel user) Obtains the offline user sessions associated with the specified user.intgetStartupTime(RealmModel realm) getUserSession(RealmModel realm, String id) getUserSessionByBrokerSessionId(RealmModel realm, String brokerSessionId) getUserSessionByBrokerUserIdStream(RealmModel realm, String brokerUserId) Obtains the online user sessions associated with the user that matches the specifiedbrokerUserId.default UserSessionModelgetUserSessionIfClientExists(RealmModel realm, String userSessionId, boolean offline, String clientUUID) Returns theUserSessionModelif the user session with IDuserSessionIdexist, and it has anAuthenticatedClientSessionModelfrom aClientModelwith IDclientUUID.getUserSessionsStream(RealmModel realm, ClientModel client) Obtains the online user sessions associated with the specified client.getUserSessionsStream(RealmModel realm, ClientModel client, Integer firstResult, Integer maxResults) Obtains the online user sessions associated with the specified client, starting from thefirstResultand containing at mostmaxResults.getUserSessionsStream(RealmModel realm, UserModel user) Obtains the online user sessions associated with the specified user.getUserSessionWithPredicate(RealmModel realm, String id, boolean offline, Predicate<UserSessionModel> predicate) Return userSession of specified ID as long as the predicate passes.default voidimportUserSessions(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.default voidvoidonClientRemoved(RealmModel realm, ClientModel client) Callback method invoked when a client is removed.voidonRealmRemoved(RealmModel realm) Callback method invoked when a realm is removed.voidRemove expired user sessions and client sessions in all the realmsvoidremoveExpired(RealmModel realm) Removes expired user sessions owned by this realm from this provider.voidremoveOfflineUserSession(RealmModel realm, UserSessionModel userSession) Removes the attached clientSessions as wellvoidremoveUserSession(RealmModel realm, UserSessionModel session) This will remove attached ClientLoginSessionModels toovoidremoveUserSessions(RealmModel realm) Removes all user sessions (regular and offline) from the specified realm.voidremoveUserSessions(RealmModel realm, UserModel user)
-
Method Details
-
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- Iftrue, retrieves the offline session; otherwise, retrieves the online session.- Returns:
- The authenticated client session, or
nullif 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 ifnullrealm- the realmuser- user associated with the created user sessionloginUsername-ipAddress-authMethod-rememberMe-brokerSessionId-brokerUserId-persistenceState-- Returns:
- Model of the created user session
-
getUserSession
-
getUserSessionsStream
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
Streamof online user sessions.
-
getUserSessionsStream
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
Streamof 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 thefirstResultand containing at mostmaxResults.- Parameters:
realm- a reference to the realm.client- the client whose user sessions are being searched.firstResult- first result to return. Ignored if negative ornull.maxResults- maximum number of results to return. Ignored if negative ornull.- Returns:
- a non-null
Streamof online user sessions.
-
getUserSessionByBrokerUserIdStream
Obtains the online user sessions associated with the user that matches the specifiedbrokerUserId.- Parameters:
realm- a reference to the realm.brokerUserId- the id of the broker user whose sessions are being searched.- Returns:
- a non-null
Streamof online user sessions.
-
getUserSessionByBrokerSessionId
-
getUserSessionWithPredicate
UserSessionModel getUserSessionWithPredicate(RealmModel realm, String id, boolean offline, Predicate<UserSessionModel> predicate) Return userSession of specified ID as long as the predicate passes. Otherwise, returnsnull. 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
-
getActiveClientSessionStats
Returns a summary of client sessions key is client.getId()- Parameters:
realm-offline-- Returns:
-
removeUserSession
This will remove attached ClientLoginSessionModels too -
removeUserSessions
-
removeAllExpired
void removeAllExpired()Remove expired user sessions and client sessions in all the realms -
removeExpired
Removes expired user sessions owned by this realm from this provider. If this `UserSessionProvider` uses `UserSessionPersister`, the removal of the expireduser sessionsis also propagated to relevant `UserSessionPersister`.- Parameters:
realm-RealmModelRealm where all the expired user sessions to be removed from.
-
removeUserSessions
Removes all user sessions (regular and offline) from the specified realm.- Parameters:
realm- the realm whose sessions are to be removed.
-
onRealmRemoved
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
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
Newly created userSession won't contain attached AuthenticatedClientSessions -
getOfflineUserSession
-
removeOfflineUserSession
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
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
Streamof offline user sessions.
-
getOfflineUserSessionByBrokerUserIdStream
Stream<UserSessionModel> getOfflineUserSessionByBrokerUserIdStream(RealmModel realm, String brokerUserId) Obtains the offline user sessions associated with the user that matches the specifiedbrokerUserId.- Parameters:
realm- a reference to the realm.brokerUserId- the id of the broker user whose sessions are being searched.- Returns:
- a non-null
Streamof offline user sessions.
-
getOfflineSessionsCount
-
getOfflineUserSessionsStream
Stream<UserSessionModel> getOfflineUserSessionsStream(RealmModel realm, ClientModel client, Integer firstResult, Integer maxResults) Obtains the offline user sessions associated with the specified client, starting from thefirstResultand containing at mostmaxResults.- Parameters:
realm- a reference to the realm.client- the client whose user sessions are being searched.firstResult- first result to return. Ignored if negative ornull.maxResults- maximum number of results to return. Ignored if negative ornull.- Returns:
- a non-null
Streamof 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() -
getStartupTime
-
migrate
-
getUserSessionIfClientExists
default UserSessionModel getUserSessionIfClientExists(RealmModel realm, String userSessionId, boolean offline, String clientUUID) Returns theUserSessionModelif the user session with IDuserSessionIdexist, and it has anAuthenticatedClientSessionModelfrom aClientModelwith IDclientUUID.If the
AuthenticatedClientSessionModelfrom the client or theUserSessionModeldoes not exist, this method returnsnull.- Parameters:
realm- TheRealmModelwhere the session belongs to.userSessionId- The ID of theUserSessionModel.offline- Iftrue, it fetches an offline session and, iffalse, an online session.clientUUID- TheClientModel.getId().- Returns:
- The
UserSessionModelif it has a session from theclientUUID.
-
createUserSession(String, RealmModel, UserModel, String, String, String, boolean, String, String, UserSessionModel.SessionPersistenceState)instead.