Class InfinispanUserSessionProvider
- java.lang.Object
- 
- org.keycloak.models.sessions.infinispan.InfinispanUserSessionProvider
 
- 
- All Implemented Interfaces:
- UserSessionProvider,- Provider
 
 public class InfinispanUserSessionProvider extends Object implements UserSessionProvider - Author:
- Stian Thorgersen
 
- 
- 
Field Summary
 - 
Constructor SummaryConstructors Constructor Description InfinispanUserSessionProvider(KeycloakSession session, RemoteCacheInvoker remoteCacheInvoker, CrossDCLastSessionRefreshStore lastSessionRefreshStore, CrossDCLastSessionRefreshStore offlineLastSessionRefreshStore, PersisterLastSessionRefreshStore persisterLastSessionRefreshStore, InfinispanKeyGenerator keyGenerator, org.infinispan.Cache<String,SessionEntityWrapper<UserSessionEntity>> sessionCache, org.infinispan.Cache<String,SessionEntityWrapper<UserSessionEntity>> offlineSessionCache, org.infinispan.Cache<UUID,SessionEntityWrapper<AuthenticatedClientSessionEntity>> clientSessionCache, org.infinispan.Cache<UUID,SessionEntityWrapper<AuthenticatedClientSessionEntity>> offlineClientSessionCache, boolean loadOfflineSessionsFromDatabase)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()AuthenticatedClientSessionModelcreateClientSession(RealmModel realm, ClientModel client, UserSessionModel userSession)AuthenticatedClientSessionModelcreateOfflineClientSession(AuthenticatedClientSessionModel clientSession, UserSessionModel offlineUserSession)Will automatically attach newly created offline client session to the offlineUserSessionUserSessionModelcreateOfflineUserSession(UserSessionModel userSession)Newly created userSession won't contain attached AuthenticatedClientSessionsUserSessionModelcreateUserSession(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.Map<String,Long>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)AuthenticatedClientSessionAdaptergetClientSession(UserSessionModel userSession, ClientModel client, String clientSessionId, boolean offline)protected org.infinispan.Cache<UUID,SessionEntityWrapper<AuthenticatedClientSessionEntity>>getClientSessionCache(boolean offline)protected InfinispanChangelogBasedTransaction<UUID,AuthenticatedClientSessionEntity>getClientSessionTransaction(boolean offline)KeycloakSessiongetKeycloakSession()Returns currently used Keycloak session.protected CrossDCLastSessionRefreshStoregetLastSessionRefreshStore()protected CrossDCLastSessionRefreshStoregetOfflineLastSessionRefreshStore()longgetOfflineSessionsCount(RealmModel realm, ClientModel client)UserSessionAdaptergetOfflineUserSession(RealmModel realm, String userSessionId)UserSessionModelgetOfflineUserSessionByBrokerSessionId(RealmModel realm, String brokerSessionId)Stream<UserSessionModel>getOfflineUserSessionByBrokerUserIdStream(RealmModel realm, String brokerUserId)Obtains the offline user sessions associated with the user that matches the specifiedbrokerUserId.Stream<UserSessionModel>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.Stream<UserSessionModel>getOfflineUserSessionsStream(RealmModel realm, UserModel user)Obtains the offline user sessions associated with the specified user.protected PersisterLastSessionRefreshStoregetPersisterLastSessionRefreshStore()intgetStartupTime(RealmModel realm)protected InfinispanChangelogBasedTransaction<String,UserSessionEntity>getTransaction(boolean offline)UserSessionModelgetUserSession(RealmModel realm, String id)protected UserSessionAdaptergetUserSession(RealmModel realm, String id, boolean offline)UserSessionModelgetUserSessionByBrokerSessionId(RealmModel realm, String brokerSessionId)Stream<UserSessionModel>getUserSessionByBrokerUserIdStream(RealmModel realm, String brokerUserId)Obtains the online user sessions associated with the user that matches the specifiedbrokerUserId.protected Stream<UserSessionModel>getUserSessionModels(RealmModel realm, Integer firstResult, Integer maxResults, boolean offline, UserSessionPredicate predicate)protected longgetUserSessionsCount(RealmModel realm, ClientModel client, boolean offline)Stream<UserSessionModel>getUserSessionsStream(RealmModel realm, ClientModel client)Obtains the online user sessions associated with the specified client.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.protected Stream<UserSessionModel>getUserSessionsStream(RealmModel realm, ClientModel client, Integer firstResult, Integer maxResults, boolean offline)protected Stream<UserSessionModel>getUserSessionsStream(RealmModel realm, UserSessionPredicate predicate, boolean offline)Stream<UserSessionModel>getUserSessionsStream(RealmModel realm, UserModel user)Obtains the online user sessions associated with the specified user.UserSessionModelgetUserSessionWithPredicate(RealmModel realm, String id, boolean offline, Predicate<UserSessionModel> predicate)Return userSession of specified ID as long as the predicate passes.protected UserSessionAdapterimportUserSession(UserSessionModel userSession, boolean offline)voidimportUserSessions(Collection<UserSessionModel> persistentUserSessions, boolean offline)Triggered by persister during pre-load.voidonClientRemoved(RealmModel realm, ClientModel client)protected voidonClientRemovedEvent(String realmId, String clientUuid)voidonRealmRemoved(RealmModel realm)protected voidonRealmRemovedEvent(String realmId)protected voidonRemoveUserSessionsEvent(String realmId)protected voidonUserRemoved(RealmModel realm, UserModel user)voidremoveAllExpired()Remove 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)voidremoveUserSessions(RealmModel realm, UserModel user)protected voidremoveUserSessions(RealmModel realm, UserModel user, boolean offline)- 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface org.keycloak.models.UserSessionProvidercreateUserSession, getClientSession
 
