Search in sources :

Example 1 with InfinispanStickySessionEncoderProviderFactory

use of org.keycloak.models.sessions.infinispan.InfinispanStickySessionEncoderProviderFactory in project keycloak by keycloak.

the class AuthenticationSessionClusterTest method testAuthSessionCookieWithoutRoute.

@Test
public void testAuthSessionCookieWithoutRoute() throws Exception {
    OAuthClient oAuthClient = new OAuthClient();
    oAuthClient.init(driver);
    oAuthClient.baseUrl(UriBuilder.fromUri(backendNode(0).getUriBuilder().build() + "/auth").build("test").toString());
    String testAppLoginNode1URL = oAuthClient.getLoginFormUrl();
    // Disable route on backend server
    getTestingClientFor(backendNode(0)).server().run(session -> {
        InfinispanStickySessionEncoderProviderFactory factory = (InfinispanStickySessionEncoderProviderFactory) session.getKeycloakSessionFactory().getProviderFactory(StickySessionEncoderProvider.class, "infinispan");
        factory.setShouldAttachRoute(false);
    });
    // Test routes
    for (int i = 0; i < 20; i++) {
        driver.navigate().to(testAppLoginNode1URL);
        String authSessionCookie = AuthenticationSessionFailoverClusterTest.getAuthSessionCookieValue(driver);
        Assert.assertEquals(36, authSessionCookie.length());
        // Drop all cookies before continue
        driver.manage().deleteAllCookies();
        // Check that route owner is always node1
        getTestingClientFor(backendNode(0)).server().run(session -> {
            Cache authSessionCache = session.getProvider(InfinispanConnectionProvider.class).getCache(InfinispanConnectionProvider.AUTHENTICATION_SESSIONS_CACHE_NAME);
            String keyOwner = InfinispanUtil.getTopologyInfo(session).getRouteName(authSessionCache, authSessionCookie);
            Assert.assertTrue(keyOwner.startsWith("node1"));
        });
    }
    // Revert route on backend server
    getTestingClientFor(backendNode(0)).server().run(session -> {
        InfinispanStickySessionEncoderProviderFactory factory = (InfinispanStickySessionEncoderProviderFactory) session.getKeycloakSessionFactory().getProviderFactory(StickySessionEncoderProvider.class, "infinispan");
        factory.setShouldAttachRoute(true);
    });
}
Also used : InfinispanStickySessionEncoderProviderFactory(org.keycloak.models.sessions.infinispan.InfinispanStickySessionEncoderProviderFactory) OAuthClient(org.keycloak.testsuite.util.OAuthClient) InfinispanConnectionProvider(org.keycloak.connections.infinispan.InfinispanConnectionProvider) StickySessionEncoderProvider(org.keycloak.sessions.StickySessionEncoderProvider) Cache(org.infinispan.Cache) Test(org.junit.Test)

Aggregations

Cache (org.infinispan.Cache)1 Test (org.junit.Test)1 InfinispanConnectionProvider (org.keycloak.connections.infinispan.InfinispanConnectionProvider)1 InfinispanStickySessionEncoderProviderFactory (org.keycloak.models.sessions.infinispan.InfinispanStickySessionEncoderProviderFactory)1 StickySessionEncoderProvider (org.keycloak.sessions.StickySessionEncoderProvider)1 OAuthClient (org.keycloak.testsuite.util.OAuthClient)1