KEYCLOAK-800 Ensure that loginFailures infinispan cache is defined

This commit is contained in:
mposolda 2014-10-30 21:15:52 +01:00
parent 99016cdc83
commit 0f25280611
7 changed files with 19 additions and 12 deletions

View file

@ -96,8 +96,8 @@ public class DefaultInfinispanConnectionProviderFactory implements InfinispanCon
} }
Configuration invalidationCacheConfiguration = invalidationConfigBuilder.build(); Configuration invalidationCacheConfiguration = invalidationConfigBuilder.build();
cacheManager.defineConfiguration("realms", invalidationCacheConfiguration); cacheManager.defineConfiguration(InfinispanConnectionProvider.REALM_CACHE_NAME, invalidationCacheConfiguration);
cacheManager.defineConfiguration("users", invalidationCacheConfiguration); cacheManager.defineConfiguration(InfinispanConnectionProvider.USER_CACHE_NAME, invalidationCacheConfiguration);
ConfigurationBuilder sessionConfigBuilder = new ConfigurationBuilder(); ConfigurationBuilder sessionConfigBuilder = new ConfigurationBuilder();
if (clustered) { if (clustered) {
@ -115,7 +115,9 @@ public class DefaultInfinispanConnectionProviderFactory implements InfinispanCon
.numSegments(config.getInt("sessionsSegments", 60)).build(); .numSegments(config.getInt("sessionsSegments", 60)).build();
} }
cacheManager.defineConfiguration("sessions", sessionConfigBuilder.build()); Configuration sessionCacheConfiguration = sessionConfigBuilder.build();
cacheManager.defineConfiguration(InfinispanConnectionProvider.SESSION_CACHE_NAME, sessionCacheConfiguration);
cacheManager.defineConfiguration(InfinispanConnectionProvider.LOGIN_FAILURE_CACHE_NAME, sessionCacheConfiguration);
} }
} }

View file

@ -8,6 +8,11 @@ import org.keycloak.provider.Provider;
*/ */
public interface InfinispanConnectionProvider extends Provider { public interface InfinispanConnectionProvider extends Provider {
static final String REALM_CACHE_NAME = "realms";
static final String USER_CACHE_NAME = "users";
static final String SESSION_CACHE_NAME = "sessions";
static final String LOGIN_FAILURE_CACHE_NAME = "loginFailures";
<K, V> Cache<K, V> getCache(String name); <K, V> Cache<K, V> getCache(String name);
} }

View file

@ -53,7 +53,7 @@
realm keys and password hashes) from being sent between the nodes. realm keys and password hashes) from being sent between the nodes.
</para> </para>
<para> <para>
User sessions supports either distributed caches or fully replicated caches. We recommend using a distributed User sessions and login failures supports either distributed caches or fully replicated caches. We recommend using a distributed
cache. cache.
</para> </para>
<para> <para>
@ -65,6 +65,7 @@
<invalidation-cache name="realms" mode="SYNC"/> <invalidation-cache name="realms" mode="SYNC"/>
<invalidation-cache name="users" mode="SYNC"/> <invalidation-cache name="users" mode="SYNC"/>
<distributed-cache name="sessions" mode="SYNC" owners="1" /> <distributed-cache name="sessions" mode="SYNC" owners="1" />
<distributed-cache name="loginFailures" mode="SYNC" owners="1" />
</cache-container> </cache-container>
... ...
</subsystem> </subsystem>

View file

@ -21,7 +21,7 @@ public class InfinispanCacheRealmProviderFactory implements CacheRealmProviderFa
@Override @Override
public CacheRealmProvider create(KeycloakSession session) { public CacheRealmProvider create(KeycloakSession session) {
Cache<String, Object> cache = session.getProvider(InfinispanConnectionProvider.class).getCache("realms"); Cache<String, Object> cache = session.getProvider(InfinispanConnectionProvider.class).getCache(InfinispanConnectionProvider.REALM_CACHE_NAME);
RealmCache realmCache = new InfinispanRealmCache(cache, realmLookup); RealmCache realmCache = new InfinispanRealmCache(cache, realmLookup);
return new DefaultCacheRealmProvider(realmCache, session); return new DefaultCacheRealmProvider(realmCache, session);
} }

View file