- 
 
- 
- 
- 
Field Detail- 
sessionprotected final KeycloakSession session 
 - 
sessionCacheprotected final org.infinispan.Cache<String,SessionEntityWrapper<UserSessionEntity>> sessionCache 
 - 
offlineSessionCacheprotected final org.infinispan.Cache<String,SessionEntityWrapper<UserSessionEntity>> offlineSessionCache 
 - 
clientSessionCacheprotected final org.infinispan.Cache<UUID,SessionEntityWrapper<AuthenticatedClientSessionEntity>> clientSessionCache 
 - 
offlineClientSessionCacheprotected final org.infinispan.Cache<UUID,SessionEntityWrapper<AuthenticatedClientSessionEntity>> offlineClientSessionCache 
 - 
sessionTxprotected final InfinispanChangelogBasedTransaction<String,UserSessionEntity> sessionTx 
 - 
offlineSessionTxprotected final InfinispanChangelogBasedTransaction<String,UserSessionEntity> offlineSessionTx 
 - 
clientSessionTxprotected final InfinispanChangelogBasedTransaction<UUID,AuthenticatedClientSessionEntity> clientSessionTx 
 - 
offlineClientSessionTxprotected final InfinispanChangelogBasedTransaction<UUID,AuthenticatedClientSessionEntity> offlineClientSessionTx 
 - 
clusterEventsSenderTxprotected final SessionEventsSenderTransaction clusterEventsSenderTx 
 - 
lastSessionRefreshStoreprotected final CrossDCLastSessionRefreshStore lastSessionRefreshStore 
 - 
offlineLastSessionRefreshStoreprotected final CrossDCLastSessionRefreshStore offlineLastSessionRefreshStore 
 - 
persisterLastSessionRefreshStoreprotected final PersisterLastSessionRefreshStore persisterLastSessionRefreshStore 
 - 
remoteCacheInvokerprotected final RemoteCacheInvoker remoteCacheInvoker 
 - 
