Due to this PR https://github.com/keycloak/keycloak/commit/056ba75a72b1595ca9fa471f5693201fd5b2c7ae by default (Keycloak latest release 6.0.1) the Infinispan Connection SPI
which uses InfinispanChangelogBasedTransaction.java
has a very particular use of a CacheDecorator.java
which will skipCacheStore
. This means that no matter if you configure a store with persistence the store will be ignored.
In order to achieve what you want, besides configuring the store, you would have to customize most of the SPIs here https://github.com/keycloak/keycloak/tree/master/model/infinispan/src/main/resources/META-INF/services in order to make sure that Keycloak will be using the cache store.
This will also not be easy since there are a lot of perks involved into the process, for example, since Keycloak is using the Marshaller of Jboss, if you customize this SPIs you would have to bring most of the org.keycloak.models.sessions.infinispan
package and register your module to make sure that Wildfly will be able to see the entities to marshall.
Another thing is that you should, with Redis, configure most of the caches pointing to one common database, except the authenticationSessions
which cannot be in the same database as sessions
, otherwise, there will be conflicts like the RootAuthenticationSesssionEntity
being found but expected to be SessionEntityWrapper
.
To resume, the process will be painfull, but if you want to dare and do it, this is how I achieved it:
- Introduced a custom InfinispanConnectionProviderFactory in order to have full capability to use infinispan configuration and then configure my containers like:
private Configuration getRedisConfiguration(int database) {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.persistence()
.passivation(false)
.addStore(RedisCacheStoreConfigurationBuilder.class)
.ignoreModifications(false)
.fetchPersistentState(false)
.purgeOnStartup(false)
.preload(false)
.shared(true)
.addProperty("host", System.getenv("REDIS_HOST"))
.addProperty("port", System.getenv("REDIS_PORT"))
.addProperty("database", String.valueOf(database));
return cb.build();
}
The RedisCacheStoreConfigurationBuilder
that you see there is basically a stripped-down version of the original store but I don't need Sentinel or Server mode I just want to connect to a host, port, and database.
Then I basically copied the org.keycloak.models.sessions.infinispan
removing everything related to remove cache, and instead of using normally the cache without the decorator to skipCacheStore.
Let me know if I can help with something, I will most prepare a post that instructs more detailed how to do this, involving also a repository that will contain the codes that I am talking about. Please let me know more if someone is still trying this.