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
|
||||
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
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.keycloak.models.KeycloakSessionFactory;
|
|||
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;
|
||||
|
||||
|
@ -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) {
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -38,9 +38,10 @@ public class InfinispanRealmCache implements RealmCache {
|
|||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
clear();
|
||||
if (this.enabled && !enabled) {
|
||||
clear();
|
||||
}
|
||||
this.enabled = enabled;
|
||||
clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -35,9 +35,10 @@ public class InfinispanUserCache implements UserCache {
|
|||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
clear();
|
||||
if (this.enabled && !enabled) {
|
||||
clear();
|
||||
}
|
||||
this.enabled = enabled;
|
||||
clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue