Search in sources :

Example 1 with RemoteCacheInvoker

use of org.keycloak.models.sessions.infinispan.remotestore.RemoteCacheInvoker in project keycloak by keycloak.

the class InfinispanUserLoginFailureProviderFactory method postInit.

@Override
public void postInit(final KeycloakSessionFactory factory) {
    this.remoteCacheInvoker = new RemoteCacheInvoker();
    factory.register(event -> {
        if (event instanceof PostMigrationEvent) {
            KeycloakModelUtils.runJobInTransaction(factory, (KeycloakSession session) -> {
                checkRemoteCaches(session);
                registerClusterListeners(session);
                loadLoginFailuresFromRemoteCaches(session);
            });
        } else if (event instanceof UserModel.UserRemovedEvent) {
            UserModel.UserRemovedEvent userRemovedEvent = (UserModel.UserRemovedEvent) event;
            UserLoginFailureProvider provider = userRemovedEvent.getKeycloakSession().getProvider(UserLoginFailureProvider.class, getId());
            provider.removeUserLoginFailure(userRemovedEvent.getRealm(), userRemovedEvent.getUser().getId());
        }
    });
}
Also used : UserModel(org.keycloak.models.UserModel) RemoteCacheInvoker(org.keycloak.models.sessions.infinispan.remotestore.RemoteCacheInvoker) KeycloakSession(org.keycloak.models.KeycloakSession) UserLoginFailureProvider(org.keycloak.models.UserLoginFailureProvider) PostMigrationEvent(org.keycloak.models.utils.PostMigrationEvent)

Example 2 with RemoteCacheInvoker

use of org.keycloak.models.sessions.infinispan.remotestore.RemoteCacheInvoker in project keycloak by keycloak.

the class InfinispanUserSessionProviderFactory method checkRemoteCaches.

protected void checkRemoteCaches(KeycloakSession session) {
    this.remoteCacheInvoker = new RemoteCacheInvoker();
    InfinispanConnectionProvider ispn = session.getProvider(InfinispanConnectionProvider.class);
    Cache<String, SessionEntityWrapper<UserSessionEntity>> sessionsCache = ispn.getCache(InfinispanConnectionProvider.USER_SESSION_CACHE_NAME);
    RemoteCache sessionsRemoteCache = checkRemoteCache(session, sessionsCache, (RealmModel realm) -> {
        // We won't write to the remoteCache during token refresh, so the timeout needs to be longer.
        return Time.toMillis(realm.getSsoSessionMaxLifespan());
    }, SessionTimeouts::getUserSessionLifespanMs, SessionTimeouts::getUserSessionMaxIdleMs);
    if (sessionsRemoteCache != null) {
        lastSessionRefreshStore = new CrossDCLastSessionRefreshStoreFactory().createAndInit(session, sessionsCache, false);
    }
    Cache<UUID, SessionEntityWrapper<AuthenticatedClientSessionEntity>> clientSessionsCache = ispn.getCache(InfinispanConnectionProvider.CLIENT_SESSION_CACHE_NAME);
    checkRemoteCache(session, clientSessionsCache, (RealmModel realm) -> {
        // We won't write to the remoteCache during token refresh, so the timeout needs to be longer.
        return Time.toMillis(realm.getSsoSessionMaxLifespan());
    }, SessionTimeouts::getClientSessionLifespanMs, SessionTimeouts::getClientSessionMaxIdleMs);
    Cache<String, SessionEntityWrapper<UserSessionEntity>> offlineSessionsCache = ispn.getCache(InfinispanConnectionProvider.OFFLINE_USER_SESSION_CACHE_NAME);
    RemoteCache offlineSessionsRemoteCache = checkRemoteCache(session, offlineSessionsCache, (RealmModel realm) -> {
        return Time.toMillis(realm.getOfflineSessionIdleTimeout());
    }, SessionTimeouts::getOfflineSessionLifespanMs, SessionTimeouts::getOfflineSessionMaxIdleMs);
    if (offlineSessionsRemoteCache != null) {
        offlineLastSessionRefreshStore = new CrossDCLastSessionRefreshStoreFactory().createAndInit(session, offlineSessionsCache, true);
    }
    Cache<UUID, SessionEntityWrapper<AuthenticatedClientSessionEntity>> offlineClientSessionsCache = ispn.getCache(InfinispanConnectionProvider.OFFLINE_CLIENT_SESSION_CACHE_NAME);
    checkRemoteCache(session, offlineClientSessionsCache, (RealmModel realm) -> {
        return Time.toMillis(realm.getOfflineSessionIdleTimeout());
    }, SessionTimeouts::getOfflineClientSessionLifespanMs, SessionTimeouts::getOfflineClientSessionMaxIdleMs);
}
Also used : RealmModel(org.keycloak.models.RealmModel) CrossDCLastSessionRefreshStoreFactory(org.keycloak.models.sessions.infinispan.changes.sessions.CrossDCLastSessionRefreshStoreFactory) RemoteCacheInvoker(org.keycloak.models.sessions.infinispan.remotestore.RemoteCacheInvoker) RemoteCache(org.infinispan.client.hotrod.RemoteCache) SessionTimeouts(org.keycloak.models.sessions.infinispan.util.SessionTimeouts) UUID(java.util.UUID) InfinispanConnectionProvider(org.keycloak.connections.infinispan.InfinispanConnectionProvider) SessionEntityWrapper(org.keycloak.models.sessions.infinispan.changes.SessionEntityWrapper)

Aggregations

RemoteCacheInvoker (org.keycloak.models.sessions.infinispan.remotestore.RemoteCacheInvoker)2 UUID (java.util.UUID)1 RemoteCache (org.infinispan.client.hotrod.RemoteCache)1 InfinispanConnectionProvider (org.keycloak.connections.infinispan.InfinispanConnectionProvider)1 KeycloakSession (org.keycloak.models.KeycloakSession)1 RealmModel (org.keycloak.models.RealmModel)1 UserLoginFailureProvider (org.keycloak.models.UserLoginFailureProvider)1 UserModel (org.keycloak.models.UserModel)1 SessionEntityWrapper (org.keycloak.models.sessions.infinispan.changes.SessionEntityWrapper)1 CrossDCLastSessionRefreshStoreFactory (org.keycloak.models.sessions.infinispan.changes.sessions.CrossDCLastSessionRefreshStoreFactory)1 SessionTimeouts (org.keycloak.models.sessions.infinispan.util.SessionTimeouts)1 PostMigrationEvent (org.keycloak.models.utils.PostMigrationEvent)1