keyGeneratorprotected final InfinispanKeyGenerator keyGenerator 
 - 
loadOfflineSessionsFromDatabaseprotected final boolean loadOfflineSessionsFromDatabase 
 
- 
 - 
Constructor Detail- 
InfinispanUserSessionProviderpublic InfinispanUserSessionProvider(KeycloakSession session, RemoteCacheInvoker remoteCacheInvoker, CrossDCLastSessionRefreshStore lastSessionRefreshStore, CrossDCLastSessionRefreshStore offlineLastSessionRefreshStore, PersisterLastSessionRefreshStore persisterLastSessionRefreshStore, InfinispanKeyGenerator keyGenerator, org.infinispan.Cache<String,SessionEntityWrapper<UserSessionEntity>> sessionCache, org.infinispan.Cache<String,SessionEntityWrapper<UserSessionEntity>> offlineSessionCache, org.infinispan.Cache<UUID,SessionEntityWrapper<AuthenticatedClientSessionEntity>> clientSessionCache, org.infinispan.Cache<UUID,SessionEntityWrapper<AuthenticatedClientSessionEntity>> offlineClientSessionCache, boolean loadOfflineSessionsFromDatabase) 
 
- 
 - 
Method Detail- 
getCacheprotected org.infinispan.Cache<String,SessionEntityWrapper<UserSessionEntity>> getCache(boolean offline) 
 - 
getTransactionprotected InfinispanChangelogBasedTransaction<String,UserSessionEntity> getTransaction(boolean offline) 
 - 
getClientSessionCacheprotected org.infinispan.Cache<UUID,SessionEntityWrapper<AuthenticatedClientSessionEntity>> getClientSessionCache(boolean offline) 
 - 
getClientSessionTransactionprotected InfinispanChangelogBasedTransaction<UUID,AuthenticatedClientSessionEntity> getClientSessionTransaction(boolean offline) 
 - 
getLastSessionRefreshStoreprotected CrossDCLastSessionRefreshStore getLastSessionRefreshStore() 
 - 
getOfflineLastSessionRefreshStoreprotected CrossDCLastSessionRefreshStore getOfflineLastSessionRefreshStore() 
 - 
getPersisterLastSessionRefreshStoreprotected PersisterLastSessionRefreshStore getPersisterLastSessionRefreshStore() 
 - 
getKeycloakSessionpublic KeycloakSession getKeycloakSession() Description copied from interface:UserSessionProviderReturns currently used Keycloak session.- Specified by:
- getKeycloakSessionin interface- UserSessionProvider
- Returns:
- KeycloakSession
 
 - 
createClientSessionpublic AuthenticatedClientSessionModel createClientSession(RealmModel realm, ClientModel client, UserSessionModel userSession) - Specified by:
- createClientSessionin interface- UserSessionProvider
 
 - 
createUserSessionpublic 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 interface- UserSessionProvider
- Parameters:
- id- identifier. Is generated if- null
- realm- the realm
- user- user associated with the created user session
- Returns:
- Model of the created user session
 
 - 
getUserSessionpublic UserSessionModel getUserSession(RealmModel realm, String id) - Specified by:
- getUserSessionin interface- UserSessionProvider
 
 - 
getUserSessionprotected UserSessionAdapter getUserSession(RealmModel realm, String id, boolean offline) 
 - 
getUserSessionsStreamprotected Stream<UserSessionModel> getUserSessionsStream(RealmModel realm, UserSessionPredicate predicate, boolean offline) 
 - 
getClientSessionpublic AuthenticatedClientSessionAdapter getClientSession(UserSessionModel userSession, ClientModel client, String clientSessionId, boolean offline) - Specified by:
- getClientSessionin interface- UserSessionProvider
 
 - 
getUserSessionsStreampublic Stream<UserSessionModel> getUserSessionsStream(RealmModel realm, UserModel user) Description copied from interface:UserSessionProviderObtains the online user sessions associated with the specified user.- Specified by:
- getUserSessionsStreamin interface- UserSessionProvider
- Parameters:
- realm- a reference to the realm.
- user- the user whose sessions are being searched.
- Returns:
- a non-null Streamof online user sessions.
 
 - 
getUserSessionByBrokerUserIdStreampublic 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 interface- UserSessionProvider
- 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.
 
 - 
getUserSessionByBrokerSessionIdpublic UserSessionModel getUserSessionByBrokerSessionId(RealmModel realm, String brokerSessionId) - Specified by:
- getUserSessionByBrokerSessionIdin interface- UserSessionProvider
 
 - 
getUserSessionsStreampublic Stream<UserSessionModel> getUserSessionsStream(RealmModel realm, ClientModel client) Description copied from interface:UserSessionProviderObtains the online user sessions associated with the specified client.- Specified by:
- getUserSessionsStreamin interface- UserSessionProvider
- Parameters:
- realm- a reference to the realm.
- client- the client whose user sessions are being searched.
- Returns:
- a non-null Streamof online user sessions.
 
 - 
getUserSessionsStreampublic 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 interface- UserSessionProvider
- Parameters:
- realm- a reference tot he 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 Streamof online user sessions.
 
 - 
getUserSessionsStreamprotected Stream<UserSessionModel> getUserSessionsStream(RealmModel realm, ClientModel client, Integer firstResult, Integer maxResults, boolean offline) 
 - 
getUserSessionModelsprotected Stream<UserSessionModel> getUserSessionModels(RealmModel realm, Integer firstResult, Integer maxResults, boolean offline, UserSessionPredicate predicate) 
 - 
getUserSessionWithPredicatepublic 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 have predicate passing (eg. download userSession from other DC)- Specified by:
- getUserSessionWithPredicatein interface- UserSessionProvider
 
 - 
getActiveUserSessionspublic long getActiveUserSessions(RealmModel realm, ClientModel client) - Specified by:
- getActiveUserSessionsin interface- UserSessionProvider
 
 - 
getActiveClientSessionStatspublic Map<String,Long> getActiveClientSessionStats(RealmModel realm, boolean offline) Description copied from interface:UserSessionProviderReturns a summary of client sessions key is client.getId()- Specified by:
- getActiveClientSessionStatsin interface- UserSessionProvider
- Returns:
 
 - 
getUserSessionsCountprotected long getUserSessionsCount(RealmModel realm, ClientModel client, boolean offline) 
 - 
removeUserSessionpublic void removeUserSession(RealmModel realm, UserSessionModel session) Description copied from interface:UserSessionProviderThis will remove attached ClientLoginSessionModels too- Specified by:
- removeUserSessionin interface- UserSessionProvider
 
 - 
removeUserSessionspublic void removeUserSessions(RealmModel realm, UserModel user) - Specified by:
- removeUserSessionsin interface- UserSessionProvider
 
 - 
removeUserSessionsprotected void removeUserSessions(RealmModel realm, UserModel user, boolean offline) 
 - 
removeAllExpiredpublic void removeAllExpired() Description copied from interface:UserSessionProviderRemove expired user sessions and client sessions in all the realms- Specified by:
- removeAllExpiredin interface- UserSessionProvider
 
 - 
removeExpiredpublic void removeExpired(RealmModel realm) 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 interface- UserSessionProvider
- Parameters:
- realm-- RealmModelRealm where all the expired user sessions to be removed from.
 
 - 
removeUserSessionspublic void removeUserSessions(RealmModel realm) - Specified by:
- removeUserSessionsin interface- UserSessionProvider
 
 - 
onRemoveUserSessionsEventprotected void onRemoveUserSessionsEvent(String realmId) 
 - 
removeLocalUserSessionspublic void removeLocalUserSessions(String realmId, boolean offline) 
 - 