@ -41,7 +41,7 @@ public class InfinispanCacheUserProviderFactory implements CacheUserProviderFact
synchronized (this) { synchronized (this) {
if (userCache == null) { if (userCache == null) {
checkIspnVersion(); checkIspnVersion();
Cache<String, CachedUser> cache = session.getProvider(InfinispanConnectionProvider.class).getCache("users"); Cache<String, CachedUser> cache = session.getProvider(InfinispanConnectionProvider.class).getCache(InfinispanConnectionProvider.USER_CACHE_NAME);
cache.addListener(new CacheListener()); cache.addListener(new CacheListener());
userCache = new InfinispanUserCache(cache, usernameLookup, emailLookup); userCache = new InfinispanUserCache(cache, usernameLookup, emailLookup);
} }

View file

@ -15,14 +15,11 @@ import org.keycloak.models.sessions.infinispan.entities.SessionEntity;
*/ */
public class InfinispanUserSessionProviderFactory implements UserSessionProviderFactory { public class InfinispanUserSessionProviderFactory implements UserSessionProviderFactory {
private static final String SESSION_CACHE_NAME = "sessions";
private static final String LOGIN_FAILURE_CACHE_NAME = "loginFailures";
@Override @Override
public UserSessionProvider create(KeycloakSession session) { public UserSessionProvider create(KeycloakSession session) {
InfinispanConnectionProvider connections = session.getProvider(InfinispanConnectionProvider.class); InfinispanConnectionProvider connections = session.getProvider(InfinispanConnectionProvider.class);
Cache<String, SessionEntity> cache = connections.getCache(SESSION_CACHE_NAME); Cache<String, SessionEntity> cache = connections.getCache(InfinispanConnectionProvider.SESSION_CACHE_NAME);
Cache<LoginFailureKey, LoginFailureEntity> loginFailures = connections.getCache(LOGIN_FAILURE_CACHE_NAME); Cache<LoginFailureKey, LoginFailureEntity> loginFailures = connections.getCache(InfinispanConnectionProvider.LOGIN_FAILURE_CACHE_NAME);
return new InfinispanUserSessionProvider(session, cache, loginFailures); return new InfinispanUserSessionProvider(session, cache, loginFailures);
} }

View file

@ -20,7 +20,9 @@ sed -i -e 's/<\/periodic-rotating-file-handler>/&\n <logger category=\"org.keycl
sed -i -e 's/<subsystem xmlns=\"urn:jboss:domain:infinispan:[0-9]\.[0-9]\">/&\n <cache-container name=\"keycloak\" jndi-name=\"infinispan\/Keycloak\" start=\"EAGER\"> \ sed -i -e 's/<subsystem xmlns=\"urn:jboss:domain:infinispan:[0-9]\.[0-9]\">/&\n <cache-container name=\"keycloak\" jndi-name=\"infinispan\/Keycloak\" start=\"EAGER\"> \
\n <transport lock-timeout=\"60000\"\/>\n <distributed-cache name=\"sessions\" mode=\"SYNC\" owners=\"2\" segments=\"60\"\/> \ \n <transport lock-timeout=\"60000\"\/>\n <distributed-cache name=\"sessions\" mode=\"SYNC\" owners=\"2\" segments=\"60\"\/> \
\n <invalidation-cache name=\"realms\" mode=\"SYNC\"\/>\n <\/cache-container>/' $JBOSS_HOME/standalone/configuration/standalone-ha.xml \n <distributed-cache name=\"loginFailures\" mode=\"SYNC\" owners=\"2\" segments=\"60\"\/> \
\n <invalidation-cache name=\"realms\" mode=\"SYNC\"\/>\n \
\n <invalidation-cache name=\"users\" mode=\"SYNC\"\/>\n <\/cache-container>/' $JBOSS_HOME/standalone/configuration/standalone-ha.xml
sed -i "s|<mod-cluster-config .*>|<mod-cluster-config advertise-socket=\"modcluster\" proxy-list=\"\$\{httpd.proxyList\}\" proxy-url=\"\/\" balancer=\"mycluster\" advertise=\"false\" connector=\"ajp\" sticky-session=\"true\">|" $JBOSS_HOME/standalone/configuration/standalone-ha.xml sed -i "s|<mod-cluster-config .*>|<mod-cluster-config advertise-socket=\"modcluster\" proxy-list=\"\$\{httpd.proxyList\}\" proxy-url=\"\/\" balancer=\"mycluster\" advertise=\"false\" connector=\"ajp\" sticky-session=\"true\">|" $JBOSS_HOME/standalone/configuration/standalone-ha.xml