Fix spelling error in field and classname

It's always a converter, unless electricity is involved.

Closes #10573
This commit is contained in:
Alexander Schwartz 2022-03-08 16:02:14 +01:00 committed by Bruno Oliveira da Silva
parent 7335abaf08
commit 18f391d8c4
15 changed files with 110 additions and 110 deletions

View file

@ -29,7 +29,7 @@ import org.keycloak.models.map.common.DeepCloner;
import org.keycloak.models.map.storage.hotRod.common.AbstractHotRodEntity; import org.keycloak.models.map.storage.hotRod.common.AbstractHotRodEntity;
import org.keycloak.models.map.storage.hotRod.common.HotRodEntityDelegate; import org.keycloak.models.map.storage.hotRod.common.HotRodEntityDelegate;
import org.keycloak.models.map.storage.hotRod.common.HotRodEntityDescriptor; import org.keycloak.models.map.storage.hotRod.common.HotRodEntityDescriptor;
import org.keycloak.models.map.common.StringKeyConvertor; import org.keycloak.models.map.common.StringKeyConverter;
import org.keycloak.models.map.storage.MapKeycloakTransaction; import org.keycloak.models.map.storage.MapKeycloakTransaction;
import org.keycloak.models.map.storage.MapStorage; import org.keycloak.models.map.storage.MapStorage;
import org.keycloak.models.map.storage.QueryParameters; import org.keycloak.models.map.storage.QueryParameters;
@ -39,7 +39,6 @@ import org.keycloak.models.map.storage.chm.MapFieldPredicates;
import org.keycloak.models.map.storage.chm.MapModelCriteriaBuilder; import org.keycloak.models.map.storage.chm.MapModelCriteriaBuilder;
import org.keycloak.storage.SearchableModelField; import org.keycloak.storage.SearchableModelField;
import java.util.Arrays;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Spliterators; import java.util.Spliterators;
@ -57,14 +56,14 @@ public class HotRodMapStorage<K, E extends AbstractHotRodEntity, V extends HotRo
private static final Logger LOG = Logger.getLogger(HotRodMapStorage.class); private static final Logger LOG = Logger.getLogger(HotRodMapStorage.class);
private final RemoteCache<K, E> remoteCache; private final RemoteCache<K, E> remoteCache;
private final StringKeyConvertor<K> keyConvertor; private final StringKeyConverter<K> keyConverter;
private final HotRodEntityDescriptor<E, V> storedEntityDescriptor; private final HotRodEntityDescriptor<E, V> storedEntityDescriptor;
private final Function<E, V> delegateProducer; private final Function<E, V> delegateProducer;
private final DeepCloner cloner; private final DeepCloner cloner;
public HotRodMapStorage(RemoteCache<K, E> remoteCache, StringKeyConvertor<K> keyConvertor, HotRodEntityDescriptor<E, V> storedEntityDescriptor, DeepCloner cloner) { public HotRodMapStorage(RemoteCache<K, E> remoteCache, StringKeyConverter<K> keyConverter, HotRodEntityDescriptor<E, V> storedEntityDescriptor, DeepCloner cloner) {
this.remoteCache = remoteCache; this.remoteCache = remoteCache;
this.keyConvertor = keyConvertor; this.keyConverter = keyConverter;
this.storedEntityDescriptor = storedEntityDescriptor; this.storedEntityDescriptor = storedEntityDescriptor;
this.cloner = cloner; this.cloner = cloner;
this.delegateProducer = storedEntityDescriptor.getHotRodDelegateProvider(); this.delegateProducer = storedEntityDescriptor.getHotRodDelegateProvider();
@ -72,10 +71,10 @@ public class HotRodMapStorage<K, E extends AbstractHotRodEntity, V extends HotRo
@Override @Override
public V create(V value) { public V create(V value) {
K key = keyConvertor.fromStringSafe(value.getId()); K key = keyConverter.fromStringSafe(value.getId());
if (key == null) { if (key == null) {
key = keyConvertor.yieldNewUniqueKey(); key = keyConverter.yieldNewUniqueKey();
value = cloner.from(keyConvertor.keyToString(key), value); value = cloner.from(keyConverter.keyToString(key), value);
} }
remoteCache.putIfAbsent(key, value.getHotRodEntity()); remoteCache.putIfAbsent(key, value.getHotRodEntity());
@ -86,19 +85,19 @@ public class HotRodMapStorage<K, E extends AbstractHotRodEntity, V extends HotRo
@Override @Override
public V read(String key) { public V read(String key) {
Objects.requireNonNull(key, "Key must be non-null"); Objects.requireNonNull(key, "Key must be non-null");
K k = keyConvertor.fromStringSafe(key); K k = keyConverter.fromStringSafe(key);
return delegateProducer.apply(remoteCache.get(k)); return delegateProducer.apply(remoteCache.get(k));
} }
@Override @Override
public V update(V value) { public V update(V value) {
K key = keyConvertor.fromStringSafe(value.getId()); K key = keyConverter.fromStringSafe(value.getId());
return delegateProducer.apply(remoteCache.replace(key, value.getHotRodEntity())); return delegateProducer.apply(remoteCache.replace(key, value.getHotRodEntity()));
} }
@Override @Override
public boolean delete(String key) { public boolean delete(String key) {
K k = keyConvertor.fromStringSafe(key); K k = keyConverter.fromStringSafe(key);
return remoteCache.remove(k) != null; return remoteCache.remove(k) != null;
} }
@ -193,6 +192,6 @@ public class HotRodMapStorage<K, E extends AbstractHotRodEntity, V extends HotRo
@Override @Override
public MapKeycloakTransaction<V, M> createTransaction(KeycloakSession session) { public MapKeycloakTransaction<V, M> createTransaction(KeycloakSession session) {
Map<SearchableModelField<? super M>, MapModelCriteriaBuilder.UpdatePredicatesFunc<K, V, M>> fieldPredicates = MapFieldPredicates.getPredicates((Class<M>) storedEntityDescriptor.getModelTypeClass()); Map<SearchableModelField<? super M>, MapModelCriteriaBuilder.UpdatePredicatesFunc<K, V, M>> fieldPredicates = MapFieldPredicates.getPredicates((Class<M>) storedEntityDescriptor.getModelTypeClass());
return new ConcurrentHashMapKeycloakTransaction<>(this, keyConvertor, cloner, fieldPredicates); return new ConcurrentHashMapKeycloakTransaction<>(this, keyConverter, cloner, fieldPredicates);
} }
} }

View file

@ -22,7 +22,7 @@ import org.keycloak.models.map.common.DeepCloner;
import org.keycloak.models.map.storage.hotRod.common.AbstractHotRodEntity; import org.keycloak.models.map.storage.hotRod.common.AbstractHotRodEntity;
import org.keycloak.models.map.storage.hotRod.common.HotRodEntityDelegate; import org.keycloak.models.map.storage.hotRod.common.HotRodEntityDelegate;
import org.keycloak.models.map.storage.hotRod.common.HotRodEntityDescriptor; import org.keycloak.models.map.storage.hotRod.common.HotRodEntityDescriptor;
import org.keycloak.models.map.common.StringKeyConvertor; import org.keycloak.models.map.common.StringKeyConverter;
import org.keycloak.models.map.storage.hotRod.connections.HotRodConnectionProvider; import org.keycloak.models.map.storage.hotRod.connections.HotRodConnectionProvider;
import org.keycloak.models.map.storage.MapStorage; import org.keycloak.models.map.storage.MapStorage;
import org.keycloak.models.map.storage.MapStorageProvider; import org.keycloak.models.map.storage.MapStorageProvider;
@ -49,7 +49,7 @@ public class HotRodMapStorageProvider implements MapStorageProvider {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <E extends AbstractHotRodEntity, V extends HotRodEntityDelegate<E> & AbstractEntity, M> HotRodMapStorage<String, E, V, M> getHotRodStorage(Class<M> modelType, MapStorageProviderFactory.Flag... flags) { public <E extends AbstractHotRodEntity, V extends HotRodEntityDelegate<E> & AbstractEntity, M> HotRodMapStorage<String, E, V, M> getHotRodStorage(Class<M> modelType, MapStorageProviderFactory.Flag... flags) {
HotRodEntityDescriptor<E, V> entityDescriptor = (HotRodEntityDescriptor<E, V>) factory.getEntityDescriptor(modelType); HotRodEntityDescriptor<E, V> entityDescriptor = (HotRodEntityDescriptor<E, V>) factory.getEntityDescriptor(modelType);
return new HotRodMapStorage<>(connectionProvider.getRemoteCache(entityDescriptor.getCacheName()), StringKeyConvertor.StringKey.INSTANCE, entityDescriptor, cloner); return new HotRodMapStorage<>(connectionProvider.getRemoteCache(entityDescriptor.getCacheName()), StringKeyConverter.StringKey.INSTANCE, entityDescriptor, cloner);
} }
@Override @Override

View file

@ -32,8 +32,8 @@ import javax.persistence.criteria.Selection;
import org.keycloak.connections.jpa.JpaKeycloakTransaction; import org.keycloak.connections.jpa.JpaKeycloakTransaction;
import static org.keycloak.models.jpa.PaginationUtils.paginateQuery; import static org.keycloak.models.jpa.PaginationUtils.paginateQuery;
import org.keycloak.models.map.common.AbstractEntity; import org.keycloak.models.map.common.AbstractEntity;
import org.keycloak.models.map.common.StringKeyConvertor; import org.keycloak.models.map.common.StringKeyConverter;
import org.keycloak.models.map.common.StringKeyConvertor.UUIDKey; import org.keycloak.models.map.common.StringKeyConverter.UUIDKey;
import org.keycloak.models.map.storage.MapKeycloakTransaction; import org.keycloak.models.map.storage.MapKeycloakTransaction;
import org.keycloak.models.map.storage.QueryParameters; import org.keycloak.models.map.storage.QueryParameters;
import static org.keycloak.models.map.storage.jpa.JpaMapStorageProviderFactory.CLONER; import static org.keycloak.models.map.storage.jpa.JpaMapStorageProviderFactory.CLONER;
@ -60,7 +60,7 @@ public abstract class JpaMapKeycloakTransaction<RE extends JpaRootEntity, E exte
JpaRootEntity jpaEntity = entityType.cast(CLONER.from(mapEntity)); JpaRootEntity jpaEntity = entityType.cast(CLONER.from(mapEntity));
CLONER.from(mapEntity); CLONER.from(mapEntity);
if (mapEntity.getId() == null) { if (mapEntity.getId() == null) {
jpaEntity.setId(StringKeyConvertor.UUIDKey.INSTANCE.yieldNewUniqueKey().toString()); jpaEntity.setId(StringKeyConverter.UUIDKey.INSTANCE.yieldNewUniqueKey().toString());
} }
setEntityVersion(jpaEntity); setEntityVersion(jpaEntity);
em.persist(jpaEntity); em.persist(jpaEntity);
@ -71,7 +71,7 @@ public abstract class JpaMapKeycloakTransaction<RE extends JpaRootEntity, E exte
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public E read(String key) { public E read(String key) {
if (key == null) return null; if (key == null) return null;
UUID uuid = StringKeyConvertor.UUIDKey.INSTANCE.fromStringSafe(key); UUID uuid = StringKeyConverter.UUIDKey.INSTANCE.fromStringSafe(key);
if (uuid == null) return null; if (uuid == null) return null;
return (E) em.find(entityType, uuid); return (E) em.find(entityType, uuid);
} }

View file

@ -30,7 +30,7 @@ import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import org.keycloak.models.GroupModel; import org.keycloak.models.GroupModel;
import org.keycloak.models.map.common.StringKeyConvertor; import org.keycloak.models.map.common.StringKeyConverter;
import org.keycloak.models.map.storage.CriterionNotSupportedException; import org.keycloak.models.map.storage.CriterionNotSupportedException;
import org.keycloak.models.map.storage.jpa.group.entity.JpaGroupEntity; import org.keycloak.models.map.storage.jpa.group.entity.JpaGroupEntity;
import org.keycloak.models.map.storage.jpa.JpaModelCriteriaBuilder; import org.keycloak.models.map.storage.jpa.JpaModelCriteriaBuilder;
@ -114,7 +114,7 @@ public class JpaGroupModelCriteriaBuilder extends JpaModelCriteriaBuilder<JpaGro
CriteriaBuilder.In<UUID> in = cb.in(root.get("id")); CriteriaBuilder.In<UUID> in = cb.in(root.get("id"));
for (Object id : collectionValues) { for (Object id : collectionValues) {
try { try {
in.value(StringKeyConvertor.UUIDKey.INSTANCE.fromString(Objects.toString(id, null))); in.value(StringKeyConverter.UUIDKey.INSTANCE.fromString(Objects.toString(id, null)));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
throw new CriterionNotSupportedException(modelField, op, id + " id is not in uuid format.", e); throw new CriterionNotSupportedException(modelField, op, id + " id is not in uuid format.", e);
} }

View file

@ -32,7 +32,7 @@ import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import org.keycloak.models.RoleModel; import org.keycloak.models.RoleModel;
import org.keycloak.models.RoleModel.SearchableFields; import org.keycloak.models.RoleModel.SearchableFields;
import org.keycloak.models.map.common.StringKeyConvertor.UUIDKey; import org.keycloak.models.map.common.StringKeyConverter.UUIDKey;
import org.keycloak.models.map.storage.CriterionNotSupportedException; import org.keycloak.models.map.storage.CriterionNotSupportedException;
import org.keycloak.models.map.storage.jpa.JpaModelCriteriaBuilder; import org.keycloak.models.map.storage.jpa.JpaModelCriteriaBuilder;
import org.keycloak.models.map.storage.jpa.role.entity.JpaRoleEntity; import org.keycloak.models.map.storage.jpa.role.entity.JpaRoleEntity;

View file

@ -18,7 +18,8 @@
package org.keycloak.models.map.storage.ldap; package org.keycloak.models.map.storage.ldap;
import org.keycloak.models.map.common.AbstractEntity; import org.keycloak.models.map.common.AbstractEntity;
import org.keycloak.models.map.common.StringKeyConvertor; import org.keycloak.models.map.common.StringKeyConverter;
import org.keycloak.models.map.common.StringKeyConverter;
import org.keycloak.models.map.storage.chm.MapModelCriteriaBuilder; import org.keycloak.models.map.storage.chm.MapModelCriteriaBuilder;
import org.keycloak.storage.SearchableModelField; import org.keycloak.storage.SearchableModelField;
@ -28,16 +29,16 @@ import java.util.function.Predicate;
public class MapModelCriteriaBuilderAssumingEqualForField<K, V extends AbstractEntity, M> extends MapModelCriteriaBuilder<K, V, M> { public class MapModelCriteriaBuilderAssumingEqualForField<K, V extends AbstractEntity, M> extends MapModelCriteriaBuilder<K, V, M> {
private final Map<SearchableModelField<? super M>, UpdatePredicatesFunc<K, V, M>> fieldPredicates; private final Map<SearchableModelField<? super M>, UpdatePredicatesFunc<K, V, M>> fieldPredicates;
private final StringKeyConvertor<K> keyConvertor; private final StringKeyConverter<K> keyConverter;
private final SearchableModelField<? super M> modelFieldThatShouldCompareToTrueForEqual; private final SearchableModelField<? super M> modelFieldThatShouldCompareToTrueForEqual;
public MapModelCriteriaBuilderAssumingEqualForField(StringKeyConvertor<K> keyConvertor, Map<SearchableModelField<? super M>, UpdatePredicatesFunc<K, V, M>> fieldPredicates, SearchableModelField<? super M> modelFieldThatShouldCompareToTrueForEqual) { public MapModelCriteriaBuilderAssumingEqualForField(StringKeyConverter<K> keyConverter, Map<SearchableModelField<? super M>, UpdatePredicatesFunc<K, V, M>> fieldPredicates, SearchableModelField<? super M> modelFieldThatShouldCompareToTrueForEqual) {
this(keyConvertor, fieldPredicates, ALWAYS_TRUE, ALWAYS_TRUE, modelFieldThatShouldCompareToTrueForEqual); this(keyConverter, fieldPredicates, ALWAYS_TRUE, ALWAYS_TRUE, modelFieldThatShouldCompareToTrueForEqual);
} }
protected MapModelCriteriaBuilderAssumingEqualForField(StringKeyConvertor<K> keyConvertor, Map<SearchableModelField<? super M>, UpdatePredicatesFunc<K, V, M>> fieldPredicates, Predicate<? super K> indexReadFilter, Predicate<? super V> sequentialReadFilter, SearchableModelField<? super M> modelFieldThatShouldCompareToTrueForEqual) { protected MapModelCriteriaBuilderAssumingEqualForField(StringKeyConverter<K> keyConverter, Map<SearchableModelField<? super M>, UpdatePredicatesFunc<K, V, M>> fieldPredicates, Predicate<? super K> indexReadFilter, Predicate<? super V> sequentialReadFilter, SearchableModelField<? super M> modelFieldThatShouldCompareToTrueForEqual) {
super(keyConvertor, fieldPredicates, indexReadFilter, sequentialReadFilter); super(keyConverter, fieldPredicates, indexReadFilter, sequentialReadFilter);
this.keyConvertor = keyConvertor; this.keyConverter = keyConverter;
this.modelFieldThatShouldCompareToTrueForEqual = modelFieldThatShouldCompareToTrueForEqual; this.modelFieldThatShouldCompareToTrueForEqual = modelFieldThatShouldCompareToTrueForEqual;
this.fieldPredicates = fieldPredicates; this.fieldPredicates = fieldPredicates;
} }
@ -46,7 +47,7 @@ public class MapModelCriteriaBuilderAssumingEqualForField<K, V extends AbstractE
public MapModelCriteriaBuilder<K, V, M> compare(SearchableModelField<? super M> modelField, Operator op, Object... values) { public MapModelCriteriaBuilder<K, V, M> compare(SearchableModelField<? super M> modelField, Operator op, Object... values) {
if (modelField == modelFieldThatShouldCompareToTrueForEqual && op == Operator.EQ) { if (modelField == modelFieldThatShouldCompareToTrueForEqual && op == Operator.EQ) {
return instantiateNewInstance( return instantiateNewInstance(
keyConvertor, keyConverter,
fieldPredicates, fieldPredicates,
ALWAYS_TRUE, ALWAYS_TRUE,
ALWAYS_TRUE); ALWAYS_TRUE);
@ -55,7 +56,7 @@ public class MapModelCriteriaBuilderAssumingEqualForField<K, V extends AbstractE
} }
@Override @Override
protected MapModelCriteriaBuilder<K, V, M> instantiateNewInstance(StringKeyConvertor<K> keyConvertor, Map<SearchableModelField<? super M>, UpdatePredicatesFunc<K, V, M>> fieldPredicates, Predicate<? super K> indexReadFilter, Predicate<? super V> sequentialReadFilter) { protected MapModelCriteriaBuilder<K, V, M> instantiateNewInstance(StringKeyConverter<K> keyConverter, Map<SearchableModelField<? super M>, UpdatePredicatesFunc<K, V, M>> fieldPredicates, Predicate<? super K> indexReadFilter, Predicate<? super V> sequentialReadFilter) {
return new MapModelCriteriaBuilderAssumingEqualForField<>(keyConvertor, fieldPredicates, indexReadFilter, sequentialReadFilter, modelFieldThatShouldCompareToTrueForEqual); return new MapModelCriteriaBuilderAssumingEqualForField<>(keyConverter, fieldPredicates, indexReadFilter, sequentialReadFilter, modelFieldThatShouldCompareToTrueForEqual);
} }
} }

View file

@ -22,7 +22,7 @@ import org.keycloak.models.ModelException;
import org.keycloak.models.RoleModel; import org.keycloak.models.RoleModel;
import org.keycloak.models.map.common.DeepCloner; import org.keycloak.models.map.common.DeepCloner;
import org.keycloak.models.map.common.StreamUtils; import org.keycloak.models.map.common.StreamUtils;
import org.keycloak.models.map.common.StringKeyConvertor; import org.keycloak.models.map.common.StringKeyConverter;
import org.keycloak.models.map.role.MapRoleEntity; import org.keycloak.models.map.role.MapRoleEntity;
import org.keycloak.models.map.storage.ModelCriteriaBuilder; import org.keycloak.models.map.storage.ModelCriteriaBuilder;
@ -56,7 +56,7 @@ import java.util.stream.Stream;
public class LdapRoleMapKeycloakTransaction extends LdapMapKeycloakTransaction<LdapMapRoleEntityFieldDelegate, MapRoleEntity, RoleModel> { public class LdapRoleMapKeycloakTransaction extends LdapMapKeycloakTransaction<LdapMapRoleEntityFieldDelegate, MapRoleEntity, RoleModel> {
private final KeycloakSession session; private final KeycloakSession session;
private final StringKeyConvertor<String> keyConverter = new StringKeyConvertor.StringKey(); private final StringKeyConverter<String> keyConverter = new StringKeyConverter.StringKey();
private final Set<String> deletedKeys = new HashSet<>(); private final Set<String> deletedKeys = new HashSet<>();
private final LdapMapRoleMapperConfig roleMapperConfig; private final LdapMapRoleMapperConfig roleMapperConfig;
private final LdapMapConfig ldapMapConfig; private final LdapMapConfig ldapMapConfig;

View file

@ -24,7 +24,7 @@ import java.util.UUID;
* *
* @author hmlnarik * @author hmlnarik
*/ */
public interface StringKeyConvertor<K> { public interface StringKeyConverter<K> {
/** /**
* Returns String representation of the key from native representation * Returns String representation of the key from native representation
@ -37,7 +37,7 @@ public interface StringKeyConvertor<K> {
/** /**
* Returns a new unique primary key for the storage that * Returns a new unique primary key for the storage that
* this {@code StringKeyConvertor} belongs to. The uniqueness * this {@link StringKeyConverter} belongs to. The uniqueness
* needs to be guaranteed by e.g. using database sequences or * needs to be guaranteed by e.g. using database sequences or
* using a random value that is proved sufficiently improbable * using a random value that is proved sufficiently improbable
* to be repeated. * to be repeated.
@ -70,7 +70,7 @@ public interface StringKeyConvertor<K> {
} }
} }
public static class UUIDKey implements StringKeyConvertor<UUID> { class UUIDKey implements StringKeyConverter<UUID> {
public static final UUIDKey INSTANCE = new UUIDKey(); public static final UUIDKey INSTANCE = new UUIDKey();
@ -85,7 +85,7 @@ public interface StringKeyConvertor<K> {
} }
} }
public static class StringKey implements StringKeyConvertor<String> { class StringKey implements StringKeyConverter<String> {
public static final StringKey INSTANCE = new StringKey(); public static final StringKey INSTANCE = new StringKey();
@ -100,7 +100,7 @@ public interface StringKeyConvertor<K> {
} }
} }
public static class ULongKey implements StringKeyConvertor<Long> { class ULongKey implements StringKeyConverter<Long> {
public static final ULongKey INSTANCE = new ULongKey(); public static final ULongKey INSTANCE = new ULongKey();

View file

@ -16,7 +16,7 @@
*/ */
package org.keycloak.models.map.storage.chm; package org.keycloak.models.map.storage.chm;
import org.keycloak.models.map.common.StringKeyConvertor; import org.keycloak.models.map.common.StringKeyConverter;
import org.keycloak.models.map.common.AbstractEntity; import org.keycloak.models.map.common.AbstractEntity;
import org.keycloak.models.map.common.DeepCloner; import org.keycloak.models.map.common.DeepCloner;
import org.keycloak.models.map.common.UpdatableEntity; import org.keycloak.models.map.common.UpdatableEntity;
@ -44,7 +44,7 @@ public class ConcurrentHashMapKeycloakTransaction<K, V extends AbstractEntity &
protected boolean rollback; protected boolean rollback;
protected final Map<String, MapTaskWithValue> tasks = new LinkedHashMap<>(); protected final Map<String, MapTaskWithValue> tasks = new LinkedHashMap<>();
protected final ConcurrentHashMapCrudOperations<V, M> map; protected final ConcurrentHashMapCrudOperations<V, M> map;
protected final StringKeyConvertor<K> keyConvertor; protected final StringKeyConverter<K> keyConverter;
protected final DeepCloner cloner; protected final DeepCloner cloner;
protected final Map<SearchableModelField<? super M>, UpdatePredicatesFunc<K, V, M>> fieldPredicates; protected final Map<SearchableModelField<? super M>, UpdatePredicatesFunc<K, V, M>> fieldPredicates;
@ -52,9 +52,9 @@ public class ConcurrentHashMapKeycloakTransaction<K, V extends AbstractEntity &
CREATE, UPDATE, DELETE, CREATE, UPDATE, DELETE,
} }
public ConcurrentHashMapKeycloakTransaction(ConcurrentHashMapCrudOperations<V, M> map, StringKeyConvertor<K> keyConvertor, DeepCloner cloner, Map<SearchableModelField<? super M>, UpdatePredicatesFunc<K, V, M>> fieldPredicates) { public ConcurrentHashMapKeycloakTransaction(ConcurrentHashMapCrudOperations<V, M> map, StringKeyConverter<K> keyConverter, DeepCloner cloner, Map<SearchableModelField<? super M>, UpdatePredicatesFunc<K, V, M>> fieldPredicates) {
this.map = map; this.map = map;
this.keyConvertor = keyConvertor; this.keyConverter = keyConverter;
this.cloner = cloner; this.cloner = cloner;
this.fieldPredicates = fieldPredicates; this.fieldPredicates = fieldPredicates;
} }
@ -99,7 +99,7 @@ public class ConcurrentHashMapKeycloakTransaction<K, V extends AbstractEntity &
} }
private MapModelCriteriaBuilder<K, V, M> createCriteriaBuilder() { private MapModelCriteriaBuilder<K, V, M> createCriteriaBuilder() {
return new MapModelCriteriaBuilder<K, V, M>(keyConvertor, fieldPredicates); return new MapModelCriteriaBuilder<K, V, M>(keyConverter, fieldPredicates);
} }
/** /**
@ -220,8 +220,8 @@ public class ConcurrentHashMapKeycloakTransaction<K, V extends AbstractEntity &
public V create(V value) { public V create(V value) {
String key = value.getId(); String key = value.getId();
if (key == null) { if (key == null) {
K newKey = keyConvertor.yieldNewUniqueKey(); K newKey = keyConverter.yieldNewUniqueKey();
key = keyConvertor.keyToString(newKey); key = keyConverter.keyToString(newKey);
value = cloner.from(key, value); value = cloner.from(key, value);
} else { } else {
value = cloner.from(value); value = cloner.from(value);
@ -257,7 +257,7 @@ public class ConcurrentHashMapKeycloakTransaction<K, V extends AbstractEntity &
public long delete(QueryParameters<M> queryParameters) { public long delete(QueryParameters<M> queryParameters) {
log.tracef("Adding operation DELETE_BULK"); log.tracef("Adding operation DELETE_BULK");
K artificialKey = keyConvertor.yieldNewUniqueKey(); K artificialKey = keyConverter.yieldNewUniqueKey();
// Remove all tasks that create / update / delete objects deleted by the bulk removal. // Remove all tasks that create / update / delete objects deleted by the bulk removal.
final BulkDeleteOperation bdo = new BulkDeleteOperation(queryParameters); final BulkDeleteOperation bdo = new BulkDeleteOperation(queryParameters);
@ -272,14 +272,14 @@ public class ConcurrentHashMapKeycloakTransaction<K, V extends AbstractEntity &
} }
} }
tasks.put(keyConvertor.keyToString(artificialKey), bdo); tasks.put(keyConverter.keyToString(artificialKey), bdo);
return res + bdo.getCount(); return res + bdo.getCount();
} }
private Stream<V> createdValuesStream(Predicate<? super K> keyFilter, Predicate<? super V> entityFilter) { private Stream<V> createdValuesStream(Predicate<? super K> keyFilter, Predicate<? super V> entityFilter) {
return this.tasks.entrySet().stream() return this.tasks.entrySet().stream()
.filter(me -> keyFilter.test(keyConvertor.fromStringSafe(me.getKey()))) .filter(me -> keyFilter.test(keyConverter.fromStringSafe(me.getKey())))
.map(Map.Entry::getValue) .map(Map.Entry::getValue)
.filter(v -> v.containsCreate() && ! v.isReplace()) .filter(v -> v.containsCreate() && ! v.isReplace())
.map(MapTaskWithValue::getValue) .map(MapTaskWithValue::getValue)
@ -411,7 +411,7 @@ public class ConcurrentHashMapKeycloakTransaction<K, V extends AbstractEntity &
Predicate<? super V> entityFilter = mmcb.getEntityFilter(); Predicate<? super V> entityFilter = mmcb.getEntityFilter();
Predicate<? super K> keyFilter = mmcb.getKeyFilter(); Predicate<? super K> keyFilter = mmcb.getKeyFilter();
return v -> v == null || ! (keyFilter.test(keyConvertor.fromStringSafe(v.getId())) && entityFilter.test(v)); return v -> v == null || ! (keyFilter.test(keyConverter.fromStringSafe(v.getId())) && entityFilter.test(v));
} }
@Override @Override

View file

@ -16,7 +16,7 @@
*/ */
package org.keycloak.models.map.storage.chm; package org.keycloak.models.map.storage.chm;
import org.keycloak.models.map.common.StringKeyConvertor; import org.keycloak.models.map.common.StringKeyConverter;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.map.storage.MapKeycloakTransaction; import org.keycloak.models.map.storage.MapKeycloakTransaction;
import org.keycloak.models.map.common.AbstractEntity; import org.keycloak.models.map.common.AbstractEntity;
@ -54,22 +54,22 @@ public class ConcurrentHashMapStorage<K, V extends AbstractEntity & UpdatableEnt
protected final ConcurrentMap<K, V> store = new ConcurrentHashMap<>(); protected final ConcurrentMap<K, V> store = new ConcurrentHashMap<>();
protected final Map<SearchableModelField<? super M>, UpdatePredicatesFunc<K, V, M>> fieldPredicates; protected final Map<SearchableModelField<? super M>, UpdatePredicatesFunc<K, V, M>> fieldPredicates;
protected final StringKeyConvertor<K> keyConvertor; protected final StringKeyConverter<K> keyConverter;
protected final DeepCloner cloner; protected final DeepCloner cloner;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public ConcurrentHashMapStorage(Class<M> modelClass, StringKeyConvertor<K> keyConvertor, DeepCloner cloner) { public ConcurrentHashMapStorage(Class<M> modelClass, StringKeyConverter<K> keyConverter, DeepCloner cloner) {
this.fieldPredicates = MapFieldPredicates.getPredicates(modelClass); this.fieldPredicates = MapFieldPredicates.getPredicates(modelClass);
this.keyConvertor = keyConvertor; this.keyConverter = keyConverter;
this.cloner = cloner; this.cloner = cloner;
} }
@Override @Override
public V create(V value) { public V create(V value) {
K key = keyConvertor.fromStringSafe(value.getId()); K key = keyConverter.fromStringSafe(value.getId());
if (key == null) { if (key == null) {
key = keyConvertor.yieldNewUniqueKey(); key = keyConverter.yieldNewUniqueKey();
value = cloner.from(keyConvertor.keyToString(key), value); value = cloner.from(keyConverter.keyToString(key), value);
} }
store.putIfAbsent(key, value); store.putIfAbsent(key, value);
return value; return value;
@ -78,19 +78,19 @@ public class ConcurrentHashMapStorage<K, V extends AbstractEntity & UpdatableEnt
@Override @Override
public V read(String key) { public V read(String key) {
Objects.requireNonNull(key, "Key must be non-null"); Objects.requireNonNull(key, "Key must be non-null");
K k = keyConvertor.fromStringSafe(key); K k = keyConverter.fromStringSafe(key);
return store.get(k); return store.get(k);
} }
@Override @Override
public V update(V value) { public V update(V value) {
K key = getKeyConvertor().fromStringSafe(value.getId()); K key = getKeyConverter().fromStringSafe(value.getId());
return store.replace(key, value); return store.replace(key, value);
} }
@Override @Override
public boolean delete(String key) { public boolean delete(String key) {
K k = getKeyConvertor().fromStringSafe(key); K k = getKeyConverter().fromStringSafe(key);
return store.remove(k) != null; return store.remove(k) != null;
} }
@ -129,15 +129,15 @@ public class ConcurrentHashMapStorage<K, V extends AbstractEntity & UpdatableEnt
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public MapKeycloakTransaction<V, M> createTransaction(KeycloakSession session) { public MapKeycloakTransaction<V, M> createTransaction(KeycloakSession session) {
MapKeycloakTransaction<V, M> sessionTransaction = session.getAttribute("map-transaction-" + hashCode(), MapKeycloakTransaction.class); MapKeycloakTransaction<V, M> sessionTransaction = session.getAttribute("map-transaction-" + hashCode(), MapKeycloakTransaction.class);
return sessionTransaction == null ? new ConcurrentHashMapKeycloakTransaction<>(this, keyConvertor, cloner, fieldPredicates) : sessionTransaction; return sessionTransaction == null ? new ConcurrentHashMapKeycloakTransaction<>(this, keyConverter, cloner, fieldPredicates) : sessionTransaction;
} }
public MapModelCriteriaBuilder<K, V, M> createCriteriaBuilder() { public MapModelCriteriaBuilder<K, V, M> createCriteriaBuilder() {
return new MapModelCriteriaBuilder<>(keyConvertor, fieldPredicates); return new MapModelCriteriaBuilder<>(keyConverter, fieldPredicates);
} }
public StringKeyConvertor<K> getKeyConvertor() { public StringKeyConverter<K> getKeyConverter() {
return keyConvertor; return keyConverter;
} }
@Override @Override

View file

@ -28,7 +28,7 @@ import org.keycloak.models.map.authorization.entity.MapResourceEntityImpl;
import org.keycloak.models.map.authorization.entity.MapResourceServerEntityImpl; import org.keycloak.models.map.authorization.entity.MapResourceServerEntityImpl;
import org.keycloak.models.map.authorization.entity.MapScopeEntity; import org.keycloak.models.map.authorization.entity.MapScopeEntity;
import org.keycloak.models.map.authorization.entity.MapScopeEntityImpl; import org.keycloak.models.map.authorization.entity.MapScopeEntityImpl;
import org.keycloak.models.map.common.StringKeyConvertor; import org.keycloak.models.map.common.StringKeyConverter;
import org.keycloak.component.AmphibianProviderFactory; import org.keycloak.component.AmphibianProviderFactory;
import org.keycloak.Config.Scope; import org.keycloak.Config.Scope;
import org.keycloak.common.Profile; import org.keycloak.common.Profile;
@ -90,13 +90,13 @@ public class ConcurrentHashMapStorageProviderFactory implements AmphibianProvide
private final ConcurrentHashMap<String, ConcurrentHashMapStorage<?,?,?>> storages = new ConcurrentHashMap<>(); private final ConcurrentHashMap<String, ConcurrentHashMapStorage<?,?,?>> storages = new ConcurrentHashMap<>();
private final Map<String, StringKeyConvertor> keyConvertors = new HashMap<>(); private final Map<String, StringKeyConverter> keyConverters = new HashMap<>();
private File storageDirectory; private File storageDirectory;
private String suffix; private String suffix;
private StringKeyConvertor defaultKeyConvertor; private StringKeyConverter defaultKeyConverter;
private final static DeepCloner CLONER = new DeepCloner.Builder() private final static DeepCloner CLONER = new DeepCloner.Builder()
.genericCloner(Serialization::from) .genericCloner(Serialization::from)
@ -130,11 +130,11 @@ public class ConcurrentHashMapStorageProviderFactory implements AmphibianProvide
.constructor(MapAuthenticationSessionEntity.class, MapAuthenticationSessionEntityImpl::new) .constructor(MapAuthenticationSessionEntity.class, MapAuthenticationSessionEntityImpl::new)
.build(); .build();
private static final Map<String, StringKeyConvertor> KEY_CONVERTORS = new HashMap<>(); private static final Map<String, StringKeyConverter> KEY_CONVERTERS = new HashMap<>();
static { static {
KEY_CONVERTORS.put("uuid", StringKeyConvertor.UUIDKey.INSTANCE); KEY_CONVERTERS.put("uuid", StringKeyConverter.UUIDKey.INSTANCE);
KEY_CONVERTORS.put("string", StringKeyConvertor.StringKey.INSTANCE); KEY_CONVERTERS.put("string", StringKeyConverter.StringKey.INSTANCE);
KEY_CONVERTORS.put("ulong", StringKeyConvertor.ULongKey.INSTANCE); KEY_CONVERTERS.put("ulong", StringKeyConverter.ULongKey.INSTANCE);
} }
@Override @Override
@ -152,9 +152,9 @@ public class ConcurrentHashMapStorageProviderFactory implements AmphibianProvide
} }
final String keyType = config.get("keyType", "uuid"); final String keyType = config.get("keyType", "uuid");
defaultKeyConvertor = getKeyConvertor(keyType); defaultKeyConverter = getKeyConverter(keyType);
for (String name : getModelNames()) { for (String name : getModelNames()) {
keyConvertors.put(name, getKeyConvertor(config.get("keyType." + name, keyType))); keyConverters.put(name, getKeyConverter(config.get("keyType." + name, keyType)));
} }
final String dir = config.get("dir"); final String dir = config.get("dir");
@ -178,8 +178,8 @@ public class ConcurrentHashMapStorageProviderFactory implements AmphibianProvide
} }
} }
private StringKeyConvertor getKeyConvertor(final String keyType) throws IllegalArgumentException { private StringKeyConverter getKeyConverter(final String keyType) throws IllegalArgumentException {
StringKeyConvertor res = KEY_CONVERTORS.get(keyType); StringKeyConverter res = KEY_CONVERTERS.get(keyType);
if (res == null) { if (res == null) {
throw new IllegalArgumentException("Unknown key type: " + keyType); throw new IllegalArgumentException("Unknown key type: " + keyType);
} }
@ -216,7 +216,7 @@ public class ConcurrentHashMapStorageProviderFactory implements AmphibianProvide
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <K, V extends AbstractEntity & UpdatableEntity, M> ConcurrentHashMapStorage<K, V, M> loadMap(String mapName, private <K, V extends AbstractEntity & UpdatableEntity, M> ConcurrentHashMapStorage<K, V, M> loadMap(String mapName,
Class<M> modelType, EnumSet<Flag> flags) { Class<M> modelType, EnumSet<Flag> flags) {
final StringKeyConvertor kc = keyConvertors.getOrDefault(mapName, defaultKeyConvertor); final StringKeyConverter kc = keyConverters.getOrDefault(mapName, defaultKeyConverter);
Class<?> valueType = ModelEntityUtil.getEntityType(modelType); Class<?> valueType = ModelEntityUtil.getEntityType(modelType);
LOG.debugf("Initializing new map storage: %s", mapName); LOG.debugf("Initializing new map storage: %s", mapName);

View file

@ -16,7 +16,7 @@
*/ */
package org.keycloak.models.map.storage.chm; package org.keycloak.models.map.storage.chm;
import org.keycloak.models.map.common.StringKeyConvertor; import org.keycloak.models.map.common.StringKeyConverter;
import org.keycloak.models.map.common.AbstractEntity; import org.keycloak.models.map.common.AbstractEntity;
import org.keycloak.storage.SearchableModelField; import org.keycloak.storage.SearchableModelField;
import java.util.Map; import java.util.Map;
@ -44,14 +44,14 @@ public class MapModelCriteriaBuilder<K, V extends AbstractEntity, M> implements
private final Predicate<? super K> keyFilter; private final Predicate<? super K> keyFilter;
private final Predicate<? super V> entityFilter; private final Predicate<? super V> entityFilter;
private final Map<SearchableModelField<? super M>, UpdatePredicatesFunc<K, V, M>> fieldPredicates; private final Map<SearchableModelField<? super M>, UpdatePredicatesFunc<K, V, M>> fieldPredicates;
private final StringKeyConvertor<K> keyConvertor; private final StringKeyConverter<K> keyConverter;
public MapModelCriteriaBuilder(StringKeyConvertor<K> keyConvertor, Map<SearchableModelField<? super M>, UpdatePredicatesFunc<K, V, M>> fieldPredicates) { public MapModelCriteriaBuilder(StringKeyConverter<K> keyConverter, Map<SearchableModelField<? super M>, UpdatePredicatesFunc<K, V, M>> fieldPredicates) {
this(keyConvertor, fieldPredicates, ALWAYS_TRUE, ALWAYS_TRUE); this(keyConverter, fieldPredicates, ALWAYS_TRUE, ALWAYS_TRUE);
} }
protected MapModelCriteriaBuilder(StringKeyConvertor<K> keyConvertor, Map<SearchableModelField<? super M>, UpdatePredicatesFunc<K, V, M>> fieldPredicates, Predicate<? super K> indexReadFilter, Predicate<? super V> sequentialReadFilter) { protected MapModelCriteriaBuilder(StringKeyConverter<K> keyConverter, Map<SearchableModelField<? super M>, UpdatePredicatesFunc<K, V, M>> fieldPredicates, Predicate<? super K> indexReadFilter, Predicate<? super V> sequentialReadFilter) {
this.keyConvertor = keyConvertor; this.keyConverter = keyConverter;
this.fieldPredicates = fieldPredicates; this.fieldPredicates = fieldPredicates;
this.keyFilter = indexReadFilter; this.keyFilter = indexReadFilter;
this.entityFilter = sequentialReadFilter; this.entityFilter = sequentialReadFilter;
@ -73,7 +73,7 @@ public class MapModelCriteriaBuilder<K, V extends AbstractEntity, M> implements
public final MapModelCriteriaBuilder<K, V, M> and(MapModelCriteriaBuilder<K, V, M>... builders) { public final MapModelCriteriaBuilder<K, V, M> and(MapModelCriteriaBuilder<K, V, M>... builders) {
Predicate<? super K> resIndexFilter = Stream.of(builders).map(MapModelCriteriaBuilder.class::cast).map(MapModelCriteriaBuilder::getKeyFilter).reduce(keyFilter, Predicate::and); Predicate<? super K> resIndexFilter = Stream.of(builders).map(MapModelCriteriaBuilder.class::cast).map(MapModelCriteriaBuilder::getKeyFilter).reduce(keyFilter, Predicate::and);
Predicate<V> resEntityFilter = Stream.of(builders).map(MapModelCriteriaBuilder.class::cast).map(MapModelCriteriaBuilder::getEntityFilter).reduce(entityFilter, Predicate::and); Predicate<V> resEntityFilter = Stream.of(builders).map(MapModelCriteriaBuilder.class::cast).map(MapModelCriteriaBuilder::getEntityFilter).reduce(entityFilter, Predicate::and);
return instantiateNewInstance(keyConvertor, fieldPredicates, resIndexFilter, resEntityFilter); return instantiateNewInstance(keyConverter, fieldPredicates, resIndexFilter, resEntityFilter);
} }
@SafeVarargs @SafeVarargs
@ -83,7 +83,7 @@ public class MapModelCriteriaBuilder<K, V extends AbstractEntity, M> implements
Predicate<? super K> resIndexFilter = Stream.of(builders).map(MapModelCriteriaBuilder.class::cast).map(MapModelCriteriaBuilder::getKeyFilter).reduce(ALWAYS_FALSE, Predicate::or); Predicate<? super K> resIndexFilter = Stream.of(builders).map(MapModelCriteriaBuilder.class::cast).map(MapModelCriteriaBuilder::getKeyFilter).reduce(ALWAYS_FALSE, Predicate::or);
Predicate<V> resEntityFilter = Stream.of(builders).map(MapModelCriteriaBuilder.class::cast).map(MapModelCriteriaBuilder::getEntityFilter).reduce(ALWAYS_FALSE, Predicate::or); Predicate<V> resEntityFilter = Stream.of(builders).map(MapModelCriteriaBuilder.class::cast).map(MapModelCriteriaBuilder::getEntityFilter).reduce(ALWAYS_FALSE, Predicate::or);
return instantiateNewInstance( return instantiateNewInstance(
keyConvertor, keyConverter,
fieldPredicates, fieldPredicates,
v -> keyFilter.test(v) && resIndexFilter.test(v), v -> keyFilter.test(v) && resIndexFilter.test(v),
v -> entityFilter.test(v) && resEntityFilter.test(v) v -> entityFilter.test(v) && resEntityFilter.test(v)
@ -96,7 +96,7 @@ public class MapModelCriteriaBuilder<K, V extends AbstractEntity, M> implements
Predicate<? super V> resEntityFilter = builder.getEntityFilter() == ALWAYS_TRUE ? ALWAYS_TRUE : builder.getEntityFilter().negate(); Predicate<? super V> resEntityFilter = builder.getEntityFilter() == ALWAYS_TRUE ? ALWAYS_TRUE : builder.getEntityFilter().negate();
return instantiateNewInstance( return instantiateNewInstance(
keyConvertor, keyConverter,
fieldPredicates, fieldPredicates,
v -> keyFilter.test(v) && resIndexFilter.test(v), v -> keyFilter.test(v) && resIndexFilter.test(v),
v -> entityFilter.test(v) && resEntityFilter.test(v) v -> entityFilter.test(v) && resEntityFilter.test(v)
@ -123,7 +123,7 @@ public class MapModelCriteriaBuilder<K, V extends AbstractEntity, M> implements
case EXISTS: case EXISTS:
case NOT_EXISTS: case NOT_EXISTS:
case IN: case IN:
return instantiateNewInstance(keyConvertor, fieldPredicates, this.keyFilter.and(CriteriaOperator.predicateFor(op, convertedValues)), this.entityFilter); return instantiateNewInstance(keyConverter, fieldPredicates, this.keyFilter.and(CriteriaOperator.predicateFor(op, convertedValues)), this.entityFilter);
default: default:
throw new AssertionError("Invalid operator: " + op); throw new AssertionError("Invalid operator: " + op);
} }
@ -137,11 +137,11 @@ public class MapModelCriteriaBuilder<K, V extends AbstractEntity, M> implements
for (int i = 0; i < values.length; i ++) { for (int i = 0; i < values.length; i ++) {
Object v = values[i]; Object v = values[i];
if (v instanceof String) { if (v instanceof String) {
res[i] = keyConvertor.fromStringSafe((String) v); res[i] = keyConverter.fromStringSafe((String) v);
} else if (v instanceof Stream) { } else if (v instanceof Stream) {
res[i] = ((Stream<?>) v).map(o -> (o instanceof String) ? keyConvertor.fromStringSafe((String) o) : o); res[i] = ((Stream<?>) v).map(o -> (o instanceof String) ? keyConverter.fromStringSafe((String) o) : o);
} else if (v instanceof Collection) { } else if (v instanceof Collection) {
res[i] = ((List<?>) v).stream().map(o -> (o instanceof String) ? keyConvertor.fromStringSafe((String) o) : o).collect(Collectors.toList()); res[i] = ((List<?>) v).stream().map(o -> (o instanceof String) ? keyConverter.fromStringSafe((String) o) : o).collect(Collectors.toList());
} else if (v == null) { } else if (v == null) {
res[i] = null; res[i] = null;
} else { } else {
@ -165,7 +165,7 @@ public class MapModelCriteriaBuilder<K, V extends AbstractEntity, M> implements
final Predicate<V> p = v -> valueComparator.test(getter.apply(v)); final Predicate<V> p = v -> valueComparator.test(getter.apply(v));
resEntityFilter = p.and(entityFilter); resEntityFilter = p.and(entityFilter);
} }
return instantiateNewInstance(keyConvertor, fieldPredicates, this.keyFilter, resEntityFilter); return instantiateNewInstance(keyConverter, fieldPredicates, this.keyFilter, resEntityFilter);
} }
/** /**
@ -174,7 +174,7 @@ public class MapModelCriteriaBuilder<K, V extends AbstractEntity, M> implements
* Subclasses can override this method to instantiate a new instance of their subclass. This allows this class to * Subclasses can override this method to instantiate a new instance of their subclass. This allows this class to
* be extendable. * be extendable.
*/ */
protected MapModelCriteriaBuilder<K, V, M> instantiateNewInstance(StringKeyConvertor<K> keyConvertor, Map<SearchableModelField<? super M>, UpdatePredicatesFunc<K, V, M>> fieldPredicates, Predicate<? super K> indexReadFilter, Predicate<? super V> sequentialReadFilter) { protected MapModelCriteriaBuilder<K, V, M> instantiateNewInstance(StringKeyConverter<K> keyConverter, Map<SearchableModelField<? super M>, UpdatePredicatesFunc<K, V, M>> fieldPredicates, Predicate<? super K> indexReadFilter, Predicate<? super V> sequentialReadFilter) {
return new MapModelCriteriaBuilder<>(keyConvertor, fieldPredicates, indexReadFilter, sequentialReadFilter); return new MapModelCriteriaBuilder<>(keyConverter, fieldPredicates, indexReadFilter, sequentialReadFilter);
} }
} }

View file

@ -16,7 +16,7 @@
*/ */
package org.keycloak.models.map.storage.chm; package org.keycloak.models.map.storage.chm;
import org.keycloak.models.map.common.StringKeyConvertor; import org.keycloak.models.map.common.StringKeyConverter;
import org.keycloak.models.AuthenticatedClientSessionModel; import org.keycloak.models.AuthenticatedClientSessionModel;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.UserSessionModel; import org.keycloak.models.UserSessionModel;
@ -52,13 +52,13 @@ public class UserSessionConcurrentHashMapStorage<K> extends ConcurrentHashMapSto
private final MapKeycloakTransaction<MapAuthenticatedClientSessionEntity, AuthenticatedClientSessionModel> clientSessionTr; private final MapKeycloakTransaction<MapAuthenticatedClientSessionEntity, AuthenticatedClientSessionModel> clientSessionTr;
public Transaction(MapKeycloakTransaction<MapAuthenticatedClientSessionEntity, AuthenticatedClientSessionModel> clientSessionTr, public Transaction(MapKeycloakTransaction<MapAuthenticatedClientSessionEntity, AuthenticatedClientSessionModel> clientSessionTr,
StringKeyConvertor<K> keyConvertor, StringKeyConverter<K> keyConverter,
DeepCloner cloner, DeepCloner cloner,
Map<SearchableModelField<? super UserSessionModel>, Map<SearchableModelField<? super UserSessionModel>,
UpdatePredicatesFunc<K, UpdatePredicatesFunc<K,
MapUserSessionEntity, MapUserSessionEntity,
UserSessionModel>> fieldPredicates) { UserSessionModel>> fieldPredicates) {
super(UserSessionConcurrentHashMapStorage.this, keyConvertor, cloner, fieldPredicates); super(UserSessionConcurrentHashMapStorage.this, keyConverter, cloner, fieldPredicates);
this.clientSessionTr = clientSessionTr; this.clientSessionTr = clientSessionTr;
} }
@ -83,8 +83,8 @@ public class UserSessionConcurrentHashMapStorage<K> extends ConcurrentHashMapSto
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public UserSessionConcurrentHashMapStorage(ConcurrentHashMapStorage<K, MapAuthenticatedClientSessionEntity, AuthenticatedClientSessionModel> clientSessionStore, public UserSessionConcurrentHashMapStorage(ConcurrentHashMapStorage<K, MapAuthenticatedClientSessionEntity, AuthenticatedClientSessionModel> clientSessionStore,
StringKeyConvertor<K> keyConvertor, DeepCloner cloner) { StringKeyConverter<K> keyConverter, DeepCloner cloner) {
super(UserSessionModel.class, keyConvertor, cloner); super(UserSessionModel.class, keyConverter, cloner);
this.clientSessionStore = clientSessionStore; this.clientSessionStore = clientSessionStore;
} }
@ -92,6 +92,6 @@ public class UserSessionConcurrentHashMapStorage<K> extends ConcurrentHashMapSto
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public MapKeycloakTransaction<MapUserSessionEntity, UserSessionModel> createTransaction(KeycloakSession session) { public MapKeycloakTransaction<MapUserSessionEntity, UserSessionModel> createTransaction(KeycloakSession session) {
MapKeycloakTransaction<MapUserSessionEntity, UserSessionModel> sessionTransaction = session.getAttribute("map-transaction-" + hashCode(), MapKeycloakTransaction.class); MapKeycloakTransaction<MapUserSessionEntity, UserSessionModel> sessionTransaction = session.getAttribute("map-transaction-" + hashCode(), MapKeycloakTransaction.class);
return sessionTransaction == null ? new Transaction(clientSessionStore.createTransaction(session), clientSessionStore.getKeyConvertor(), cloner, fieldPredicates) : sessionTransaction; return sessionTransaction == null ? new Transaction(clientSessionStore.createTransaction(session), clientSessionStore.getKeyConverter(), cloner, fieldPredicates) : sessionTransaction;
} }
} }

View file

@ -124,21 +124,21 @@ public abstract class ServerResourceUpdater<T extends ServerResourceUpdater, Res
* @param <V> Type of the objects required by add/remove functions (e.g. IDs) * @param <V> Type of the objects required by add/remove functions (e.g. IDs)
* @param from Initial collection * @param from Initial collection
* @param to Target collection * @param to Target collection
* @param client2ServerConvertorGenerator Producer of the convertor. If not needed, just use {@code () -> Functions::identity}. * @param client2ServerConverterGenerator Producer of the converter. If not needed, just use {@code () -> Functions::identity}.
* This is intentionally a lazy-evaluated function variable because the conversion map often needs to be obtained from the * This is intentionally a lazy-evaluated function variable because the conversion map often needs to be obtained from the
* server which can be slow operation. This function is called only if the two collections differ. * server which can be slow operation. This function is called only if the two collections differ.
* @param add Function to add * @param add Function to add
* @param remove Function to remove * @param remove Function to remove
*/ */
public static <T, V> void updateViaAddRemove(Collection<T> from, Collection<T> to, Supplier<Function<T, V>> client2ServerConvertorGenerator, Consumer<V> add, Consumer<V> remove) { public static <T, V> void updateViaAddRemove(Collection<T> from, Collection<T> to, Supplier<Function<T, V>> client2ServerConverterGenerator, Consumer<V> add, Consumer<V> remove) {
if (Objects.equals(from, to)) { if (Objects.equals(from, to)) {
return; return;
} }
Function<T, V> client2ServerConvertor = client2ServerConvertorGenerator.get(); Function<T, V> client2ServerConverter = client2ServerConverterGenerator.get();
Set<V> current = from == null ? Collections.EMPTY_SET : from.stream().map(client2ServerConvertor).collect(Collectors.toSet()); Set<V> current = from == null ? Collections.EMPTY_SET : from.stream().map(client2ServerConverter).collect(Collectors.toSet());
Set<V> expected = to == null ? Collections.EMPTY_SET : to.stream().map(client2ServerConvertor).collect(Collectors.toSet()); Set<V> expected = to == null ? Collections.EMPTY_SET : to.stream().map(client2ServerConverter).collect(Collectors.toSet());
expected.stream() expected.stream()
.filter(role -> ! current.contains(role)) .filter(role -> ! current.contains(role))

View file

@ -29,7 +29,7 @@ import org.keycloak.models.map.client.MapClientProviderFactory;
import org.keycloak.models.map.storage.MapStorage; import org.keycloak.models.map.storage.MapStorage;
import org.keycloak.models.map.storage.MapStorageProvider; import org.keycloak.models.map.storage.MapStorageProvider;
import org.keycloak.models.map.storage.MapStorageProviderFactory; import org.keycloak.models.map.storage.MapStorageProviderFactory;
import org.keycloak.models.map.common.StringKeyConvertor; import org.keycloak.models.map.common.StringKeyConverter;
import org.keycloak.models.map.storage.chm.ConcurrentHashMapStorage; import org.keycloak.models.map.storage.chm.ConcurrentHashMapStorage;
import org.keycloak.models.map.storage.chm.ConcurrentHashMapStorageProviderFactory; import org.keycloak.models.map.storage.chm.ConcurrentHashMapStorageProviderFactory;
import org.keycloak.models.utils.KeycloakModelUtils; import org.keycloak.models.utils.KeycloakModelUtils;
@ -93,9 +93,9 @@ public class ConcurrentHashMapStorageTest extends KeycloakModelTest {
assertThat(storage1, notNullValue()); assertThat(storage1, notNullValue());
assertThat(storage2, notNullValue()); assertThat(storage2, notNullValue());
final StringKeyConvertor<K> kcMain = storageMain.getKeyConvertor(); final StringKeyConverter<K> kcMain = storageMain.getKeyConverter();
final StringKeyConvertor<K1> kc1 = storage1.getKeyConvertor(); final StringKeyConverter<K1> kc1 = storage1.getKeyConverter();
final StringKeyConvertor<K2> kc2 = storage2.getKeyConvertor(); final StringKeyConverter<K2> kc2 = storage2.getKeyConverter();
String idMain = kcMain.keyToString(kcMain.yieldNewUniqueKey()); String idMain = kcMain.keyToString(kcMain.yieldNewUniqueKey());
String id1 = kc1.keyToString(kc1.yieldNewUniqueKey()); String id1 = kc1.keyToString(kc1.yieldNewUniqueKey());
@ -155,7 +155,7 @@ public class ConcurrentHashMapStorageTest extends KeycloakModelTest {
assertClientsPersisted(component1Id, component2Id, idMain, id1, id2); assertClientsPersisted(component1Id, component2Id, idMain, id1, id2);
} }
private <K,K1> void assertClientDoesNotExist(ConcurrentHashMapStorage<K, MapClientEntity, ClientModel> storage, String id, final StringKeyConvertor<K1> kc, final StringKeyConvertor<K> kcStorage) { private <K,K1> void assertClientDoesNotExist(ConcurrentHashMapStorage<K, MapClientEntity, ClientModel> storage, String id, final StringKeyConverter<K1> kc, final StringKeyConverter<K> kcStorage) {
// Assert that the other stores do not contain the to-be-created clients (if they use compatible key format) // Assert that the other stores do not contain the to-be-created clients (if they use compatible key format)
try { try {
assertThat(storage.read(id), nullValue()); assertThat(storage.read(id), nullValue());
@ -174,9 +174,9 @@ public class ConcurrentHashMapStorageTest extends KeycloakModelTest {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ConcurrentHashMapStorage<K2, MapClientEntity, ClientModel> storage2 = (ConcurrentHashMapStorage<K2, MapClientEntity, ClientModel>) (MapStorage) session.getComponentProvider(MapStorageProvider.class, component2Id).getStorage(ClientModel.class); ConcurrentHashMapStorage<K2, MapClientEntity, ClientModel> storage2 = (ConcurrentHashMapStorage<K2, MapClientEntity, ClientModel>) (MapStorage) session.getComponentProvider(MapStorageProvider.class, component2Id).getStorage(ClientModel.class);
final StringKeyConvertor<K> kcMain = storageMain.getKeyConvertor(); final StringKeyConverter<K> kcMain = storageMain.getKeyConverter();
final StringKeyConvertor<K1> kc1 = storage1.getKeyConvertor(); final StringKeyConverter<K1> kc1 = storage1.getKeyConverter();
final StringKeyConvertor<K2> kc2 = storage2.getKeyConvertor(); final StringKeyConverter<K2> kc2 = storage2.getKeyConverter();
// Assert that the stores contain the created clients // Assert that the stores contain the created clients
assertThat(storageMain.read(idMain), notNullValue()); assertThat(storageMain.read(idMain), notNullValue());