KEYCLOAK-1813 KEYCLOAK-2182 Fixes enable/disable cache
This commit is contained in:
parent
09c18306c2
commit
ee6753d31b
5 changed files with 24 additions and 9 deletions
|
@ -63,9 +63,9 @@ supported-locales=Supported Locales
|
||||||
supported-locales.placeholder=Type a locale and enter
|
supported-locales.placeholder=Type a locale and enter
|
||||||
default-locale=Default Locale
|
default-locale=Default Locale
|
||||||
realm-cache-enabled=Realm Cache Enabled
|
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=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=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.
|
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
|
sso-session-idle=SSO Session Idle
|
||||||
|
|
|
@ -8,6 +8,7 @@ import org.keycloak.models.KeycloakSessionFactory;
|
||||||
import org.keycloak.models.cache.CacheRealmProvider;
|
import org.keycloak.models.cache.CacheRealmProvider;
|
||||||
import org.keycloak.models.cache.CacheRealmProviderFactory;
|
import org.keycloak.models.cache.CacheRealmProviderFactory;
|
||||||
import org.keycloak.models.cache.RealmCache;
|
import org.keycloak.models.cache.RealmCache;
|
||||||
|
import org.keycloak.models.cache.entities.CachedUser;
|
||||||
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
@ -19,13 +20,25 @@ public class InfinispanCacheRealmProviderFactory implements CacheRealmProviderFa
|
||||||
|
|
||||||
protected final ConcurrentHashMap<String, String> realmLookup = new ConcurrentHashMap<String, String>();
|
protected final ConcurrentHashMap<String, String> realmLookup = new ConcurrentHashMap<String, String>();
|
||||||
|
|
||||||
|
protected volatile InfinispanRealmCache realmCache;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CacheRealmProvider create(KeycloakSession session) {
|
public CacheRealmProvider create(KeycloakSession session) {
|
||||||
Cache<String, Object> cache = session.getProvider(InfinispanConnectionProvider.class).getCache(InfinispanConnectionProvider.REALM_CACHE_NAME);
|
lazyInit(session);
|
||||||
RealmCache realmCache = new InfinispanRealmCache(cache, realmLookup);
|
|
||||||
return new DefaultCacheRealmProvider(realmCache, 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
|
@Override
|
||||||
public void init(Config.Scope config) {
|
public void init(Config.Scope config) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class InfinispanCacheUserProviderFactory implements CacheUserProviderFact
|
||||||
|
|
||||||
private static final Logger log = Logger.getLogger(InfinispanCacheUserProviderFactory.class);
|
private static final Logger log = Logger.getLogger(InfinispanCacheUserProviderFactory.class);
|
||||||
|
|
||||||
protected InfinispanUserCache userCache;
|
protected volatile InfinispanUserCache userCache;
|
||||||
|
|
||||||
protected final RealmLookup usernameLookup = new RealmLookup();
|
protected final RealmLookup usernameLookup = new RealmLookup();
|
||||||
|
|
||||||
|
|
|
@ -38,9 +38,10 @@ public class InfinispanRealmCache implements RealmCache {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setEnabled(boolean enabled) {
|
public void setEnabled(boolean enabled) {
|
||||||
clear();
|
if (this.enabled && !enabled) {
|
||||||
|
clear();
|
||||||
|
}
|
||||||
this.enabled = enabled;
|
this.enabled = enabled;
|
||||||
clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -35,9 +35,10 @@ public class InfinispanUserCache implements UserCache {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setEnabled(boolean enabled) {
|
public void setEnabled(boolean enabled) {
|
||||||
clear();
|
if (this.enabled && !enabled) {
|
||||||
|
clear();
|
||||||
|
}
|
||||||
this.enabled = enabled;
|
this.enabled = enabled;
|
||||||
clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue