Class InfinispanUserSessionProvider
java.lang.Object
org.keycloak.models.sessions.infinispan.InfinispanUserSessionProvider
- All Implemented Interfaces:
SessionRefreshStore
,UserSessionProvider
,Provider
public class InfinispanUserSessionProvider
extends Object
implements UserSessionProvider, SessionRefreshStore
- Author:
- Stian Thorgersen
-
Field Summary
Modifier and TypeFieldDescriptionprotected final org.infinispan.Cache<UUID,
SessionEntityWrapper<AuthenticatedClientSessionEntity>> protected final InfinispanChangelogBasedTransaction<UUID,
AuthenticatedClientSessionEntity> protected final SessionEventsSenderTransaction
protected final InfinispanKeyGenerator
protected final CrossDCLastSessionRefreshStore
protected final org.infinispan.Cache<UUID,
SessionEntityWrapper<AuthenticatedClientSessionEntity>> protected final SessionFunction
protected final InfinispanChangelogBasedTransaction<UUID,
AuthenticatedClientSessionEntity> protected final CrossDCLastSessionRefreshStore
protected final org.infinispan.Cache<String,
SessionEntityWrapper<UserSessionEntity>> protected final SessionFunction
protected final InfinispanChangelogBasedTransaction<String,
UserSessionEntity> protected final PersisterLastSessionRefreshStore
protected final KeycloakSession
protected final org.infinispan.Cache<String,
SessionEntityWrapper<UserSessionEntity>> protected final InfinispanChangelogBasedTransaction<String,
UserSessionEntity> -
Constructor Summary
ConstructorDescriptionInfinispanUserSessionProvider
(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, SessionFunction<UserSessionEntity> offlineSessionCacheEntryLifespanAdjuster, SessionFunction<AuthenticatedClientSessionEntity> offlineClientSessionCacheEntryLifespanAdjuster, SerializeExecutionsByKey<String> serializerSession, SerializeExecutionsByKey<String> serializerOfflineSession, SerializeExecutionsByKey<UUID> serializerClientSession, SerializeExecutionsByKey<UUID> serializerOfflineClientSession) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
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()long
getActiveUserSessions
(RealmModel realm, ClientModel client) protected org.infinispan.Cache<String,
SessionEntityWrapper<UserSessionEntity>> getCache
(boolean offline) getClientSession
(UserSessionModel userSession, ClientModel client, String clientSessionId, boolean offline) protected org.infinispan.Cache<UUID,
SessionEntityWrapper<AuthenticatedClientSessionEntity>> getClientSessionCache
(boolean offline) getClientSessionTransaction
(boolean offline) Returns currently used Keycloak session.long
getOfflineSessionsCount
(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 thefirstResult
and containing at mostmaxResults
.getOfflineUserSessionsStream
(RealmModel realm, UserModel user) Obtains the offline user sessions associated with the specified user.int
getStartupTime
(RealmModel realm) getTransaction
(boolean offline) getUserSession
(RealmModel realm, String id) protected UserSessionAdapter
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 long
getUserSessionsCount
(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 thefirstResult
and 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
importUserSession
(UserSessionModel userSession, boolean offline) void
importUserSessions
(Collection<UserSessionModel> persistentUserSessions, boolean offline) Triggered by persister during pre-load.void
void
onClientRemoved
(RealmModel realm, ClientModel client) void
onRealmRemoved
(RealmModel realm) protected void
onRealmRemovedEvent
(String realmId) protected void
onRemoveUserSessionsEvent
(String realmId) protected void
onUserRemoved
(RealmModel realm, UserModel user) void
Remove expired user sessions and client sessions in all the realmsvoid
removeExpired
(RealmModel realm) Removes expired user sessions owned by this realm from this provider.void
removeLocalUserSessions
(String realmId, boolean offline) void
removeOfflineUserSession
(RealmModel realm, UserSessionModel userSession) Removes the attached clientSessions as wellvoid
removeUserSession
(RealmModel realm, UserSessionModel session) This will remove attached ClientLoginSessionModels tooprotected void
removeUserSession
(UserSessionEntity sessionEntity, boolean offline) void
removeUserSessions
(RealmModel realm) void
removeUserSessions
(RealmModel realm, UserModel user) protected void
removeUserSessions
(RealmModel realm, UserModel user, boolean offline) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.keycloak.models.UserSessionProvider
createUserSession, getClientSession, getUserSessionIfClientExists
-
Field Details
-
session
-
sessionCache
-
offlineSessionCache
protected final org.infinispan.Cache<String,SessionEntityWrapper<UserSessionEntity>> offlineSessionCache -
clientSessionCache
protected final org.infinispan.Cache<UUID,SessionEntityWrapper<AuthenticatedClientSessionEntity>> clientSessionCache -
offlineClientSessionCache
protected final org.infinispan.Cache<UUID,SessionEntityWrapper<AuthenticatedClientSessionEntity>> offlineClientSessionCache -
sessionTx
-
offlineSessionTx
-
clientSessionTx
protected final InfinispanChangelogBasedTransaction<UUID,AuthenticatedClientSessionEntity> clientSessionTx -
offlineClientSessionTx
protected final InfinispanChangelogBasedTransaction<UUID,AuthenticatedClientSessionEntity> offlineClientSessionTx -
clusterEventsSenderTx
-
lastSessionRefreshStore
-
offlineLastSessionRefreshStore
-
persisterLastSessionRefreshStore
-
keyGenerator
-
offlineSessionCacheEntryLifespanAdjuster
-
offlineClientSessionCacheEntryLifespanAdjuster
-
-
Constructor Details
-
InfinispanUserSessionProvider
public 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, SessionFunction<UserSessionEntity> offlineSessionCacheEntryLifespanAdjuster, SessionFunction<AuthenticatedClientSessionEntity> offlineClientSessionCacheEntryLifespanAdjuster, SerializeExecutionsByKey<String> serializerSession, SerializeExecutionsByKey<String> serializerOfflineSession, SerializeExecutionsByKey<UUID> serializerClientSession, SerializeExecutionsByKey<UUID> serializerOfflineClientSession)
-
-
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<UUID,SessionEntityWrapper<AuthenticatedClientSessionEntity>> getClientSessionCache(boolean offline) -
getClientSessionTransaction
protected InfinispanChangelogBasedTransaction<UUID,AuthenticatedClientSessionEntity> getClientSessionTransaction(boolean offline) -
getLastSessionRefreshStore
- Specified by:
getLastSessionRefreshStore
in interfaceSessionRefreshStore
-
getOfflineLastSessionRefreshStore
- Specified by:
getOfflineLastSessionRefreshStore
in interfaceSessionRefreshStore
-
getPersisterLastSessionRefreshStore
- Specified by:
getPersisterLastSessionRefreshStore
in interfaceSessionRefreshStore
-
getKeycloakSession
Description copied from interface:UserSessionProvider
Returns currently used Keycloak session.- Specified by:
getKeycloakSession
in interfaceUserSessionProvider
- Returns:
KeycloakSession
-
createClientSession
public AuthenticatedClientSessionModel createClientSession(RealmModel realm, ClientModel client, UserSessionModel userSession) - Specified by:
createClientSession
in 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:UserSessionProvider
Creates a new user session with the given parameters.- Specified by:
createUserSession
in interfaceUserSessionProvider
- Parameters:
id
- identifier. Is generated ifnull
realm
- the realmuser
- user associated with the created user session- Returns:
- Model of the created user session
-
getUserSession
- Specified by:
getUserSession
in interfaceUserSessionProvider
-
migrate
- Specified by:
migrate
in interfaceUserSessionProvider
-
getUserSession
-
getUserSessionsStream
protected Stream<UserSessionModel> getUserSessionsStream(RealmModel realm, UserSessionPredicate predicate, boolean offline) -
getClientSession
public AuthenticatedClientSessionAdapter getClientSession(UserSessionModel userSession, ClientModel client, String clientSessionId, boolean offline) - Specified by:
getClientSession
in interfaceUserSessionProvider
-
getUserSessionsStream
Description copied from interface:UserSessionProvider
Obtains the online user sessions associated with the specified user.- Specified by:
getUserSessionsStream
in interfaceUserSessionProvider
- Parameters:
realm
- a reference to the realm.user
- the user whose sessions are being searched.- Returns:
- a non-null
Stream
of online user sessions.
-
getUserSessionByBrokerUserIdStream
public Stream<UserSessionModel> getUserSessionByBrokerUserIdStream(RealmModel realm, String brokerUserId) Description copied from interface:UserSessionProvider
Obtains the online user sessions associated with the user that matches the specifiedbrokerUserId
.- Specified by:
getUserSessionByBrokerUserIdStream
in interfaceUserSessionProvider
- 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
- Specified by:
getUserSessionByBrokerSessionId
in interfaceUserSessionProvider
-
getUserSessionsStream
Description copied from interface:UserSessionProvider
Obtains the online user sessions associated with the specified client.- Specified by:
getUserSessionsStream
in interfaceUserSessionProvider
- 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
public Stream<UserSessionModel> getUserSessionsStream(RealmModel realm, ClientModel client, Integer firstResult, Integer maxResults) Description copied from interface:UserSessionProvider
Obtains the online user sessions associated with the specified client, starting from thefirstResult
and containing at mostmaxResults
.- Specified by:
getUserSessionsStream
in 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
Stream
of 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:UserSessionProvider
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)- Specified by:
getUserSessionWithPredicate
in interfaceUserSessionProvider
-
getActiveUserSessions
- Specified by:
getActiveUserSessions
in interfaceUserSessionProvider
-
getActiveClientSessionStats
Description copied from interface:UserSessionProvider
Returns a summary of client sessions key is client.getId()- Specified by:
getActiveClientSessionStats
in interfaceUserSessionProvider
- Returns:
-
getUserSessionsCount
-
removeUserSession
Description copied from interface:UserSessionProvider
This will remove attached ClientLoginSessionModels too- Specified by:
removeUserSession
in interfaceUserSessionProvider
-
removeUserSessions
- Specified by:
removeUserSessions
in interfaceUserSessionProvider
-
removeUserSessions
-
removeAllExpired
public void removeAllExpired()Description copied from interface:UserSessionProvider
Remove expired user sessions and client sessions in all the realms- Specified by:
removeAllExpired
in interfaceUserSessionProvider
-
removeExpired
Description copied from interface:UserSessionProvider
Removes expired user sessions owned by this realm from this provider. If this `UserSessionProvider` uses `UserSessionPersister`, the removal of the expireduser sessions
is also propagated to relevant `UserSessionPersister`.- Specified by:
removeExpired
in interfaceUserSessionProvider
- Parameters:
realm
-RealmModel
Realm where all the expired user sessions to be removed from.
-
removeUserSessions
- Specified by:
removeUserSessions
in interfaceUserSessionProvider
-
onRemoveUserSessionsEvent
-
removeLocalUserSessions
-
onRealmRemoved
- Specified by:
onRealmRemoved
in interfaceUserSessionProvider
-
onRealmRemovedEvent
-
onClientRemoved
- Specified by:
onClientRemoved
in interfaceUserSessionProvider
-
onUserRemoved
-
close
public void close()- Specified by:
close
in interfaceProvider
- Specified by:
close
in interfaceUserSessionProvider
-
getStartupTime
- Specified by:
getStartupTime
in interfaceUserSessionProvider
-
removeUserSession
-
createOfflineUserSession
Description copied from interface:UserSessionProvider
Newly created userSession won't contain attached AuthenticatedClientSessions- Specified by:
createOfflineUserSession
in interfaceUserSessionProvider
-
getOfflineUserSession
- Specified by:
getOfflineUserSession
in interfaceUserSessionProvider
-
getOfflineUserSessionByBrokerUserIdStream
public Stream<UserSessionModel> getOfflineUserSessionByBrokerUserIdStream(RealmModel realm, String brokerUserId) Description copied from interface:UserSessionProvider
Obtains the offline user sessions associated with the user that matches the specifiedbrokerUserId
.- Specified by:
getOfflineUserSessionByBrokerUserIdStream
in interfaceUserSessionProvider
- 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.
-
removeOfflineUserSession
Description copied from interface:UserSessionProvider
Removes the attached clientSessions as well- Specified by:
removeOfflineUserSession
in interfaceUserSessionProvider
-
createOfflineClientSession
public AuthenticatedClientSessionModel createOfflineClientSession(AuthenticatedClientSessionModel clientSession, UserSessionModel offlineUserSession) Description copied from interface:UserSessionProvider
Will automatically attach newly created offline client session to the offlineUserSession- Specified by:
createOfflineClientSession
in interfaceUserSessionProvider
-
getOfflineUserSessionsStream
Description copied from interface:UserSessionProvider
Obtains the offline user sessions associated with the specified user.- Specified by:
getOfflineUserSessionsStream
in interfaceUserSessionProvider
- 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.
-
getOfflineSessionsCount
- Specified by:
getOfflineSessionsCount
in interfaceUserSessionProvider
-
getOfflineUserSessionsStream
public Stream<UserSessionModel> getOfflineUserSessionsStream(RealmModel realm, ClientModel client, Integer first, Integer max) Description copied from interface:UserSessionProvider
Obtains the offline user sessions associated with the specified client, starting from thefirstResult
and containing at mostmaxResults
.- Specified by:
getOfflineUserSessionsStream
in 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
Stream
of offline user sessions.
-
importUserSessions
public void importUserSessions(Collection<UserSessionModel> persistentUserSessions, boolean offline) Description copied from interface:UserSessionProvider
Triggered by persister during pre-load. It imports authenticatedClientSessions too.- Specified by:
importUserSessions
in interfaceUserSessionProvider
-
importUserSession
-