Class SessionTimeouts
java.lang.Object
org.keycloak.models.sessions.infinispan.util.SessionTimeouts
- Author:
- Marek Posolda
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThis indicates that entry is already expired and should be removed from the cachestatic final long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic longcalculateEffectiveSessionLifespan(long maxIdle, long lifespan) Calculates the effective lifespan value to use when storing user and client session entries in the Infinispan cache.static longgetAuthSessionLifespanMS(RealmModel realm, ClientModel client, RootAuthenticationSessionEntity entity) static longgetAuthSessionMaxIdleMS(RealmModel realm, ClientModel client, RootAuthenticationSessionEntity entity) static longgetClientSessionLifespanMs(RealmModel realm, ClientModel client, boolean offline, boolean isUserSessionRememberMe, int started, int userSessionStarted) static longgetClientSessionLifespanMs(RealmModel realm, ClientModel client, AuthenticatedClientSessionEntity clientSessionEntity) Get the maximum lifespan, which this clientSession can remain in the infinispan cache.static longgetClientSessionMaxIdleMs(RealmModel realm, ClientModel client, boolean offline, boolean isUserSessionRememberMe, int timestamp) static longgetClientSessionMaxIdleMs(RealmModel realm, ClientModel client, AuthenticatedClientSessionEntity clientSessionEntity) Get the maxIdle, which this clientSession will use.static longgetLoginFailuresLifespanMs(boolean isPermanentLockout, int maxTemporaryLockouts, long maxDeltaTimeMillis, LoginFailureEntity loginFailureEntity) static longgetLoginFailuresLifespanMs(RealmModel realm, ClientModel client, LoginFailureEntity loginFailureEntity) Not using lifespan for detached login failure (backwards compatibility with the background cleaner threads, which were used for cleanup of detached login failures)static longgetLoginFailuresMaxIdleMs(RealmModel realm, ClientModel client, LoginFailureEntity loginFailureEntity) Not using maxIdle for detached login failure (backwards compatibility with the background cleaner threads, which were used for cleanup of detached login failures)static longgetOfflineClientSessionLifespanMs(RealmModel realm, ClientModel client, AuthenticatedClientSessionEntity authenticatedClientSessionEntity) Get the maximum lifespan, which this offline clientSession can remain in the infinispan cache.static longgetOfflineClientSessionMaxIdleMs(RealmModel realm, ClientModel client, AuthenticatedClientSessionEntity authenticatedClientSessionEntity) Get the maxIdle, which this offline clientSession will use.static longgetOfflineSessionLifespanMs(RealmModel realm, ClientModel client, UserSessionEntity userSessionEntity) Get the maximum lifespan, which this offline userSession can remain in the infinispan cache.static longgetOfflineSessionMaxIdleMs(RealmModel realm, ClientModel client, UserSessionEntity userSessionEntity) Get the maximum idle time for this offline userSession.static longgetUserSessionLifespanMs(RealmModel realm, boolean offline, boolean rememberMe, int started) static longgetUserSessionLifespanMs(RealmModel realm, ClientModel client, UserSessionEntity userSessionEntity) Get the maximum lifespan, which this userSession can remain in the infinispan cache.static longgetUserSessionMaxIdleMs(RealmModel realm, boolean offline, boolean rememberMe, int lastSessionRefresh) static longgetUserSessionMaxIdleMs(RealmModel realm, ClientModel client, UserSessionEntity userSessionEntity) Get the maximum idle time for this userSession.
-
Field Details
-
ENTRY_EXPIRED_FLAG
public static final long ENTRY_EXPIRED_FLAGThis indicates that entry is already expired and should be removed from the cache- See Also:
-
IMMORTAL_FLAG
public static final long IMMORTAL_FLAG- See Also:
-
-
Constructor Details
-
SessionTimeouts
public SessionTimeouts()
-
-
Method Details
-
getUserSessionLifespanMs
public static long getUserSessionLifespanMs(RealmModel realm, ClientModel client, UserSessionEntity userSessionEntity) Get the maximum lifespan, which this userSession can remain in the infinispan cache. Returned value will be used as "lifespan" when calling put/replace operation in the infinispan cache for this entity- Parameters:
realm-client-userSessionEntity-- Returns:
-
getUserSessionLifespanMs
public static long getUserSessionLifespanMs(RealmModel realm, boolean offline, boolean rememberMe, int started) -
getUserSessionMaxIdleMs
public static long getUserSessionMaxIdleMs(RealmModel realm, ClientModel client, UserSessionEntity userSessionEntity) Get the maximum idle time for this userSession. Returned value will be used when as "maxIdleTime" when calling put/replace operation in the infinispan cache for this entity- Parameters:
realm-client-userSessionEntity-- Returns:
-
getUserSessionMaxIdleMs
public static long getUserSessionMaxIdleMs(RealmModel realm, boolean offline, boolean rememberMe, int lastSessionRefresh) -
getClientSessionLifespanMs
public static long getClientSessionLifespanMs(RealmModel realm, ClientModel client, AuthenticatedClientSessionEntity clientSessionEntity) Get the maximum lifespan, which this clientSession can remain in the infinispan cache. Returned value will be used as "lifespan" when calling put/replace operation in the infinispan cache for this entity- Parameters:
realm-client-clientSessionEntity-- Returns:
-
getClientSessionLifespanMs
public static long getClientSessionLifespanMs(RealmModel realm, ClientModel client, boolean offline, boolean isUserSessionRememberMe, int started, int userSessionStarted) -
getClientSessionMaxIdleMs
public static long getClientSessionMaxIdleMs(RealmModel realm, ClientModel client, AuthenticatedClientSessionEntity clientSessionEntity) Get the maxIdle, which this clientSession will use. Returned value will be used as "maxIdle" when calling put/replace operation in the infinispan cache for this entity- Parameters:
realm-client-clientSessionEntity-- Returns:
-
getClientSessionMaxIdleMs
public static long getClientSessionMaxIdleMs(RealmModel realm, ClientModel client, boolean offline, boolean isUserSessionRememberMe, int timestamp) -
getOfflineSessionLifespanMs
public static long getOfflineSessionLifespanMs(RealmModel realm, ClientModel client, UserSessionEntity userSessionEntity) Get the maximum lifespan, which this offline userSession can remain in the infinispan cache. Returned value will be used as "lifespan" when calling put/replace operation in the infinispan cache for this entity- Parameters:
realm-client-userSessionEntity-- Returns:
-
getOfflineSessionMaxIdleMs
public static long getOfflineSessionMaxIdleMs(RealmModel realm, ClientModel client, UserSessionEntity userSessionEntity) Get the maximum idle time for this offline userSession. Returned value will be used when as "maxIdleTime" when calling put/replace operation in the infinispan cache for this entity- Parameters:
realm-client-userSessionEntity-- Returns:
-
getOfflineClientSessionLifespanMs
public static long getOfflineClientSessionLifespanMs(RealmModel realm, ClientModel client, AuthenticatedClientSessionEntity authenticatedClientSessionEntity) Get the maximum lifespan, which this offline clientSession can remain in the infinispan cache. Returned value will be used as "lifespan" when calling put/replace operation in the infinispan cache for this entity- Parameters:
realm-client-authenticatedClientSessionEntity-- Returns:
-
getOfflineClientSessionMaxIdleMs
public static long getOfflineClientSessionMaxIdleMs(RealmModel realm, ClientModel client, AuthenticatedClientSessionEntity authenticatedClientSessionEntity) Get the maxIdle, which this offline clientSession will use. Returned value will be used as "maxIdle" when calling put/replace operation in the infinispan cache for this entity- Parameters:
realm-client-authenticatedClientSessionEntity-- Returns:
-
getLoginFailuresLifespanMs
public static long getLoginFailuresLifespanMs(RealmModel realm, ClientModel client, LoginFailureEntity loginFailureEntity) Not using lifespan for detached login failure (backwards compatibility with the background cleaner threads, which were used for cleanup of detached login failures)- Parameters:
realm-client-loginFailureEntity-- Returns:
-
getLoginFailuresLifespanMs
public static long getLoginFailuresLifespanMs(boolean isPermanentLockout, int maxTemporaryLockouts, long maxDeltaTimeMillis, LoginFailureEntity loginFailureEntity) -
getLoginFailuresMaxIdleMs
public static long getLoginFailuresMaxIdleMs(RealmModel realm, ClientModel client, LoginFailureEntity loginFailureEntity) Not using maxIdle for detached login failure (backwards compatibility with the background cleaner threads, which were used for cleanup of detached login failures)- Parameters:
realm-client-loginFailureEntity-- Returns:
-
getAuthSessionLifespanMS
public static long getAuthSessionLifespanMS(RealmModel realm, ClientModel client, RootAuthenticationSessionEntity entity) -
getAuthSessionMaxIdleMS
public static long getAuthSessionMaxIdleMS(RealmModel realm, ClientModel client, RootAuthenticationSessionEntity entity) -
calculateEffectiveSessionLifespan
public static long calculateEffectiveSessionLifespan(long maxIdle, long lifespan) Calculates the effective lifespan value to use when storing user and client session entries in the Infinispan cache.This method optimizes Infinispan cache configuration by incorporating the max-idle timeout into the lifespan value. Since Infinispan's max-idle implementation is expensive (requires tracking last access time and additional overhead), this optimization avoids using max-idle directly and instead sets the lifespan to the minimum of max-idle and lifespan values. This ensures session entries expire at the correct time without the performance cost of max-idle tracking.
- Parameters:
maxIdle- the maximum idle time in milliseconds, orIMMORTAL_FLAGfor no idle timeoutlifespan- the maximum lifespan in milliseconds, orIMMORTAL_FLAGfor no lifespan timeout- Returns:
- the effective lifespan to use for the session cache entry: returns
lifespanifmaxIdleisIMMORTAL_FLAG,maxIdleiflifespanisIMMORTAL_FLAG, otherwise returnsmin(maxIdle, lifespan)
-