reorg caching

This commit is contained in:
Bill Burke 2016-02-19 16:38:31 -05:00
parent c45524d8d4
commit 2e64d01251
49 changed files with 185 additions and 475 deletions

View file

@ -19,8 +19,7 @@ package org.keycloak.models.cache.infinispan;
import org.keycloak.models.*; import org.keycloak.models.*;
import org.keycloak.models.cache.CacheRealmProvider; import org.keycloak.models.cache.CacheRealmProvider;
import org.keycloak.models.cache.RealmCache; import org.keycloak.models.cache.infinispan.entities.CachedClient;
import org.keycloak.models.cache.entities.CachedClient;
import java.util.*; import java.util.*;

View file

@ -24,8 +24,7 @@ import org.keycloak.models.RealmModel;
import org.keycloak.models.RoleContainerModel; import org.keycloak.models.RoleContainerModel;
import org.keycloak.models.RoleModel; import org.keycloak.models.RoleModel;
import org.keycloak.models.cache.CacheRealmProvider; import org.keycloak.models.cache.CacheRealmProvider;
import org.keycloak.models.cache.RealmCache; import org.keycloak.models.cache.infinispan.entities.CachedClientTemplate;
import org.keycloak.models.cache.entities.CachedClientTemplate;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -39,14 +38,12 @@ import java.util.Set;
public class ClientTemplateAdapter implements ClientTemplateModel { public class ClientTemplateAdapter implements ClientTemplateModel {
protected CacheRealmProvider cacheSession; protected CacheRealmProvider cacheSession;
protected RealmModel cachedRealm; protected RealmModel cachedRealm;
protected RealmCache cache;
protected ClientTemplateModel updated; protected ClientTemplateModel updated;
protected CachedClientTemplate cached; protected CachedClientTemplate cached;
public ClientTemplateAdapter(RealmModel cachedRealm, CachedClientTemplate cached, CacheRealmProvider cacheSession, RealmCache cache) { public ClientTemplateAdapter(RealmModel cachedRealm, CachedClientTemplate cached, CacheRealmProvider cacheSession) {
this.cachedRealm = cachedRealm; this.cachedRealm = cachedRealm;
this.cache = cache;
this.cacheSession = cacheSession; this.cacheSession = cacheSession;
this.cached = cached; this.cached = cached;
} }

View file

@ -19,8 +19,7 @@ package org.keycloak.models.cache.infinispan;
import org.keycloak.models.*; import org.keycloak.models.*;
import org.keycloak.models.cache.CacheUserProvider; import org.keycloak.models.cache.CacheUserProvider;
import org.keycloak.models.cache.UserCache; import org.keycloak.models.cache.infinispan.entities.CachedUser;
import org.keycloak.models.cache.entities.CachedUser;
import java.util.*; import java.util.*;

View file

@ -24,7 +24,7 @@ import org.keycloak.models.RealmModel;
import org.keycloak.models.RoleContainerModel; import org.keycloak.models.RoleContainerModel;
import org.keycloak.models.RoleModel; import org.keycloak.models.RoleModel;
import org.keycloak.models.cache.CacheRealmProvider; import org.keycloak.models.cache.CacheRealmProvider;
import org.keycloak.models.cache.entities.CachedGroup; import org.keycloak.models.cache.infinispan.entities.CachedGroup;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;

View file

@ -18,15 +18,6 @@
package org.keycloak.models.cache.infinispan; package org.keycloak.models.cache.infinispan;
import org.infinispan.Cache; import org.infinispan.Cache;
import org.infinispan.notifications.Listener;
import org.infinispan.notifications.cachelistener.annotation.CacheEntriesEvicted;
import org.infinispan.notifications.cachelistener.annotation.CacheEntryCreated;
import org.infinispan.notifications.cachelistener.annotation.CacheEntryInvalidated;
import org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved;
import org.infinispan.notifications.cachelistener.event.CacheEntriesEvictedEvent;
import org.infinispan.notifications.cachelistener.event.CacheEntryCreatedEvent;
import org.infinispan.notifications.cachelistener.event.CacheEntryInvalidatedEvent;
import org.infinispan.notifications.cachelistener.event.CacheEntryRemovedEvent;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.keycloak.Config; import org.keycloak.Config;
import org.keycloak.connections.infinispan.InfinispanConnectionProvider; import org.keycloak.connections.infinispan.InfinispanConnectionProvider;
@ -34,12 +25,7 @@ import org.keycloak.models.KeycloakSession;
import org.keycloak.models.KeycloakSessionFactory; 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.entities.CachedClient; import org.keycloak.models.cache.infinispan.entities.Revisioned;
import org.keycloak.models.cache.entities.CachedRealm;
import org.keycloak.models.cache.infinispan.stream.StreamCacheRealmProvider;
import org.keycloak.models.cache.infinispan.stream.StreamRealmCache;
import java.util.concurrent.ConcurrentHashMap;
/** /**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
@ -61,7 +47,7 @@ public class InfinispanCacheRealmProviderFactory implements CacheRealmProviderFa
if (realmCache == null) { if (realmCache == null) {
synchronized (this) { synchronized (this) {
if (realmCache == null) { if (realmCache == null) {
Cache<String, Object> cache = session.getProvider(InfinispanConnectionProvider.class).getCache(InfinispanConnectionProvider.REALM_CACHE_NAME); Cache<String, Revisioned> cache = session.getProvider(InfinispanConnectionProvider.class).getCache(InfinispanConnectionProvider.REALM_CACHE_NAME);
Cache<String, Long> revisions = session.getProvider(InfinispanConnectionProvider.class).getCache(InfinispanConnectionProvider.VERSION_CACHE_NAME); Cache<String, Long> revisions = session.getProvider(InfinispanConnectionProvider.class).getCache(InfinispanConnectionProvider.VERSION_CACHE_NAME);
realmCache = new StreamRealmCache(cache, revisions); realmCache = new StreamRealmCache(cache, revisions);
} }

View file

@ -28,7 +28,7 @@ import org.keycloak.models.KeycloakSession;
import org.keycloak.models.KeycloakSessionFactory; import org.keycloak.models.KeycloakSessionFactory;
import org.keycloak.models.cache.CacheUserProvider; import org.keycloak.models.cache.CacheUserProvider;
import org.keycloak.models.cache.CacheUserProviderFactory; import org.keycloak.models.cache.CacheUserProviderFactory;
import org.keycloak.models.cache.entities.CachedUser; import org.keycloak.models.cache.infinispan.entities.CachedUser;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;

View file

@ -19,8 +19,7 @@ package org.keycloak.models.cache.infinispan;
import org.infinispan.Cache; import org.infinispan.Cache;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.keycloak.models.cache.UserCache; import org.keycloak.models.cache.infinispan.entities.CachedUser;
import org.keycloak.models.cache.entities.CachedUser;
/** /**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a> * @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>

View file

@ -21,8 +21,7 @@ import org.keycloak.Config;
import org.keycloak.common.enums.SslRequired; import org.keycloak.common.enums.SslRequired;
import org.keycloak.models.*; import org.keycloak.models.*;
import org.keycloak.models.cache.CacheRealmProvider; import org.keycloak.models.cache.CacheRealmProvider;
import org.keycloak.models.cache.RealmCache; import org.keycloak.models.cache.infinispan.entities.CachedRealm;
import org.keycloak.models.cache.entities.CachedRealm;
import org.keycloak.models.utils.KeycloakModelUtils; import org.keycloak.models.utils.KeycloakModelUtils;
import java.security.Key; import java.security.Key;

View file

@ -15,13 +15,13 @@
* limitations under the License. * limitations under the License.
*/ */
package org.keycloak.models.cache; package org.keycloak.models.cache.infinispan;
import org.keycloak.models.cache.entities.CachedClient; import org.keycloak.models.cache.infinispan.entities.CachedClient;
import org.keycloak.models.cache.entities.CachedClientTemplate; import org.keycloak.models.cache.infinispan.entities.CachedClientTemplate;
import org.keycloak.models.cache.entities.CachedGroup; import org.keycloak.models.cache.infinispan.entities.CachedGroup;
import org.keycloak.models.cache.entities.CachedRealm; import org.keycloak.models.cache.infinispan.entities.CachedRealm;
import org.keycloak.models.cache.entities.CachedRole; import org.keycloak.models.cache.infinispan.entities.CachedRole;
/** /**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>

View file

@ -21,10 +21,9 @@ import org.keycloak.models.RealmModel;
import org.keycloak.models.RoleContainerModel; import org.keycloak.models.RoleContainerModel;
import org.keycloak.models.RoleModel; import org.keycloak.models.RoleModel;
import org.keycloak.models.cache.CacheRealmProvider; import org.keycloak.models.cache.CacheRealmProvider;
import org.keycloak.models.cache.RealmCache; import org.keycloak.models.cache.infinispan.entities.CachedClientRole;
import org.keycloak.models.cache.entities.CachedClientRole; import org.keycloak.models.cache.infinispan.entities.CachedRealmRole;
import org.keycloak.models.cache.entities.CachedRealmRole; import org.keycloak.models.cache.infinispan.entities.CachedRole;
import org.keycloak.models.cache.entities.CachedRole;
import org.keycloak.models.utils.KeycloakModelUtils; import org.keycloak.models.utils.KeycloakModelUtils;
import java.util.HashSet; import java.util.HashSet;
@ -38,13 +37,11 @@ public class RoleAdapter implements RoleModel {
protected RoleModel updated; protected RoleModel updated;
protected CachedRole cached; protected CachedRole cached;
protected RealmCache cache;
protected CacheRealmProvider cacheSession; protected CacheRealmProvider cacheSession;
protected RealmModel realm; protected RealmModel realm;
public RoleAdapter(CachedRole cached, RealmCache cache, CacheRealmProvider session, RealmModel realm) { public RoleAdapter(CachedRole cached, CacheRealmProvider session, RealmModel realm) {
this.cached = cached; this.cached = cached;
this.cache = cache;
this.cacheSession = session; this.cacheSession = session;
this.realm = realm; this.realm = realm;
} }

View file

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.keycloak.models.cache.infinispan.stream; package org.keycloak.models.cache.infinispan;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.keycloak.migration.MigrationModel; import org.keycloak.migration.MigrationModel;
@ -28,19 +28,16 @@ import org.keycloak.models.RealmModel;
import org.keycloak.models.RealmProvider; import org.keycloak.models.RealmProvider;
import org.keycloak.models.RoleModel; import org.keycloak.models.RoleModel;
import org.keycloak.models.cache.CacheRealmProvider; import org.keycloak.models.cache.CacheRealmProvider;
import org.keycloak.models.cache.entities.CachedRole; import org.keycloak.models.cache.infinispan.entities.CachedClient;
import org.keycloak.models.cache.infinispan.ClientAdapter; import org.keycloak.models.cache.infinispan.entities.CachedClientRole;
import org.keycloak.models.cache.infinispan.ClientTemplateAdapter; import org.keycloak.models.cache.infinispan.entities.CachedClientTemplate;
import org.keycloak.models.cache.infinispan.GroupAdapter; import org.keycloak.models.cache.infinispan.entities.CachedGroup;
import org.keycloak.models.cache.infinispan.RealmAdapter; import org.keycloak.models.cache.infinispan.entities.CachedRealm;
import org.keycloak.models.cache.infinispan.RoleAdapter; import org.keycloak.models.cache.infinispan.entities.CachedRealmRole;
import org.keycloak.models.cache.infinispan.stream.entities.Revisioned; import org.keycloak.models.cache.infinispan.entities.CachedRole;
import org.keycloak.models.cache.infinispan.stream.entities.RevisionedCachedClient; import org.keycloak.models.cache.infinispan.entities.ClientListQuery;
import org.keycloak.models.cache.infinispan.stream.entities.RevisionedCachedClientRole; import org.keycloak.models.cache.infinispan.entities.RealmListQuery;
import org.keycloak.models.cache.infinispan.stream.entities.RevisionedCachedClientTemplate; import org.keycloak.models.cache.infinispan.entities.Revisioned;
import org.keycloak.models.cache.infinispan.stream.entities.RevisionedCachedGroup;
import org.keycloak.models.cache.infinispan.stream.entities.RevisionedCachedRealm;
import org.keycloak.models.cache.infinispan.stream.entities.RevisionedCachedRealmRole;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -249,7 +246,7 @@ public class StreamCacheRealmProvider implements CacheRealmProvider {
@Override @Override
public RealmModel getRealm(String id) { public RealmModel getRealm(String id) {
RevisionedCachedRealm cached = cache.get(id, RevisionedCachedRealm.class); CachedRealm cached = cache.get(id, CachedRealm.class);
if (cached != null) { if (cached != null) {
logger.tracev("by id cache hit: {0}", cached.getName()); logger.tracev("by id cache hit: {0}", cached.getName());
} }
@ -258,7 +255,7 @@ public class StreamCacheRealmProvider implements CacheRealmProvider {
RealmModel model = getDelegate().getRealm(id); RealmModel model = getDelegate().getRealm(id);
if (model == null) return null; if (model == null) return null;
if (invalidations.contains(id)) return model; if (invalidations.contains(id)) return model;
cached = new RevisionedCachedRealm(loaded, null, this, model); cached = new CachedRealm(loaded, model);
cache.addRevisioned(cached); cache.addRevisioned(cached);
} else if (invalidations.contains(id)) { } else if (invalidations.contains(id)) {
return getDelegate().getRealm(id); return getDelegate().getRealm(id);
@ -415,25 +412,25 @@ public class StreamCacheRealmProvider implements CacheRealmProvider {
if (model == null) return null; if (model == null) return null;
if (invalidations.contains(id)) return model; if (invalidations.contains(id)) return model;
if (model.getContainer() instanceof ClientModel) { if (model.getContainer() instanceof ClientModel) {
cached = new RevisionedCachedClientRole(loaded, ((ClientModel) model.getContainer()).getId(), model, realm); cached = new CachedClientRole(loaded, ((ClientModel) model.getContainer()).getId(), model, realm);
} else { } else {
cached = new RevisionedCachedRealmRole(loaded, model, realm); cached = new CachedRealmRole(loaded, model, realm);
} }
cache.addRevisioned((Revisioned)cached); cache.addRevisioned(cached);
} else if (invalidations.contains(id)) { } else if (invalidations.contains(id)) {
return getDelegate().getRoleById(id, realm); return getDelegate().getRoleById(id, realm);
} else if (managedRoles.containsKey(id)) { } else if (managedRoles.containsKey(id)) {
return managedRoles.get(id); return managedRoles.get(id);
} }
RoleAdapter adapter = new RoleAdapter(cached, null, this, realm); RoleAdapter adapter = new RoleAdapter(cached,this, realm);
managedRoles.put(id, adapter); managedRoles.put(id, adapter);
return adapter; return adapter;
} }
@Override @Override
public GroupModel getGroupById(String id, RealmModel realm) { public GroupModel getGroupById(String id, RealmModel realm) {
RevisionedCachedGroup cached = cache.get(id, RevisionedCachedGroup.class); CachedGroup cached = cache.get(id, CachedGroup.class);
if (cached != null && !cached.getRealm().equals(realm.getId())) { if (cached != null && !cached.getRealm().equals(realm.getId())) {
cached = null; cached = null;
} }
@ -443,7 +440,7 @@ public class StreamCacheRealmProvider implements CacheRealmProvider {
GroupModel model = getDelegate().getGroupById(id, realm); GroupModel model = getDelegate().getGroupById(id, realm);
if (model == null) return null; if (model == null) return null;
if (invalidations.contains(id)) return model; if (invalidations.contains(id)) return model;
cached = new RevisionedCachedGroup(loaded, realm, model); cached = new CachedGroup(loaded, realm, model);
cache.addRevisioned(cached); cache.addRevisioned(cached);
} else if (invalidations.contains(id)) { } else if (invalidations.contains(id)) {
@ -458,7 +455,7 @@ public class StreamCacheRealmProvider implements CacheRealmProvider {
@Override @Override
public ClientModel getClientById(String id, RealmModel realm) { public ClientModel getClientById(String id, RealmModel realm) {
RevisionedCachedClient cached = cache.get(id, RevisionedCachedClient.class); CachedClient cached = cache.get(id, CachedClient.class);
if (cached != null && !cached.getRealm().equals(realm.getId())) { if (cached != null && !cached.getRealm().equals(realm.getId())) {
cached = null; cached = null;
} }
@ -471,7 +468,7 @@ public class StreamCacheRealmProvider implements CacheRealmProvider {
ClientModel model = getDelegate().getClientById(id, realm); ClientModel model = getDelegate().getClientById(id, realm);
if (model == null) return null; if (model == null) return null;
if (invalidations.contains(id)) return model; if (invalidations.contains(id)) return model;
cached = new RevisionedCachedClient(loaded, null, getDelegate(), realm, model); cached = new CachedClient(loaded, realm, model);
logger.tracev("adding client by id cache miss: {0}", cached.getClientId()); logger.tracev("adding client by id cache miss: {0}", cached.getClientId());
cache.addRevisioned(cached); cache.addRevisioned(cached);
} else if (invalidations.contains(id)) { } else if (invalidations.contains(id)) {
@ -516,7 +513,7 @@ public class StreamCacheRealmProvider implements CacheRealmProvider {
@Override @Override
public ClientTemplateModel getClientTemplateById(String id, RealmModel realm) { public ClientTemplateModel getClientTemplateById(String id, RealmModel realm) {
RevisionedCachedClientTemplate cached = cache.get(id, RevisionedCachedClientTemplate.class); CachedClientTemplate cached = cache.get(id, CachedClientTemplate.class);
if (cached != null && !cached.getRealm().equals(realm.getId())) { if (cached != null && !cached.getRealm().equals(realm.getId())) {
cached = null; cached = null;
} }
@ -526,14 +523,14 @@ public class StreamCacheRealmProvider implements CacheRealmProvider {
ClientTemplateModel model = getDelegate().getClientTemplateById(id, realm); ClientTemplateModel model = getDelegate().getClientTemplateById(id, realm);
if (model == null) return null; if (model == null) return null;
if (invalidations.contains(id)) return model; if (invalidations.contains(id)) return model;
cached = new RevisionedCachedClientTemplate(loaded, null, getDelegate(), realm, model); cached = new CachedClientTemplate(loaded, realm, model);
cache.addRevisioned(cached); cache.addRevisioned(cached);
} else if (invalidations.contains(id)) { } else if (invalidations.contains(id)) {
return getDelegate().getClientTemplateById(id, realm); return getDelegate().getClientTemplateById(id, realm);
} else if (managedClientTemplates.containsKey(id)) { } else if (managedClientTemplates.containsKey(id)) {
return managedClientTemplates.get(id); return managedClientTemplates.get(id);
} }
ClientTemplateModel adapter = new ClientTemplateAdapter(realm, cached, this, null); ClientTemplateModel adapter = new ClientTemplateAdapter(realm, cached, this);
managedClientTemplates.put(id, adapter); managedClientTemplates.put(id, adapter);
return adapter; return adapter;
} }

View file

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.keycloak.models.cache.infinispan.stream; package org.keycloak.models.cache.infinispan;
import org.infinispan.Cache; import org.infinispan.Cache;
import org.infinispan.notifications.Listener; import org.infinispan.notifications.Listener;
@ -24,12 +24,19 @@ import org.infinispan.notifications.cachelistener.annotation.CacheEntryInvalidat
import org.infinispan.notifications.cachelistener.event.CacheEntriesEvictedEvent; import org.infinispan.notifications.cachelistener.event.CacheEntriesEvictedEvent;
import org.infinispan.notifications.cachelistener.event.CacheEntryInvalidatedEvent; import org.infinispan.notifications.cachelistener.event.CacheEntryInvalidatedEvent;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.keycloak.models.cache.entities.CachedClient; import org.keycloak.models.cache.infinispan.entities.CachedClient;
import org.keycloak.models.cache.entities.CachedClientTemplate; import org.keycloak.models.cache.infinispan.entities.CachedClientTemplate;
import org.keycloak.models.cache.entities.CachedGroup; import org.keycloak.models.cache.infinispan.entities.CachedGroup;
import org.keycloak.models.cache.entities.CachedRealm; import org.keycloak.models.cache.infinispan.entities.CachedRealm;
import org.keycloak.models.cache.entities.CachedRole; import org.keycloak.models.cache.infinispan.entities.CachedRole;
import org.keycloak.models.cache.infinispan.stream.entities.Revisioned; import org.keycloak.models.cache.infinispan.entities.Revisioned;
import org.keycloak.models.cache.infinispan.stream.ClientQueryPredicate;
import org.keycloak.models.cache.infinispan.stream.ClientTemplateQueryPredicate;
import org.keycloak.models.cache.infinispan.stream.GroupQueryPredicate;
import org.keycloak.models.cache.infinispan.stream.HasRolePredicate;
import org.keycloak.models.cache.infinispan.stream.InClientPredicate;
import org.keycloak.models.cache.infinispan.stream.InRealmPredicate;
import org.keycloak.models.cache.infinispan.stream.RealmQueryPredicate;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -46,15 +53,15 @@ public class StreamRealmCache {
protected static final Logger logger = Logger.getLogger(StreamRealmCache.class); protected static final Logger logger = Logger.getLogger(StreamRealmCache.class);
protected final Cache<String, Long> revisions; protected final Cache<String, Long> revisions;
protected final Cache<String, Object> cache; protected final Cache<String, Revisioned> cache;
public StreamRealmCache(Cache<String, Object> cache, Cache<String, Long> revisions) { public StreamRealmCache(Cache<String, Revisioned> cache, Cache<String, Long> revisions) {
this.cache = cache; this.cache = cache;
this.cache.addListener(this); this.cache.addListener(this);
this.revisions = revisions; this.revisions = revisions;
} }
public Cache<String, Object> getCache() { public Cache<String, Revisioned> getCache() {
return cache; return cache;
} }
@ -144,11 +151,11 @@ public class StreamRealmCache {
} }
public void realmInvalidation(String id, Set<String> invalidations) { public void realmInvalidation(String id, Set<String> invalidations) {
Predicate<Map.Entry<String, Object>> predicate = getRealmInvalidationPredicate(id); Predicate<Map.Entry<String, Revisioned>> predicate = getRealmInvalidationPredicate(id);
addInvalidations(predicate, invalidations); addInvalidations(predicate, invalidations);
} }
public Predicate<Map.Entry<String, Object>> getRealmInvalidationPredicate(String id) { public Predicate<Map.Entry<String, Revisioned>> getRealmInvalidationPredicate(String id) {
return RealmQueryPredicate.create().realm(id); return RealmQueryPredicate.create().realm(id);
} }
@ -156,7 +163,7 @@ public class StreamRealmCache {
addInvalidations(getClientInvalidationPredicate(id), invalidations); addInvalidations(getClientInvalidationPredicate(id), invalidations);
} }
public Predicate<Map.Entry<String, Object>> getClientInvalidationPredicate(String id) { public Predicate<Map.Entry<String, Revisioned>> getClientInvalidationPredicate(String id) {
return ClientQueryPredicate.create().client(id); return ClientQueryPredicate.create().client(id);
} }
@ -165,7 +172,7 @@ public class StreamRealmCache {
} }
public Predicate<Map.Entry<String, Object>> getRoleInvalidationPredicate(String id) { public Predicate<Map.Entry<String, Revisioned>> getRoleInvalidationPredicate(String id) {
return HasRolePredicate.create().role(id); return HasRolePredicate.create().role(id);
} }
@ -174,7 +181,7 @@ public class StreamRealmCache {
} }
public Predicate<Map.Entry<String, Object>> getGroupInvalidationPredicate(String id) { public Predicate<Map.Entry<String, Revisioned>> getGroupInvalidationPredicate(String id) {
return GroupQueryPredicate.create().group(id); return GroupQueryPredicate.create().group(id);
} }
@ -183,17 +190,17 @@ public class StreamRealmCache {
} }
public Predicate<Map.Entry<String, Object>> getClientTemplateInvalidationPredicate(String id) { public Predicate<Map.Entry<String, Revisioned>> getClientTemplateInvalidationPredicate(String id) {
return ClientTemplateQueryPredicate.create().template(id); return ClientTemplateQueryPredicate.create().template(id);
} }
public void realmRemoval(String id, Set<String> invalidations) { public void realmRemoval(String id, Set<String> invalidations) {
Predicate<Map.Entry<String, Object>> predicate = getRealmRemovalPredicate(id); Predicate<Map.Entry<String, Revisioned>> predicate = getRealmRemovalPredicate(id);
addInvalidations(predicate, invalidations); addInvalidations(predicate, invalidations);
} }
public Predicate<Map.Entry<String, Object>> getRealmRemovalPredicate(String id) { public Predicate<Map.Entry<String, Revisioned>> getRealmRemovalPredicate(String id) {
Predicate<Map.Entry<String, Object>> predicate = null; Predicate<Map.Entry<String, Revisioned>> predicate = null;
predicate = RealmQueryPredicate.create().realm(id) predicate = RealmQueryPredicate.create().realm(id)
.or(InRealmPredicate.create().realm(id)); .or(InRealmPredicate.create().realm(id));
return predicate; return predicate;
@ -203,18 +210,18 @@ public class StreamRealmCache {
addInvalidations(getClientAddedPredicate(realmId), invalidations); addInvalidations(getClientAddedPredicate(realmId), invalidations);
} }
public Predicate<Map.Entry<String, Object>> getClientAddedPredicate(String realmId) { public Predicate<Map.Entry<String, Revisioned>> getClientAddedPredicate(String realmId) {
return ClientQueryPredicate.create().inRealm(realmId); return ClientQueryPredicate.create().inRealm(realmId);
} }
public void clientRemoval(String realmId, String id, Set<String> invalidations) { public void clientRemoval(String realmId, String id, Set<String> invalidations) {
Predicate<Map.Entry<String, Object>> predicate = null; Predicate<Map.Entry<String, Revisioned>> predicate = null;
predicate = getClientRemovalPredicate(realmId, id); predicate = getClientRemovalPredicate(realmId, id);
addInvalidations(predicate, invalidations); addInvalidations(predicate, invalidations);
} }
public Predicate<Map.Entry<String, Object>> getClientRemovalPredicate(String realmId, String id) { public Predicate<Map.Entry<String, Revisioned>> getClientRemovalPredicate(String realmId, String id) {
Predicate<Map.Entry<String, Object>> predicate; Predicate<Map.Entry<String, Revisioned>> predicate;
predicate = ClientQueryPredicate.create().inRealm(realmId) predicate = ClientQueryPredicate.create().inRealm(realmId)
.or(ClientQueryPredicate.create().client(id)) .or(ClientQueryPredicate.create().client(id))
.or(InClientPredicate.create().client(id)); .or(InClientPredicate.create().client(id));
@ -226,18 +233,18 @@ public class StreamRealmCache {
} }
public Predicate<Map.Entry<String, Object>> getRoleRemovalPredicate(String id) { public Predicate<Map.Entry<String, Revisioned>> getRoleRemovalPredicate(String id) {
return getRoleInvalidationPredicate(id); return getRoleInvalidationPredicate(id);
} }
public void addInvalidations(Predicate<Map.Entry<String, Object>> predicate, Set<String> invalidations) { public void addInvalidations(Predicate<Map.Entry<String, Revisioned>> predicate, Set<String> invalidations) {
Iterator<Map.Entry<String, Object>> it = getEntryIterator(predicate); Iterator<Map.Entry<String, Revisioned>> it = getEntryIterator(predicate);
while (it.hasNext()) { while (it.hasNext()) {
invalidations.add(it.next().getKey()); invalidations.add(it.next().getKey());
} }
} }
private Iterator<Map.Entry<String, Object>> getEntryIterator(Predicate<Map.Entry<String, Object>> predicate) { private Iterator<Map.Entry<String, Revisioned>> getEntryIterator(Predicate<Map.Entry<String, Revisioned>> predicate) {
return cache return cache
.entrySet() .entrySet()
.stream() .stream()
@ -249,7 +256,7 @@ public class StreamRealmCache {
if (event.isPre()) { if (event.isPre()) {
Object object = event.getValue(); Object object = event.getValue();
if (object != null) { if (object != null) {
Predicate<Map.Entry<String, Object>> predicate = getInvalidationPredicate(object); Predicate<Map.Entry<String, Revisioned>> predicate = getInvalidationPredicate(object);
if (predicate != null) runEvictions(predicate); if (predicate != null) runEvictions(predicate);
} }
} }
@ -258,18 +265,18 @@ public class StreamRealmCache {
@CacheEntriesEvicted @CacheEntriesEvicted
public void cacheEvicted(CacheEntriesEvictedEvent<String, Object> event) { public void cacheEvicted(CacheEntriesEvictedEvent<String, Object> event) {
for (Object object : event.getEntries().values()) { for (Object object : event.getEntries().values()) {
Predicate<Map.Entry<String, Object>> predicate = getEvictionPredicate(object); Predicate<Map.Entry<String, Revisioned>> predicate = getEvictionPredicate(object);
if (predicate != null) runEvictions(predicate); if (predicate != null) runEvictions(predicate);
} }
} }
public void runEvictions(Predicate<Map.Entry<String, Object>> current) { public void runEvictions(Predicate<Map.Entry<String, Revisioned>> current) {
Set<String> evictions = new HashSet<>(); Set<String> evictions = new HashSet<>();
addInvalidations(current, evictions); addInvalidations(current, evictions);
for (String key : evictions) cache.evict(key); for (String key : evictions) cache.evict(key);
} }
protected Predicate<Map.Entry<String, Object>> getEvictionPredicate(Object object) { protected Predicate<Map.Entry<String, Revisioned>> getEvictionPredicate(Object object) {
if (object instanceof CachedRealm) { if (object instanceof CachedRealm) {
CachedRealm cached = (CachedRealm)object; CachedRealm cached = (CachedRealm)object;
return getRealmInvalidationPredicate(cached.getId()); return getRealmInvalidationPredicate(cached.getId());
@ -288,13 +295,13 @@ public class StreamRealmCache {
} }
return null; return null;
} }
protected Predicate<Map.Entry<String, Object>> getInvalidationPredicate(Object object) { protected Predicate<Map.Entry<String, Revisioned>> getInvalidationPredicate(Object object) {
if (object instanceof CachedRealm) { if (object instanceof CachedRealm) {
CachedRealm cached = (CachedRealm)object; CachedRealm cached = (CachedRealm)object;
return getRealmRemovalPredicate(cached.getId()); return getRealmRemovalPredicate(cached.getId());
} else if (object instanceof CachedClient) { } else if (object instanceof CachedClient) {
CachedClient cached = (CachedClient)object; CachedClient cached = (CachedClient)object;
Predicate<Map.Entry<String, Object>> predicate = getClientRemovalPredicate(cached.getRealm(), cached.getId()); Predicate<Map.Entry<String, Revisioned>> predicate = getClientRemovalPredicate(cached.getRealm(), cached.getId());
for (String roleId : cached.getRoles().values()) { for (String roleId : cached.getRoles().values()) {
predicate.or(getRoleRemovalPredicate(roleId)); predicate.or(getRoleRemovalPredicate(roleId));
} }

View file

@ -1,4 +1,4 @@
package org.keycloak.models.cache.infinispan.stream; package org.keycloak.models.cache.infinispan;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;

View file

@ -19,7 +19,7 @@ package org.keycloak.models.cache.infinispan;
import org.keycloak.models.*; import org.keycloak.models.*;
import org.keycloak.models.cache.CacheUserProvider; import org.keycloak.models.cache.CacheUserProvider;
import org.keycloak.models.cache.entities.CachedUser; import org.keycloak.models.cache.infinispan.entities.CachedUser;
import org.keycloak.models.utils.KeycloakModelUtils; import org.keycloak.models.utils.KeycloakModelUtils;
import java.util.*; import java.util.*;

View file

@ -15,9 +15,9 @@
* limitations under the License. * limitations under the License.
*/ */
package org.keycloak.models.cache; package org.keycloak.models.cache.infinispan;
import org.keycloak.models.cache.entities.CachedUser; import org.keycloak.models.cache.infinispan.entities.CachedUser;
/** /**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>

View file

@ -1,10 +1,12 @@
package org.keycloak.models.cache.infinispan.stream.entities; package org.keycloak.models.cache.infinispan.entities;
import java.io.Serializable;
/** /**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $ * @version $Revision: 1 $
*/ */
public class AbstractRevisioned implements Revisioned { public class AbstractRevisioned implements Revisioned, Serializable {
private String id; private String id;
private Long revision; private Long revision;

View file

@ -15,14 +15,14 @@
* limitations under the License. * limitations under the License.
*/ */
package org.keycloak.models.cache.entities; package org.keycloak.models.cache.infinispan.entities;
import org.keycloak.models.ClientModel; import org.keycloak.models.ClientModel;
import org.keycloak.models.ProtocolMapperModel; import org.keycloak.models.ProtocolMapperModel;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;
import org.keycloak.models.RealmProvider; import org.keycloak.models.RealmProvider;
import org.keycloak.models.RoleModel; import org.keycloak.models.RoleModel;
import org.keycloak.models.cache.RealmCache; import org.keycloak.models.cache.infinispan.RealmCache;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
@ -37,9 +37,7 @@ import java.util.TreeMap;
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $ * @version $Revision: 1 $
*/ */
public class CachedClient implements Serializable { public class CachedClient extends AbstractRevisioned implements InRealm {
protected String id;
protected String clientId; protected String clientId;
protected String name; protected String name;
protected String description; protected String description;
@ -77,8 +75,8 @@ public class CachedClient implements Serializable {
protected boolean useTemplateConfig; protected boolean useTemplateConfig;
protected boolean useTemplateMappers; protected boolean useTemplateMappers;
public CachedClient(RealmCache cache, RealmProvider delegate, RealmModel realm, ClientModel model) { public CachedClient(Long revision, RealmModel realm, ClientModel model) {
id = model.getId(); super(revision, model.getId());
clientAuthenticatorType = model.getClientAuthenticatorType(); clientAuthenticatorType = model.getClientAuthenticatorType();
secret = model.getSecret(); secret = model.getSecret();
registrationToken = model.getRegistrationToken(); registrationToken = model.getRegistrationToken();
@ -112,10 +110,10 @@ public class CachedClient implements Serializable {
implicitFlowEnabled = model.isImplicitFlowEnabled(); implicitFlowEnabled = model.isImplicitFlowEnabled();
directAccessGrantsEnabled = model.isDirectAccessGrantsEnabled(); directAccessGrantsEnabled = model.isDirectAccessGrantsEnabled();
serviceAccountsEnabled = model.isServiceAccountsEnabled(); serviceAccountsEnabled = model.isServiceAccountsEnabled();
cacheRoles(cache, realm, model); cacheRoles(model);
nodeReRegistrationTimeout = model.getNodeReRegistrationTimeout(); nodeReRegistrationTimeout = model.getNodeReRegistrationTimeout();
registeredNodes = new TreeMap<String, Integer>(model.getRegisteredNodes()); registeredNodes = new TreeMap<>(model.getRegisteredNodes());
if (model.getClientTemplate() != null) { if (model.getClientTemplate() != null) {
clientTemplate = model.getClientTemplate().getId(); clientTemplate = model.getClientTemplate().getId();
} }
@ -124,17 +122,12 @@ public class CachedClient implements Serializable {
useTemplateScope = model.useTemplateScope(); useTemplateScope = model.useTemplateScope();
} }
protected void cacheRoles(RealmCache cache, RealmModel realm, ClientModel model) { protected void cacheRoles(ClientModel model) {
for (RoleModel role : model.getRoles()) { for (RoleModel role : model.getRoles()) {
roles.put(role.getName(), role.getId()); roles.put(role.getName(), role.getId());
cache.addRole(new CachedClientRole(id, role, realm));
} }
} }
public String getId() {
return id;
}
public String getClientId() { public String getClientId() {
return clientId; return clientId;
} }

View file

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.keycloak.models.cache.entities; package org.keycloak.models.cache.infinispan.entities;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;
import org.keycloak.models.RoleModel; import org.keycloak.models.RoleModel;
@ -24,12 +24,12 @@ import org.keycloak.models.RoleModel;
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $ * @version $Revision: 1 $
*/ */
public class CachedClientRole extends CachedRole { public class CachedClientRole extends CachedRole implements InClient {
private final String clientId; private final String clientId;
public CachedClientRole(String clientId, RoleModel model, RealmModel realm) { public CachedClientRole(Long revision, String clientId, RoleModel model, RealmModel realm) {
super(model, realm); super(revision, model, realm);
this.clientId = clientId; this.clientId = clientId;
} }

View file

@ -15,14 +15,14 @@
* limitations under the License. * limitations under the License.
*/ */
package org.keycloak.models.cache.entities; package org.keycloak.models.cache.infinispan.entities;
import org.keycloak.models.ClientTemplateModel; import org.keycloak.models.ClientTemplateModel;
import org.keycloak.models.ProtocolMapperModel; import org.keycloak.models.ProtocolMapperModel;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;
import org.keycloak.models.RealmProvider; import org.keycloak.models.RealmProvider;
import org.keycloak.models.RoleModel; import org.keycloak.models.RoleModel;
import org.keycloak.models.cache.RealmCache; import org.keycloak.models.cache.infinispan.RealmCache;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
@ -34,9 +34,8 @@ import java.util.Set;
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $ * @version $Revision: 1 $
*/ */
public class CachedClientTemplate implements Serializable { public class CachedClientTemplate extends AbstractRevisioned implements InRealm {
private String id;
private String name; private String name;
private String description; private String description;
private String realm; private String realm;
@ -50,12 +49,12 @@ public class CachedClientTemplate implements Serializable {
private boolean implicitFlowEnabled; private boolean implicitFlowEnabled;
private boolean directAccessGrantsEnabled; private boolean directAccessGrantsEnabled;
private boolean serviceAccountsEnabled; private boolean serviceAccountsEnabled;
private Set<String> scope = new HashSet<String>(); private Set<String> scope = new HashSet<>();
private Set<ProtocolMapperModel> protocolMappers = new HashSet<ProtocolMapperModel>(); private Set<ProtocolMapperModel> protocolMappers = new HashSet<ProtocolMapperModel>();
private Map<String, String> attributes = new HashMap<String, String>(); private Map<String, String> attributes = new HashMap<>();
public CachedClientTemplate(RealmCache cache, RealmProvider delegate, RealmModel realm, ClientTemplateModel model) { public CachedClientTemplate(Long revision, RealmModel realm, ClientTemplateModel model) {
id = model.getId(); super(revision, model.getId());
name = model.getName(); name = model.getName();
description = model.getDescription(); description = model.getDescription();
this.realm = realm.getId(); this.realm = realm.getId();
@ -77,10 +76,6 @@ public class CachedClientTemplate implements Serializable {
directAccessGrantsEnabled = model.isDirectAccessGrantsEnabled(); directAccessGrantsEnabled = model.isDirectAccessGrantsEnabled();
serviceAccountsEnabled = model.isServiceAccountsEnabled(); serviceAccountsEnabled = model.isServiceAccountsEnabled();
} }
public String getId() {
return id;
}
public String getName() { public String getName() {
return name; return name;

View file

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.keycloak.models.cache.entities; package org.keycloak.models.cache.infinispan.entities;
import org.keycloak.common.util.MultivaluedHashMap; import org.keycloak.common.util.MultivaluedHashMap;
import org.keycloak.models.GroupModel; import org.keycloak.models.GroupModel;
@ -30,8 +30,7 @@ import java.util.Set;
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $ * @version $Revision: 1 $
*/ */
public class CachedGroup implements Serializable { public class CachedGroup extends AbstractRevisioned implements InRealm {
private String id;
private String realm; private String realm;
private String name; private String name;
private String parentId; private String parentId;
@ -39,8 +38,8 @@ public class CachedGroup implements Serializable {
private Set<String> roleMappings = new HashSet<>(); private Set<String> roleMappings = new HashSet<>();
private Set<String> subGroups = new HashSet<>(); private Set<String> subGroups = new HashSet<>();
public CachedGroup(RealmModel realm, GroupModel group) { public CachedGroup(Long revision, RealmModel realm, GroupModel group) {
this.id = group.getId(); super(revision, group.getId());
this.realm = realm.getId(); this.realm = realm.getId();
this.name = group.getName(); this.name = group.getName();
this.parentId = group.getParentId(); this.parentId = group.getParentId();
@ -57,10 +56,6 @@ public class CachedGroup implements Serializable {
} }
} }
public String getId() {
return id;
}
public String getRealm() { public String getRealm() {
return realm; return realm;
} }

View file

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.keycloak.models.cache.entities; package org.keycloak.models.cache.infinispan.entities;
import org.keycloak.common.enums.SslRequired; import org.keycloak.common.enums.SslRequired;
import org.keycloak.models.AuthenticationExecutionModel; import org.keycloak.models.AuthenticationExecutionModel;
@ -35,7 +35,7 @@ import org.keycloak.models.RequiredCredentialModel;
import org.keycloak.models.RoleModel; import org.keycloak.models.RoleModel;
import org.keycloak.models.UserFederationMapperModel; import org.keycloak.models.UserFederationMapperModel;
import org.keycloak.models.UserFederationProviderModel; import org.keycloak.models.UserFederationProviderModel;
import org.keycloak.models.cache.RealmCache; import org.keycloak.models.cache.infinispan.RealmCache;
import org.keycloak.common.util.MultivaluedHashMap; import org.keycloak.common.util.MultivaluedHashMap;
import java.io.Serializable; import java.io.Serializable;
@ -56,9 +56,8 @@ import java.util.Set;
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $ * @version $Revision: 1 $
*/ */
public class CachedRealm implements Serializable { public class CachedRealm extends AbstractRevisioned {
protected String id;
protected String name; protected String name;
protected String displayName; protected String displayName;
protected String displayNameHtml; protected String displayNameHtml;
@ -155,11 +154,8 @@ public class CachedRealm implements Serializable {
protected MultivaluedHashMap<String, IdentityProviderMapperModel> identityProviderMappers = new MultivaluedHashMap<>(); protected MultivaluedHashMap<String, IdentityProviderMapperModel> identityProviderMappers = new MultivaluedHashMap<>();
protected Set<IdentityProviderMapperModel> identityProviderMapperSet; protected Set<IdentityProviderMapperModel> identityProviderMapperSet;
public CachedRealm() { public CachedRealm(Long revision, RealmModel model) {
} super(revision, model.getId());
public CachedRealm(RealmCache cache, RealmProvider delegate, RealmModel model) {
id = model.getId();
name = model.getName(); name = model.getName();
displayName = model.getDisplayName(); displayName = model.getDisplayName();
displayNameHtml = model.getDisplayNameHtml(); displayNameHtml = model.getDisplayNameHtml();
@ -244,11 +240,11 @@ public class CachedRealm implements Serializable {
ClientModel masterAdminClient = model.getMasterAdminClient(); ClientModel masterAdminClient = model.getMasterAdminClient();
this.masterAdminClient = (masterAdminClient != null) ? masterAdminClient.getId() : null; this.masterAdminClient = (masterAdminClient != null) ? masterAdminClient.getId() : null;
cacheRealmRoles(cache, model); cacheRealmRoles(model);
cacheClients(cache, delegate, model); cacheClients(model);
cacheClientTemplates(cache, delegate, model); cacheClientTemplates(model);
internationalizationEnabled = model.isInternationalizationEnabled(); internationalizationEnabled = model.isInternationalizationEnabled();
supportedLocales = model.getSupportedLocales(); supportedLocales = model.getSupportedLocales();
@ -286,35 +282,25 @@ public class CachedRealm implements Serializable {
} }
protected void cacheClientTemplates(RealmCache cache, RealmProvider delegate, RealmModel model) { protected void cacheClientTemplates(RealmModel model) {
for (ClientTemplateModel template : model.getClientTemplates()) { for (ClientTemplateModel template : model.getClientTemplates()) {
clientTemplates.add(template.getId()); clientTemplates.add(template.getId());
CachedClientTemplate cachedClient = new CachedClientTemplate(cache, delegate, model, template);
cache.addClientTemplate(cachedClient);
} }
} }
protected void cacheClients(RealmCache cache, RealmProvider delegate, RealmModel model) { protected void cacheClients(RealmModel model) {
for (ClientModel client : model.getClients()) { for (ClientModel client : model.getClients()) {
clients.add(client.getId()); clients.add(client.getId());
CachedClient cachedClient = new CachedClient(cache, delegate, model, client);
cache.addClient(cachedClient);
} }
} }
protected void cacheRealmRoles(RealmCache cache, RealmModel model) { protected void cacheRealmRoles(RealmModel model) {
for (RoleModel role : model.getRoles()) { for (RoleModel role : model.getRoles()) {
realmRoles.put(role.getName(), role.getId()); realmRoles.put(role.getName(), role.getId());
CachedRole cachedRole = new CachedRealmRole(role, model);
cache.addRole(cachedRole);
} }
} }
public String getId() {
return id;
}
public String getMasterAdminClient() { public String getMasterAdminClient() {
return masterAdminClient; return masterAdminClient;
} }

View file

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.keycloak.models.cache.entities; package org.keycloak.models.cache.infinispan.entities;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;
import org.keycloak.models.RoleModel; import org.keycloak.models.RoleModel;
@ -27,8 +27,8 @@ import org.keycloak.models.RoleModel;
public class CachedRealmRole extends CachedRole { public class CachedRealmRole extends CachedRole {
public CachedRealmRole(RoleModel model, RealmModel realm) { public CachedRealmRole(Long revision, RoleModel model, RealmModel realm) {
super(model, realm); super(revision, model, realm);
} }

View file

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.keycloak.models.cache.entities; package org.keycloak.models.cache.infinispan.entities;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;
import org.keycloak.models.RoleModel; import org.keycloak.models.RoleModel;
@ -28,9 +28,8 @@ import java.util.Set;
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $ * @version $Revision: 1 $
*/ */
public class CachedRole implements Serializable { public class CachedRole extends AbstractRevisioned implements InRealm {
final protected String id;
final protected String name; final protected String name;
final protected String realm; final protected String realm;
final protected String description; final protected String description;
@ -38,10 +37,10 @@ public class CachedRole implements Serializable {
final protected boolean composite; final protected boolean composite;
final protected Set<String> composites = new HashSet<String>(); final protected Set<String> composites = new HashSet<String>();
public CachedRole(RoleModel model, RealmModel realm) { public CachedRole(Long revision, RoleModel model, RealmModel realm) {
super(revision, model.getId());
composite = model.isComposite(); composite = model.isComposite();
description = model.getDescription(); description = model.getDescription();
id = model.getId();
name = model.getName(); name = model.getName();
scopeParamRequired = model.isScopeParamRequired(); scopeParamRequired = model.isScopeParamRequired();
this.realm = realm.getId(); this.realm = realm.getId();
@ -53,10 +52,6 @@ public class CachedRole implements Serializable {
} }
public String getId() {
return id;
}
public String getName() { public String getName() {
return name; return name;
} }

View file

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.keycloak.models.cache.entities; package org.keycloak.models.cache.infinispan.entities;
import org.keycloak.models.GroupModel; import org.keycloak.models.GroupModel;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;

View file

@ -1,7 +1,6 @@
package org.keycloak.models.cache.infinispan.stream; package org.keycloak.models.cache.infinispan.entities;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;
import org.keycloak.models.cache.infinispan.stream.entities.AbstractRevisioned;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;

View file

@ -1,8 +1,7 @@
package org.keycloak.models.cache.infinispan.stream; package org.keycloak.models.cache.infinispan.entities;
import org.keycloak.models.cache.infinispan.stream.entities.InRealm; import org.keycloak.models.cache.infinispan.entities.InRealm;
import java.util.List;
import java.util.Set; import java.util.Set;
/** /**

View file

@ -1,6 +1,6 @@
package org.keycloak.models.cache.infinispan.stream; package org.keycloak.models.cache.infinispan.entities;
import org.keycloak.models.cache.infinispan.stream.entities.InRealm; import org.keycloak.models.cache.infinispan.entities.InRealm;
import java.util.Set; import java.util.Set;

View file

@ -1,6 +1,6 @@
package org.keycloak.models.cache.infinispan.stream; package org.keycloak.models.cache.infinispan.entities;
import org.keycloak.models.cache.infinispan.stream.entities.InRealm; import org.keycloak.models.cache.infinispan.entities.InRealm;
import java.util.Set; import java.util.Set;

View file

@ -1,4 +1,4 @@
package org.keycloak.models.cache.infinispan.stream.entities; package org.keycloak.models.cache.infinispan.entities;
/** /**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>

View file

@ -1,4 +1,4 @@
package org.keycloak.models.cache.infinispan.stream.entities; package org.keycloak.models.cache.infinispan.entities;
/** /**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>

View file

@ -1,6 +1,4 @@
package org.keycloak.models.cache.infinispan.stream; package org.keycloak.models.cache.infinispan.entities;
import org.keycloak.models.cache.infinispan.stream.entities.AbstractRevisioned;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;

View file

@ -1,6 +1,4 @@
package org.keycloak.models.cache.infinispan.stream; package org.keycloak.models.cache.infinispan.entities;
import org.keycloak.models.cache.infinispan.stream.entities.InRealm;
import java.util.Set; import java.util.Set;

View file

@ -1,4 +1,4 @@
package org.keycloak.models.cache.infinispan.stream.entities; package org.keycloak.models.cache.infinispan.entities;
/** /**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>

View file

@ -1,6 +1,6 @@
package org.keycloak.models.cache.infinispan.stream; package org.keycloak.models.cache.infinispan.entities;
import org.keycloak.models.cache.infinispan.stream.entities.InRealm; import org.keycloak.models.cache.infinispan.entities.InRealm;
import java.util.Set; import java.util.Set;

View file

@ -1,6 +1,8 @@
package org.keycloak.models.cache.infinispan.stream; package org.keycloak.models.cache.infinispan.stream;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.keycloak.models.cache.infinispan.entities.ClientQuery;
import org.keycloak.models.cache.infinispan.entities.Revisioned;
import java.io.Serializable; import java.io.Serializable;
import java.util.Map; import java.util.Map;
@ -10,7 +12,7 @@ import java.util.function.Predicate;
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $ * @version $Revision: 1 $
*/ */
public class ClientQueryPredicate implements Predicate<Map.Entry<String, Object>>, Serializable { public class ClientQueryPredicate implements Predicate<Map.Entry<String, Revisioned>>, Serializable {
protected static final Logger logger = Logger.getLogger(ClientQueryPredicate.class); protected static final Logger logger = Logger.getLogger(ClientQueryPredicate.class);
private String client; private String client;
private String inRealm; private String inRealm;
@ -34,7 +36,7 @@ public class ClientQueryPredicate implements Predicate<Map.Entry<String, Object>
@Override @Override
public boolean test(Map.Entry<String, Object> entry) { public boolean test(Map.Entry<String, Revisioned> entry) {
Object value = entry.getValue(); Object value = entry.getValue();
if (value == null) return false; if (value == null) return false;
if (!(value instanceof ClientQuery)) return false; if (!(value instanceof ClientQuery)) return false;

View file

@ -1,5 +1,8 @@
package org.keycloak.models.cache.infinispan.stream; package org.keycloak.models.cache.infinispan.stream;
import org.keycloak.models.cache.infinispan.entities.ClientTemplateQuery;
import org.keycloak.models.cache.infinispan.entities.Revisioned;
import java.io.Serializable; import java.io.Serializable;
import java.util.Map; import java.util.Map;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -8,7 +11,7 @@ import java.util.function.Predicate;
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $ * @version $Revision: 1 $
*/ */
public class ClientTemplateQueryPredicate implements Predicate<Map.Entry<String, Object>>, Serializable { public class ClientTemplateQueryPredicate implements Predicate<Map.Entry<String, Revisioned>>, Serializable {
private String template; private String template;
public static ClientTemplateQueryPredicate create() { public static ClientTemplateQueryPredicate create() {
@ -25,7 +28,7 @@ public class ClientTemplateQueryPredicate implements Predicate<Map.Entry<String,
@Override @Override
public boolean test(Map.Entry<String, Object> entry) { public boolean test(Map.Entry<String, Revisioned> entry) {
Object value = entry.getValue(); Object value = entry.getValue();
if (value == null) return false; if (value == null) return false;
if (!(value instanceof ClientTemplateQuery)) return false; if (!(value instanceof ClientTemplateQuery)) return false;

View file

@ -1,5 +1,8 @@
package org.keycloak.models.cache.infinispan.stream; package org.keycloak.models.cache.infinispan.stream;
import org.keycloak.models.cache.infinispan.entities.GroupQuery;
import org.keycloak.models.cache.infinispan.entities.Revisioned;
import java.io.Serializable; import java.io.Serializable;
import java.util.Map; import java.util.Map;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -8,7 +11,7 @@ import java.util.function.Predicate;
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $ * @version $Revision: 1 $
*/ */
public class GroupQueryPredicate implements Predicate<Map.Entry<String, Object>>, Serializable { public class GroupQueryPredicate implements Predicate<Map.Entry<String, Revisioned>>, Serializable {
private String group; private String group;
public static GroupQueryPredicate create() { public static GroupQueryPredicate create() {
@ -25,7 +28,7 @@ public class GroupQueryPredicate implements Predicate<Map.Entry<String, Object>>
@Override @Override
public boolean test(Map.Entry<String, Object> entry) { public boolean test(Map.Entry<String, Revisioned> entry) {
Object value = entry.getValue(); Object value = entry.getValue();
if (value == null) return false; if (value == null) return false;
if (!(value instanceof GroupQuery)) return false; if (!(value instanceof GroupQuery)) return false;

View file

@ -1,7 +1,8 @@
package org.keycloak.models.cache.infinispan.stream; package org.keycloak.models.cache.infinispan.stream;
import org.keycloak.models.cache.entities.CachedGroup; import org.keycloak.models.cache.infinispan.entities.CachedGroup;
import org.keycloak.models.cache.entities.CachedRole; import org.keycloak.models.cache.infinispan.entities.CachedRole;
import org.keycloak.models.cache.infinispan.entities.Revisioned;
import java.io.Serializable; import java.io.Serializable;
import java.util.Map; import java.util.Map;
@ -11,7 +12,7 @@ import java.util.function.Predicate;
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $ * @version $Revision: 1 $
*/ */
public class HasRolePredicate implements Predicate<Map.Entry<String, Object>>, Serializable { public class HasRolePredicate implements Predicate<Map.Entry<String, Revisioned>>, Serializable {
private String role; private String role;
public static HasRolePredicate create() { public static HasRolePredicate create() {
@ -24,7 +25,7 @@ public class HasRolePredicate implements Predicate<Map.Entry<String, Object>>, S
} }
@Override @Override
public boolean test(Map.Entry<String, Object> entry) { public boolean test(Map.Entry<String, Revisioned> entry) {
Object value = entry.getValue(); Object value = entry.getValue();
if (value == null) return false; if (value == null) return false;
if (value instanceof CachedRole) { if (value instanceof CachedRole) {

View file

@ -1,7 +1,7 @@
package org.keycloak.models.cache.infinispan.stream; package org.keycloak.models.cache.infinispan.stream;
import org.keycloak.models.cache.infinispan.stream.entities.InClient; import org.keycloak.models.cache.infinispan.entities.InClient;
import org.keycloak.models.cache.infinispan.stream.entities.InRealm; import org.keycloak.models.cache.infinispan.entities.Revisioned;
import java.io.Serializable; import java.io.Serializable;
import java.util.Map; import java.util.Map;
@ -11,7 +11,7 @@ import java.util.function.Predicate;
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $ * @version $Revision: 1 $
*/ */
public class InClientPredicate implements Predicate<Map.Entry<String, Object>>, Serializable { public class InClientPredicate implements Predicate<Map.Entry<String, Revisioned>>, Serializable {
private String clientId; private String clientId;
public static InClientPredicate create() { public static InClientPredicate create() {
@ -24,7 +24,7 @@ public class InClientPredicate implements Predicate<Map.Entry<String, Object>>,
} }
@Override @Override
public boolean test(Map.Entry<String, Object> entry) { public boolean test(Map.Entry<String, Revisioned> entry) {
Object value = entry.getValue(); Object value = entry.getValue();
if (value == null) return false; if (value == null) return false;
if (!(value instanceof InClient)) return false; if (!(value instanceof InClient)) return false;

View file

@ -1,6 +1,7 @@
package org.keycloak.models.cache.infinispan.stream; package org.keycloak.models.cache.infinispan.stream;
import org.keycloak.models.cache.infinispan.stream.entities.InRealm; import org.keycloak.models.cache.infinispan.entities.InRealm;
import org.keycloak.models.cache.infinispan.entities.Revisioned;
import java.io.Serializable; import java.io.Serializable;
import java.util.Map; import java.util.Map;
@ -10,7 +11,7 @@ import java.util.function.Predicate;
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $ * @version $Revision: 1 $
*/ */
public class InRealmPredicate implements Predicate<Map.Entry<String, Object>>, Serializable { public class InRealmPredicate implements Predicate<Map.Entry<String, Revisioned>>, Serializable {
private String realm; private String realm;
public static InRealmPredicate create() { public static InRealmPredicate create() {
@ -23,7 +24,7 @@ public class InRealmPredicate implements Predicate<Map.Entry<String, Object>>, S
} }
@Override @Override
public boolean test(Map.Entry<String, Object> entry) { public boolean test(Map.Entry<String, Revisioned> entry) {
Object value = entry.getValue(); Object value = entry.getValue();
if (value == null) return false; if (value == null) return false;
if (!(value instanceof InRealm)) return false; if (!(value instanceof InRealm)) return false;

View file

@ -1,5 +1,8 @@
package org.keycloak.models.cache.infinispan.stream; package org.keycloak.models.cache.infinispan.stream;
import org.keycloak.models.cache.infinispan.entities.RealmQuery;
import org.keycloak.models.cache.infinispan.entities.Revisioned;
import java.io.Serializable; import java.io.Serializable;
import java.util.Map; import java.util.Map;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -8,7 +11,7 @@ import java.util.function.Predicate;
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $ * @version $Revision: 1 $
*/ */
public class RealmQueryPredicate implements Predicate<Map.Entry<String, Object>>, Serializable { public class RealmQueryPredicate implements Predicate<Map.Entry<String, Revisioned>>, Serializable {
private String realm; private String realm;
public static RealmQueryPredicate create() { public static RealmQueryPredicate create() {
@ -25,7 +28,7 @@ public class RealmQueryPredicate implements Predicate<Map.Entry<String, Object>>
@Override @Override
public boolean test(Map.Entry<String, Object> entry) { public boolean test(Map.Entry<String, Revisioned> entry) {
Object value = entry.getValue(); Object value = entry.getValue();
if (value == null) return false; if (value == null) return false;
if (!(value instanceof RealmQuery)) return false; if (!(value instanceof RealmQuery)) return false;

View file

@ -1,5 +1,8 @@
package org.keycloak.models.cache.infinispan.stream; package org.keycloak.models.cache.infinispan.stream;
import org.keycloak.models.cache.infinispan.entities.Revisioned;
import org.keycloak.models.cache.infinispan.entities.RoleQuery;
import java.io.Serializable; import java.io.Serializable;
import java.util.Map; import java.util.Map;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -8,7 +11,7 @@ import java.util.function.Predicate;
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $ * @version $Revision: 1 $
*/ */
public class RoleQueryPredicate implements Predicate<Map.Entry<String, Object>>, Serializable { public class RoleQueryPredicate implements Predicate<Map.Entry<String, Revisioned>>, Serializable {
private String role; private String role;
public static RoleQueryPredicate create() { public static RoleQueryPredicate create() {
@ -25,7 +28,7 @@ public class RoleQueryPredicate implements Predicate<Map.Entry<String, Object>>,
@Override @Override
public boolean test(Map.Entry<String, Object> entry) { public boolean test(Map.Entry<String, Revisioned> entry) {
Object value = entry.getValue(); Object value = entry.getValue();
if (value == null) return false; if (value == null) return false;
if (!(value instanceof RoleQuery)) return false; if (!(value instanceof RoleQuery)) return false;

View file

@ -1,39 +0,0 @@
package org.keycloak.models.cache.infinispan.stream.entities;
import org.keycloak.models.ClientModel;
import org.keycloak.models.RealmModel;
import org.keycloak.models.RealmProvider;
import org.keycloak.models.RoleModel;
import org.keycloak.models.cache.RealmCache;
import org.keycloak.models.cache.entities.CachedClient;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public class RevisionedCachedClient extends CachedClient implements Revisioned, InRealm {
public RevisionedCachedClient(Long revision, RealmCache cache, RealmProvider delegate, RealmModel realm, ClientModel model) {
super(cache, delegate, realm, model);
this.revision = revision;
}
private Long revision;
@Override
public Long getRevision() {
return revision;
}
@Override
public void setRevision(Long revision) {
this.revision = revision;
}
@Override
protected void cacheRoles(RealmCache cache, RealmModel realm, ClientModel model) {
for (RoleModel role : model.getRoles()) {
roles.put(role.getName(), role.getId());
}
}
}

View file

@ -1,31 +0,0 @@
package org.keycloak.models.cache.infinispan.stream.entities;
import org.keycloak.models.RealmModel;
import org.keycloak.models.RoleModel;
import org.keycloak.models.cache.entities.CachedClientRole;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public class RevisionedCachedClientRole extends CachedClientRole implements Revisioned, InClient {
public RevisionedCachedClientRole(Long revision, String idClient, RoleModel model, RealmModel realm) {
super(idClient, model, realm);
this.revision = revision;
}
private Long revision;
@Override
public Long getRevision() {
return revision;
}
@Override
public void setRevision(Long revision) {
this.revision = revision;
}
}

View file

@ -1,33 +0,0 @@
package org.keycloak.models.cache.infinispan.stream.entities;
import org.keycloak.models.ClientTemplateModel;
import org.keycloak.models.RealmModel;
import org.keycloak.models.RealmProvider;
import org.keycloak.models.cache.RealmCache;
import org.keycloak.models.cache.entities.CachedClientTemplate;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public class RevisionedCachedClientTemplate extends CachedClientTemplate implements Revisioned, InRealm {
public RevisionedCachedClientTemplate(Long revision, RealmCache cache, RealmProvider delegate, RealmModel realm, ClientTemplateModel model) {
super(cache, delegate, realm, model);
this.revision = revision;
}
private Long revision;
@Override
public Long getRevision() {
return revision;
}
@Override
public void setRevision(Long revision) {
this.revision = revision;
}
}

View file

@ -1,30 +0,0 @@
package org.keycloak.models.cache.infinispan.stream.entities;
import org.keycloak.models.GroupModel;
import org.keycloak.models.RealmModel;
import org.keycloak.models.cache.entities.CachedGroup;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public class RevisionedCachedGroup extends CachedGroup implements Revisioned, InRealm {
public RevisionedCachedGroup(Long revision, RealmModel realm, GroupModel group) {
super(realm, group);
this.revision = revision;
}
private Long revision;
@Override
public Long getRevision() {
return revision;
}
@Override
public void setRevision(Long revision) {
this.revision = revision;
}
}

View file

@ -1,54 +0,0 @@
package org.keycloak.models.cache.infinispan.stream.entities;
import org.keycloak.models.ClientModel;
import org.keycloak.models.ClientTemplateModel;
import org.keycloak.models.RealmModel;
import org.keycloak.models.RealmProvider;
import org.keycloak.models.RoleModel;
import org.keycloak.models.cache.RealmCache;
import org.keycloak.models.cache.entities.CachedRealm;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public class RevisionedCachedRealm extends CachedRealm implements Revisioned {
public RevisionedCachedRealm(Long revision, RealmCache cache, RealmProvider delegate, RealmModel model) {
super(cache, delegate, model);
this.revision = revision;
}
private Long revision;
@Override
public Long getRevision() {
return revision;
}
@Override
public void setRevision(Long revision) {
this.revision = revision;
}
@Override
protected void cacheClientTemplates(RealmCache cache, RealmProvider delegate, RealmModel model) {
for (ClientTemplateModel template : model.getClientTemplates()) {
clientTemplates.add(template.getId());
}
}
@Override
protected void cacheClients(RealmCache cache, RealmProvider delegate, RealmModel model) {
for (ClientModel client : model.getClients()) {
clients.add(client.getId());
}
}
@Override
protected void cacheRealmRoles(RealmCache cache, RealmModel model) {
for (RoleModel role : model.getRoles()) {
realmRoles.put(role.getName(), role.getId());
}
}
}

View file

@ -1,30 +0,0 @@
package org.keycloak.models.cache.infinispan.stream.entities;
import org.keycloak.models.RealmModel;
import org.keycloak.models.RoleModel;
import org.keycloak.models.cache.entities.CachedRealmRole;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public class RevisionedCachedRealmRole extends CachedRealmRole implements Revisioned, InRealm {
public RevisionedCachedRealmRole(Long revision, RoleModel model, RealmModel realm) {
super(model, realm);
this.revision = revision;
}
private Long revision;
@Override
public Long getRevision() {
return revision;
}
@Override
public void setRevision(Long revision) {
this.revision = revision;
}
}

View file

@ -1,29 +0,0 @@
package org.keycloak.models.cache.infinispan.stream.entities;
import org.keycloak.models.RealmModel;
import org.keycloak.models.UserModel;
import org.keycloak.models.cache.entities.CachedUser;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public class RevisionedCachedUser extends CachedUser implements Revisioned, InRealm {
public RevisionedCachedUser(Long revision, RealmModel realm, UserModel user) {
super(realm, user);
this.revision = revision;
}
private Long revision;
@Override
public Long getRevision() {
return revision;
}
@Override
public void setRevision(Long revision) {
this.revision = revision;
}
}