Search in sources :

Example 6 with UserSessionProvider

use of org.keycloak.models.UserSessionProvider in project keycloak by keycloak.

the class OfflineSessionPersistenceTest method testOfflineSessionLoadingAfterCacheRemoval.

@Test
@RequireProvider(UserSessionPersisterProvider.class)
@RequireProvider(value = UserSessionProvider.class, only = InfinispanUserSessionProviderFactory.PROVIDER_ID)
public void testOfflineSessionLoadingAfterCacheRemoval() {
    List<String> offlineSessionIds = createOfflineSessions(realmId, userIds);
    assertOfflineSessionsExist(realmId, offlineSessionIds);
    // Simulate server restart
    reinitializeKeycloakSessionFactory();
    assertOfflineSessionsExist(realmId, offlineSessionIds);
    // remove sessions from the cache
    withRealm(realmId, (session, realm) -> {
        // Delete local user cache (persisted sessions are still kept)
        UserSessionProvider provider = session.getProvider(UserSessionProvider.class);
        // Remove in-memory representation of the offline sessions
        ((InfinispanUserSessionProvider) provider).removeLocalUserSessions(realm.getId(), true);
        return null;
    });
    // assert sessions are lazily loaded from DB
    assertOfflineSessionsExist(realmId, offlineSessionIds);
}
Also used : UserSessionProvider(org.keycloak.models.UserSessionProvider) InfinispanUserSessionProvider(org.keycloak.models.sessions.infinispan.InfinispanUserSessionProvider) InfinispanUserSessionProvider(org.keycloak.models.sessions.infinispan.InfinispanUserSessionProvider) KeycloakModelTest(org.keycloak.testsuite.model.KeycloakModelTest) Test(org.junit.Test) RequireProvider(org.keycloak.testsuite.model.RequireProvider)

Aggregations

UserSessionProvider (org.keycloak.models.UserSessionProvider)6 ClientModel (org.keycloak.models.ClientModel)2 KeycloakSession (org.keycloak.models.KeycloakSession)2 UserModel (org.keycloak.models.UserModel)2 UserSessionModel (org.keycloak.models.UserSessionModel)2 AuthenticationSessionProvider (org.keycloak.sessions.AuthenticationSessionProvider)2 Test (org.junit.Test)1 ClusterProvider (org.keycloak.cluster.ClusterProvider)1 EventBuilder (org.keycloak.events.EventBuilder)1 AuthenticatedClientSessionModel (org.keycloak.models.AuthenticatedClientSessionModel)1 ClientSessionContext (org.keycloak.models.ClientSessionContext)1 KeycloakSessionFactory (org.keycloak.models.KeycloakSessionFactory)1 RealmModel (org.keycloak.models.RealmModel)1 UserManager (org.keycloak.models.UserManager)1 InfinispanUserSessionProvider (org.keycloak.models.sessions.infinispan.InfinispanUserSessionProvider)1 ClientRemovedSessionEvent (org.keycloak.models.sessions.infinispan.events.ClientRemovedSessionEvent)1 RealmRemovedSessionEvent (org.keycloak.models.sessions.infinispan.events.RealmRemovedSessionEvent)1 RemoveUserSessionsEvent (org.keycloak.models.sessions.infinispan.events.RemoveUserSessionsEvent)1 TokenManager (org.keycloak.protocol.oidc.TokenManager)1 AccessTokenResponseBuilder (org.keycloak.protocol.oidc.TokenManager.AccessTokenResponseBuilder)1