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);
});
}
Aggregations