onRealmRemovedpublic void onRealmRemoved(RealmModel realm) - Specified by:
- onRealmRemovedin interface- UserSessionProvider
 
 - 
onRealmRemovedEventprotected void onRealmRemovedEvent(String realmId) 
 - 
onClientRemovedpublic void onClientRemoved(RealmModel realm, ClientModel client) - Specified by:
- onClientRemovedin interface- UserSessionProvider
 
 - 
onUserRemovedprotected void onUserRemoved(RealmModel realm, UserModel user) 
 - 
closepublic void close() - Specified by:
- closein interface- Provider
- Specified by:
- closein interface- UserSessionProvider
 
 - 
getStartupTimepublic int getStartupTime(RealmModel realm) - Specified by:
- getStartupTimein interface- UserSessionProvider
 
 - 
removeUserSessionprotected void removeUserSession(UserSessionEntity sessionEntity, boolean offline) 
 - 
createOfflineUserSessionpublic UserSessionModel createOfflineUserSession(UserSessionModel userSession) Description copied from interface:UserSessionProviderNewly created userSession won't contain attached AuthenticatedClientSessions- Specified by:
- createOfflineUserSessionin interface- UserSessionProvider
 
 - 
getOfflineUserSessionpublic UserSessionAdapter getOfflineUserSession(RealmModel realm, String userSessionId) - Specified by:
- getOfflineUserSessionin interface- UserSessionProvider
 
 - 
getOfflineUserSessionByBrokerSessionIdpublic UserSessionModel getOfflineUserSessionByBrokerSessionId(RealmModel realm, String brokerSessionId) - Specified by:
- getOfflineUserSessionByBrokerSessionIdin interface- UserSessionProvider
 
 - 
getOfflineUserSessionByBrokerUserIdStreampublic 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 interface- UserSessionProvider
- 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.
 
 - 
removeOfflineUserSessionpublic void removeOfflineUserSession(RealmModel realm, UserSessionModel userSession) Description copied from interface:UserSessionProviderRemoves the attached clientSessions as well- Specified by:
- removeOfflineUserSessionin interface- UserSessionProvider
 
 - 
createOfflineClientSessionpublic AuthenticatedClientSessionModel createOfflineClientSession(AuthenticatedClientSessionModel clientSession, UserSessionModel offlineUserSession) Description copied from interface:UserSessionProviderWill automatically attach newly created offline client session to the offlineUserSession- Specified by:
- createOfflineClientSessionin interface- UserSessionProvider
 
 - 
getOfflineUserSessionsStreampublic Stream<UserSessionModel> getOfflineUserSessionsStream(RealmModel realm, UserModel user) Description copied from interface:UserSessionProviderObtains the offline user sessions associated with the specified user.- Specified by:
- getOfflineUserSessionsStreamin interface- UserSessionProvider
- Parameters:
- realm- a reference to the realm.
- user- the user whose offline sessions are being searched.
- Returns:
- a non-null Streamof offline user sessions.
 
 - 
getOfflineSessionsCountpublic long getOfflineSessionsCount(RealmModel realm, ClientModel client) - Specified by:
- getOfflineSessionsCountin interface- UserSessionProvider
 
 - 
getOfflineUserSessionsStreampublic 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 interface- UserSessionProvider
- Parameters:
- realm- a reference tot he realm.
- client- the client whose user sessions are being searched.
- first- first result to return. Ignored if negative or- null.
- max- maximum number of results to return. Ignored if negative or- null.
- Returns:
- a non-null Streamof offline user sessions.
 
 - 
importUserSessionspublic void importUserSessions(Collection<UserSessionModel> persistentUserSessions, boolean offline) Description copied from interface:UserSessionProviderTriggered by persister during pre-load. It imports authenticatedClientSessions too- Specified by:
- importUserSessionsin interface- UserSessionProvider
 
 - 
importUserSessionprotected UserSessionAdapter importUserSession(UserSessionModel userSession, boolean offline) 
 
- 
 
-