Skip to content

Commit

Permalink
KEYCLOAK-1813 KEYCLOAK-2182 Fixes enable/disable cache
Browse files Browse the repository at this point in the history
  • Loading branch information
stianst committed Dec 2, 2015
1 parent 09c1830 commit ee6753d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
Expand Up @@ -63,9 +63,9 @@ supported-locales=Supported Locales
supported-locales.placeholder=Type a locale and enter
default-locale=Default Locale
realm-cache-enabled=Realm Cache Enabled
realm-cache-enabled.tooltip=Enable/disable cache for realm, client and role data.
realm-cache-enabled.tooltip=Enable/disable cache for realms, clients and roles.
user-cache-enabled=User Cache Enabled
user-cache-enabled.tooltip=Enable/disable user and user role mapping cache.
user-cache-enabled.tooltip=Enable/disable cache for users and user role mappings.
revoke-refresh-token=Revoke Refresh Token
revoke-refresh-token.tooltip=If enabled refresh tokens can only be used once. Otherwise refresh tokens are not revoked when used and can be used multiple times.
sso-session-idle=SSO Session Idle
Expand Down
Expand Up @@ -8,6 +8,7 @@
import org.keycloak.models.cache.CacheRealmProvider;
import org.keycloak.models.cache.CacheRealmProviderFactory;
import org.keycloak.models.cache.RealmCache;
import org.keycloak.models.cache.entities.CachedUser;

import java.util.concurrent.ConcurrentHashMap;

Expand All @@ -19,13 +20,25 @@ public class InfinispanCacheRealmProviderFactory implements CacheRealmProviderFa

protected final ConcurrentHashMap<String, String> realmLookup = new ConcurrentHashMap<String, String>();

protected volatile InfinispanRealmCache realmCache;

@Override
public CacheRealmProvider create(KeycloakSession session) {
Cache<String, Object> cache = session.getProvider(InfinispanConnectionProvider.class).getCache(InfinispanConnectionProvider.REALM_CACHE_NAME);
RealmCache realmCache = new InfinispanRealmCache(cache, realmLookup);
lazyInit(session);
return new DefaultCacheRealmProvider(realmCache, session);
}

private void lazyInit(KeycloakSession session) {
if (realmCache == null) {
synchronized (this) {
if (realmCache == null) {
Cache<String, Object> cache = session.getProvider(InfinispanConnectionProvider.class).getCache(InfinispanConnectionProvider.REALM_CACHE_NAME);
realmCache = new InfinispanRealmCache(cache, realmLookup);
}
}
}
}

@Override
public void init(Config.Scope config) {
}
Expand Down
Expand Up @@ -26,7 +26,7 @@ public class InfinispanCacheUserProviderFactory implements CacheUserProviderFact

private static final Logger log = Logger.getLogger(InfinispanCacheUserProviderFactory.class);

protected InfinispanUserCache userCache;
protected volatile InfinispanUserCache userCache;

protected final RealmLookup usernameLookup = new RealmLookup();

Expand Down
Expand Up @@ -38,9 +38,10 @@ public boolean isEnabled() {

@Override
public void setEnabled(boolean enabled) {
clear();
if (this.enabled && !enabled) {
clear();
}
this.enabled = enabled;
clear();
}

@Override
Expand Down
Expand Up @@ -35,9 +35,10 @@ public boolean isEnabled() {

@Override
public void setEnabled(boolean enabled) {
clear();
if (this.enabled && !enabled) {
clear();
}
this.enabled = enabled;
clear();
}

@Override
Expand Down

0 comments on commit ee6753d

Please sign in to comment.