Class InfinispanUserSessionProvider
java.lang.Object
org.keycloak.models.sessions.infinispan.InfinispanUserSessionProvider
- All Implemented Interfaces:
ClientSessionManager,SessionRefreshStore,UserSessionProvider,Provider
public class InfinispanUserSessionProvider
extends Object
implements UserSessionProvider, SessionRefreshStore, ClientSessionManager
- Author:
- Stian Thorgersen
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final InfinispanChangelogBasedTransaction<EmbeddedClientSessionKey,AuthenticatedClientSessionEntity> protected final SessionEventsSenderTransactionprotected final InfinispanKeyGeneratorprotected final SessionFunction<AuthenticatedClientSessionEntity>protected final InfinispanChangelogBasedTransaction<EmbeddedClientSessionKey,AuthenticatedClientSessionEntity> protected final SessionFunction<UserSessionEntity>protected final InfinispanChangelogBasedTransaction<String,UserSessionEntity> protected final PersisterLastSessionRefreshStoreprotected final KeycloakSessionprotected final InfinispanChangelogBasedTransaction<String,UserSessionEntity> -
Constructor Summary
ConstructorsConstructorDescriptionInfinispanUserSessionProvider(KeycloakSession session, PersisterLastSessionRefreshStore persisterLastSessionRefreshStore, InfinispanKeyGenerator keyGenerator, InfinispanChangelogBasedTransaction<String, UserSessionEntity> sessionTx, InfinispanChangelogBasedTransaction<String, UserSessionEntity> offlineSessionTx, InfinispanChangelogBasedTransaction<EmbeddedClientSessionKey, AuthenticatedClientSessionEntity> clientSessionTx, InfinispanChangelogBasedTransaction<EmbeddedClientSessionKey, AuthenticatedClientSessionEntity> offlineClientSessionTx, SessionFunction<UserSessionEntity> offlineSessionCacheEntryLifespanAdjuster, SessionFunction<AuthenticatedClientSessionEntity> offlineClientSessionCacheEntryLifespanAdjuster) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChange(EmbeddedClientSessionKey key, PersistentSessionUpdateTask<AuthenticatedClientSessionEntity> task) Adds a update task to the changelog for a specific client session.voidclose()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.getActiveClientSessionStats(RealmModel realm, boolean offline) Returns a summary of client sessions key is client.getId()longgetActiveUserSessions(RealmModel realm, ClientModel client) protected org.infinispan.Cache<String,SessionEntityWrapper<UserSessionEntity>> getCache(boolean offline) getClientSession(UserSessionModel userSession, ClientModel client, boolean offline) Gets the authenticated client session for a given user session and client.protected org.infinispan.Cache<EmbeddedClientSessionKey,SessionEntityWrapper<AuthenticatedClientSessionEntity>> getClientSessionCache(boolean offline) protected InfinispanChangelogBasedTransaction<EmbeddedClientSessionKey,AuthenticatedClientSessionEntity> getClientSessionTransaction(boolean offline) Returns currently used Keycloak session.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 first, Integer max) 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) getTransaction(boolean offline) getUserSession(RealmModel realm, String id) protected UserSessionAdapter<InfinispanUserSessionProvider>getUserSession(RealmModel realm, String id, boolean offline) getUserSessionByBrokerSessionId(RealmModel realm, String brokerSessionId) getUserSessionByBrokerUserIdStream(RealmModel realm, String brokerUserId) Obtains the online user sessions associated with the user that matches the specifiedbrokerUserId.protected longgetUserSessionsCount(RealmModel realm, ClientModel client, boolean offline) 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.protected Stream<UserSessionModel>getUserSessionsStream(RealmModel realm, ClientModel client, Integer firstResult, Integer maxResults, boolean offline) protected Stream<UserSessionModel>getUserSessionsStream(RealmModel realm, UserSessionPredicate predicate, boolean offline) 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.protected UserSessionAdapter<InfinispanUserSessionProvider>importUserSession(UserSessionModel userSession) voidimportUserSessions(Collection<UserSessionModel> persistentUserSessions, boolean offline) Deprecated, for removal: This API element is subject to removal in a future version.voidvoidonClientRemoved(RealmModel realm, ClientModel client) Callback method invoked when a client is removed.voidonRealmRemoved(RealmModel realm) Callback method invoked when a realm is removed.protected voidonRealmRemovedEvent(String realmId) protected voidonRemoveUserSessionsEvent(String realmId) protected voidonUserRemoved(RealmModel realm, UserModel user) voidRemove expired user sessions and client sessions in all the realmsvoidremoveExpired(RealmModel realm) Removes expired user sessions owned by this realm from this provider.voidremoveLocalUserSessions(String realmId, boolean offline) voidremoveOfflineUserSession(RealmModel realm, UserSessionModel userSession) Removes the attached clientSessions as wellvoidremoveUserSession(RealmModel realm, UserSessionModel session) This will remove attached ClientLoginSessionModels tooprotected voidremoveUserSession(UserSessionEntity sessionEntity, boolean offline) voidremoveUserSessions(RealmModel realm) Removes all user sessions (regular and offline) from the specified realm.voidremoveUserSessions(RealmModel realm, UserModel user) protected voidremoveUserSessions(RealmModel realm, UserModel user, boolean offline) voidrestartEntity(EmbeddedClientSessionKey key, PersistentSessionUpdateTask<AuthenticatedClientSessionEntity> task) Resets and replaces the state of the persistedAuthenticatedClientSessionEntityfor the given session.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.keycloak.models.UserSessionProvider
createUserSession, getClientSession, getClientSession, getUserSessionIfClientExists
-
Field Details
-
session
-
sessionTx
-
offlineSessionTx
-
clientSessionTx
protected final InfinispanChangelogBasedTransaction<EmbeddedClientSessionKey,AuthenticatedClientSessionEntity> clientSessionTx -
offlineClientSessionTx
protected final InfinispanChangelogBasedTransaction<EmbeddedClientSessionKey,AuthenticatedClientSessionEntity> offlineClientSessionTx -
clusterEventsSenderTx
-
persisterLastSessionRefreshStore
-
keyGenerator
-
offlineSessionCacheEntryLifespanAdjuster
-
offlineClientSessionCacheEntryLifespanAdjuster
protected final SessionFunction<AuthenticatedClientSessionEntity> offlineClientSessionCacheEntryLifespanAdjuster
-
-
Constructor Details
-
InfinispanUserSessionProvider
public InfinispanUserSessionProvider(KeycloakSession session, PersisterLastSessionRefreshStore persisterLastSessionRefreshStore, InfinispanKeyGenerator keyGenerator, InfinispanChangelogBasedTransaction<String, UserSessionEntity> sessionTx, InfinispanChangelogBasedTransaction<String, UserSessionEntity> offlineSessionTx, InfinispanChangelogBasedTransaction<EmbeddedClientSessionKey, AuthenticatedClientSessionEntity> clientSessionTx, InfinispanChangelogBasedTransaction<EmbeddedClientSessionKey, AuthenticatedClientSessionEntity> offlineClientSessionTx, SessionFunction<UserSessionEntity> offlineSessionCacheEntryLifespanAdjuster, SessionFunction<AuthenticatedClientSessionEntity> offlineClientSessionCacheEntryLifespanAdjuster)
-
-
Method Details
-
getCache
protected org.infinispan.Cache<String,SessionEntityWrapper<UserSessionEntity>> getCache(boolean offline) -
getTransaction
protected InfinispanChangelogBasedTransaction<String,UserSessionEntity> getTransaction(boolean offline) -
getClientSessionCache
protected org.infinispan.Cache<EmbeddedClientSessionKey,SessionEntityWrapper<AuthenticatedClientSessionEntity>> getClientSessionCache(boolean offline) -
getClientSessionTransaction
protected InfinispanChangelogBasedTransaction<EmbeddedClientSessionKey,AuthenticatedClientSessionEntity> getClientSessionTransaction(boolean offline) -
getPersisterLastSessionRefreshStore
- Specified by:
getPersisterLastSessionRefreshStorein interfaceSessionRefreshStore
-
getKeycloakSession
Description copied from interface:UserSessionProviderReturns currently used Keycloak session.- Specified by:
getKeycloakSessionin interfaceUserSessionProvider- Returns:
KeycloakSession
-
createClientSession
public AuthenticatedClientSessionModel createClientSession(RealmModel realm, ClientModel client, UserSessionModel userSession) - Specified by:
createClientSessionin interfaceUserSessionProvider
-
createUserSession
public UserSessionModel createUserSession(String id, RealmModel realm, UserModel user, String loginUsername, String ipAddress, String authMethod, boolean rememberMe, String brokerSessionId, String brokerUserId, UserSessionModel.SessionPersistenceState persistenceState) Description copied from interface:UserSessionProviderCreates a new user session with the given parameters.- Specified by:
createUserSessionin interfaceUserSessionProvider- Parameters:
id- identifier. Is generated ifnullrealm- the realmuser- user associated with the created user session- Returns:
- Model of the created user session
-
getUserSession
- Specified by:
getUserSessionin interfaceUserSessionProvider
-
migrate
- Specified by:
migratein interfaceUserSessionProvider
-
getUserSession
protected UserSessionAdapter<InfinispanUserSessionProvider> getUserSession(RealmModel realm, String id, boolean offline) -
getUserSessionsStream
protected Stream<UserSessionModel> getUserSessionsStream(RealmModel realm, UserSessionPredicate predicate, boolean offline) -
getClientSession
public AuthenticatedClientSessionAdapter getClientSession(UserSessionModel userSession, ClientModel client, boolean offline) Description copied from interface:UserSessionProviderGets the authenticated client session for a given user session and client.- Specified by:
getClientSessionin interfaceUserSessionProvider- 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.
-
getUserSessionsStream
Description copied from interface:UserSessionProviderObtains the online user sessions associated with the specified user.- Specified by:
getUserSessionsStreamin interfaceUserSessionProvider- Parameters:
realm- a reference to the realm.user- the user whose sessions are being searched.- Returns:
- a non-null
Streamof online user sessions.
-
getUserSessionByBrokerUserIdStream
public Stream<UserSessionModel> getUserSessionByBrokerUserIdStream(RealmModel realm, String brokerUserId) Description copied from interface:UserSessionProviderObtains the online user sessions associated with the user that matches the specifiedbrokerUserId.- Specified by:
getUserSessionByBrokerUserIdStreamin interfaceUserSessionProvider- 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
- Specified by:
getUserSessionByBrokerSessionIdin interfaceUserSessionProvider
-
getUserSessionsStream
Description copied from interface:UserSessionProviderObtains the online user sessions associated with the specified client.- Specified by:
getUserSessionsStreamin interfaceUserSessionProvider- 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
public Stream<UserSessionModel> getUserSessionsStream(RealmModel realm, ClientModel client, Integer firstResult, Integer maxResults) Description copied from interface:UserSessionProviderObtains the online user sessions associated with the specified client, starting from thefirstResultand containing at mostmaxResults.- Specified by:
getUserSessionsStreamin interfaceUserSessionProvider- 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.
-
getUserSessionsStream
protected Stream<UserSessionModel> getUserSessionsStream(RealmModel realm, ClientModel client, Integer firstResult, Integer maxResults, boolean offline) -
getUserSessionWithPredicate
public UserSessionModel getUserSessionWithPredicate(RealmModel realm, String id, boolean offline, Predicate<UserSessionModel> predicate) Description copied from interface:UserSessionProviderReturn 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)- Specified by:
getUserSessionWithPredicatein interfaceUserSessionProvider
-
getActiveUserSessions
- Specified by:
getActiveUserSessionsin interfaceUserSessionProvider
-
getActiveClientSessionStats
Description copied from interface:UserSessionProviderReturns a summary of client sessions key is client.getId()- Specified by:
getActiveClientSessionStatsin interfaceUserSessionProvider- Returns:
-
getUserSessionsCount
-
removeUserSession
Description copied from interface:UserSessionProviderThis will remove attached ClientLoginSessionModels too- Specified by:
removeUserSessionin interfaceUserSessionProvider
-
removeUserSessions
- Specified by:
removeUserSessionsin interfaceUserSessionProvider
-
removeUserSessions
-
removeAllExpired
public void removeAllExpired()Description copied from interface:UserSessionProviderRemove expired user sessions and client sessions in all the realms- Specified by:
removeAllExpiredin interfaceUserSessionProvider
-
removeExpired
Description copied from interface:UserSessionProviderRemoves 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`.- Specified by:
removeExpiredin interfaceUserSessionProvider- Parameters:
realm-RealmModelRealm where all the expired user sessions to be removed from.
-
removeUserSessions
Description copied from interface:UserSessionProviderRemoves all user sessions (regular and offline) from the specified realm.- Specified by:
removeUserSessionsin interfaceUserSessionProvider- Parameters:
realm- the realm whose sessions are to be removed.
-
onRemoveUserSessionsEvent
-
removeLocalUserSessions
-
onRealmRemoved
Description copied from interface:UserSessionProviderCallback method invoked when a realm is removed. Implementations should clear any sessions associated with the removed realm.- Specified by:
onRealmRemovedin interfaceUserSessionProvider- Parameters:
realm- a reference to the realm being removed.
-
onRealmRemovedEvent
-
onClientRemoved
Description copied from interface:UserSessionProviderCallback method invoked when a client is removed. Implementations should clear any sessions associated with the removed client.- Specified by:
onClientRemovedin interfaceUserSessionProvider- Parameters:
realm- a reference to the realm.client- a reference to the client being removed.
-
onUserRemoved
-
close
public void close()- Specified by:
closein interfaceProvider- Specified by:
closein interfaceUserSessionProvider
-
getStartupTime
- Specified by:
getStartupTimein interfaceUserSessionProvider
-
removeUserSession
-
createOfflineUserSession
Description copied from interface:UserSessionProviderNewly created userSession won't contain attached AuthenticatedClientSessions- Specified by:
createOfflineUserSessionin interfaceUserSessionProvider
-
getOfflineUserSession
public UserSessionAdapter<InfinispanUserSessionProvider> getOfflineUserSession(RealmModel realm, String userSessionId) - Specified by:
getOfflineUserSessionin interfaceUserSessionProvider
-
getOfflineUserSessionByBrokerUserIdStream
public Stream<UserSessionModel> getOfflineUserSessionByBrokerUserIdStream(RealmModel realm, String brokerUserId) Description copied from interface:UserSessionProviderObtains the offline user sessions associated with the user that matches the specifiedbrokerUserId.- Specified by:
getOfflineUserSessionByBrokerUserIdStreamin interfaceUserSessionProvider- 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.
-
removeOfflineUserSession
Description copied from interface:UserSessionProviderRemoves the attached clientSessions as well- Specified by:
removeOfflineUserSessionin interfaceUserSessionProvider
-
createOfflineClientSession
public AuthenticatedClientSessionModel createOfflineClientSession(AuthenticatedClientSessionModel clientSession, UserSessionModel offlineUserSession) Description copied from interface:UserSessionProviderWill automatically attach newly created offline client session to the offlineUserSession- Specified by:
createOfflineClientSessionin interfaceUserSessionProvider
-
getOfflineUserSessionsStream
Description copied from interface:UserSessionProviderObtains the offline user sessions associated with the specified user.- Specified by:
getOfflineUserSessionsStreamin interfaceUserSessionProvider- Parameters:
realm- a reference to the realm.user- the user whose offline sessions are being searched.- Returns:
- a non-null
Streamof offline user sessions.
-
getOfflineSessionsCount
- Specified by:
getOfflineSessionsCountin interfaceUserSessionProvider
-
getOfflineUserSessionsStream
public Stream<UserSessionModel> getOfflineUserSessionsStream(RealmModel realm, ClientModel client, Integer first, Integer max) Description copied from interface:UserSessionProviderObtains the offline user sessions associated with the specified client, starting from thefirstResultand containing at mostmaxResults.- Specified by:
getOfflineUserSessionsStreamin interfaceUserSessionProvider- Parameters:
realm- a reference to the realm.client- the client whose user sessions are being searched.first- first result to return. Ignored if negative ornull.max- maximum number of results to return. Ignored if negative ornull.- Returns:
- a non-null
Streamof offline user sessions.
-
importUserSessions
@Deprecated(forRemoval=true, since="25.0") public void importUserSessions(Collection<UserSessionModel> persistentUserSessions, boolean offline) Deprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:UserSessionProviderTriggered by persister during pre-load. It imports authenticatedClientSessions too.- Specified by:
importUserSessionsin interfaceUserSessionProvider
-
importUserSession
protected UserSessionAdapter<InfinispanUserSessionProvider> importUserSession(UserSessionModel userSession) -
addChange
public void addChange(EmbeddedClientSessionKey key, PersistentSessionUpdateTask<AuthenticatedClientSessionEntity> task) Description copied from interface:ClientSessionManagerAdds a update task to the changelog for a specific client session.When the transaction commits, this task will apply its changes to the persisted
AuthenticatedClientSessionEntity, effectively updating the correspondingAuthenticatedClientSessionModel. MultipleaddChangecalls for the same session are accumulated (merged).- Specified by:
addChangein interfaceClientSessionManager- Parameters:
key- The identifier for the target client session.task- The operation containing the changes to apply to the persisted entity.
-
restartEntity
public void restartEntity(EmbeddedClientSessionKey key, PersistentSessionUpdateTask<AuthenticatedClientSessionEntity> task) Description copied from interface:ClientSessionManagerResets and replaces the state of the persistedAuthenticatedClientSessionEntityfor the given session.All previously added changes via
addChangefor this session are discarded, and the provided task is executed to set the new state of the client session entity.- Specified by:
restartEntityin interfaceClientSessionManager- Parameters:
key- The identifier for the target client session.task- The operation that must set the complete new state of the persisted entity.
-