KEYCLOAK-18414 Remove unnecessary id parameter from create operation
This commit is contained in:
parent
11b72d20e7
commit
0523dad4d5
21 changed files with 37 additions and 36 deletions
|
@ -102,7 +102,7 @@ public class MapRootAuthenticationSessionProvider<K> implements AuthenticationSe
|
|||
throw new ModelDuplicateException("Root authentication session exists: " + entity.getId());
|
||||
}
|
||||
|
||||
tx.create(entity.getId(), entity);
|
||||
tx.create(entity);
|
||||
|
||||
return entityToAdapterFunc(realm).apply(entity);
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ public class MapPermissionTicketStore<K extends Comparable<K>> implements Permis
|
|||
entity.setOwner(owner);
|
||||
entity.setResourceServerId(resourceServer.getId());
|
||||
|
||||
tx.create(entity.getId(), entity);
|
||||
tx.create(entity);
|
||||
|
||||
return entityToAdapter(entity);
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ public class MapPolicyStore<K> implements PolicyStore {
|
|||
entity.setName(representation.getName());
|
||||
entity.setResourceServerId(resourceServer.getId());
|
||||
|
||||
tx.create(uid, entity);
|
||||
tx.create(entity);
|
||||
|
||||
return entityToAdapter(entity);
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ public class MapResourceServerStore<K> implements ResourceServerStore {
|
|||
|
||||
MapResourceServerEntity<K> entity = new MapResourceServerEntity<>(resourceServerStore.getKeyConvertor().fromString(clientId));
|
||||
|
||||
tx.create(entity.getId(), entity);
|
||||
tx.create(entity);
|
||||
|
||||
return entityToAdapter(entity);
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ public class MapResourceStore<K extends Comparable<K>> implements ResourceStore
|
|||
entity.setResourceServerId(resourceServer.getId());
|
||||
entity.setOwner(owner);
|
||||
|
||||
tx.create(uid, entity);
|
||||
tx.create(entity);
|
||||
|
||||
return entityToAdapter(entity);
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ public class MapScopeStore<K> implements ScopeStore {
|
|||
entity.setName(name);
|
||||
entity.setResourceServerId(resourceServer.getId());
|
||||
|
||||
tx.create(uid, entity);
|
||||
tx.create(entity);
|
||||
|
||||
return entityToAdapter(entity);
|
||||
}
|
||||
|
|
|
@ -157,7 +157,7 @@ public class MapClientProvider<K> implements ClientProvider {
|
|||
if (tx.read(entity.getId()) != null) {
|
||||
throw new ModelDuplicateException("Client exists: " + id);
|
||||
}
|
||||
tx.create(entity.getId(), entity);
|
||||
tx.create(entity);
|
||||
final ClientModel resource = entityToAdapterFunc(realm).apply(entity);
|
||||
|
||||
// TODO: Sending an event should be extracted to store layer
|
||||
|
|
|
@ -104,7 +104,7 @@ public class MapClientScopeProvider<K> implements ClientScopeProvider {
|
|||
if (tx.read(entity.getId()) != null) {
|
||||
throw new ModelDuplicateException("Client scope exists: " + id);
|
||||
}
|
||||
tx.create(entity.getId(), entity);
|
||||
tx.create(entity);
|
||||
return entityToAdapterFunc(realm).apply(entity);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,12 +21,12 @@ import org.keycloak.common.Profile;
|
|||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.map.storage.MapStorage;
|
||||
import org.keycloak.models.map.storage.MapStorageProvider;
|
||||
import org.keycloak.models.map.storage.MapStorageProviderFactory;
|
||||
import org.keycloak.models.map.storage.MapStorageSpi;
|
||||
import org.keycloak.component.AmphibianProviderFactory;
|
||||
import org.keycloak.models.KeycloakSessionFactory;
|
||||
import org.keycloak.provider.EnvironmentDependentProviderFactory;
|
||||
import org.keycloak.provider.Provider;
|
||||
import org.keycloak.provider.ProviderFactory;
|
||||
import org.jboss.logging.Logger;
|
||||
import static org.keycloak.models.utils.KeycloakModelUtils.getComponentFactory;
|
||||
|
||||
|
@ -60,7 +60,7 @@ public abstract class AbstractMapProviderFactory<T extends Provider, K, V extend
|
|||
}
|
||||
|
||||
protected MapStorage<K, V, M> getStorage(KeycloakSession session) {
|
||||
MapStorageProviderFactory storageProviderFactory = (MapStorageProviderFactory) getComponentFactory(session.getKeycloakSessionFactory(),
|
||||
ProviderFactory<MapStorageProvider> storageProviderFactory = getComponentFactory(session.getKeycloakSessionFactory(),
|
||||
MapStorageProvider.class, storageConfigScope, MapStorageSpi.NAME);
|
||||
final MapStorageProvider factory = storageProviderFactory.create(session);
|
||||
|
||||
|
|
|
@ -211,7 +211,7 @@ public class MapGroupProvider<K> implements GroupProvider {
|
|||
if (tx.read(entity.getId()) != null) {
|
||||
throw new ModelDuplicateException("Group exists: " + entityId);
|
||||
}
|
||||
tx.create(entity.getId(), entity);
|
||||
tx.create(entity);
|
||||
|
||||
return entityToAdapterFunc(realm).apply(entity);
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ public class MapUserLoginFailureProvider<K> implements UserLoginFailureProvider
|
|||
if (userLoginFailureEntity == null) {
|
||||
userLoginFailureEntity = new MapUserLoginFailureEntity<>(userLoginFailureStore.getKeyConvertor().yieldNewUniqueKey(), realm.getId(), userId);
|
||||
|
||||
userLoginFailureTx.create(userLoginFailureEntity.getId(), userLoginFailureEntity);
|
||||
userLoginFailureTx.create(userLoginFailureEntity);
|
||||
}
|
||||
|
||||
return userLoginFailureEntityToAdapterFunc(realm).apply(userLoginFailureEntity);
|
||||
|
|
|
@ -87,7 +87,7 @@ public class MapRealmProvider<K> implements RealmProvider {
|
|||
MapRealmEntity<K> entity = new MapRealmEntity<>(kId);
|
||||
entity.setName(name);
|
||||
|
||||
tx.create(kId, entity);
|
||||
tx.create(entity);
|
||||
return entityToAdapter(entity);
|
||||
}
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ public class MapRoleProvider<K> implements RoleProvider {
|
|||
if (tx.read(entity.getId()) != null) {
|
||||
throw new ModelDuplicateException("Role exists: " + id);
|
||||
}
|
||||
tx.create(entity.getId(), entity);
|
||||
tx.create(entity);
|
||||
return entityToAdapterFunc(realm).apply(entity);
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,7 @@ public class MapRoleProvider<K> implements RoleProvider {
|
|||
if (tx.read(entity.getId()) != null) {
|
||||
throw new ModelDuplicateException("Role exists: " + id);
|
||||
}
|
||||
tx.create(entity.getId(), entity);
|
||||
tx.create(entity);
|
||||
return entityToAdapterFunc(client.getRealm()).apply(entity);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,10 +28,9 @@ public interface MapKeycloakTransaction<K, V extends AbstractEntity<K>, M> exten
|
|||
/**
|
||||
* Instructs this transaction to add a new value into the underlying store on commit.
|
||||
*
|
||||
* @param key an identifier that will be associated with the {@code value}
|
||||
* @param value the value
|
||||
*/
|
||||
void create(K key, V value);
|
||||
void create(V value);
|
||||
|
||||
/**
|
||||
* Provides possibility to lookup for values by a {@code key} in the underlying store with respect to changes done
|
||||
|
|
|
@ -39,13 +39,14 @@ import java.util.stream.Stream;
|
|||
public interface MapStorage<K, V extends AbstractEntity<K>, M> {
|
||||
|
||||
/**
|
||||
* Creates an object in the store identified by given {@code key}.
|
||||
* @param key Key of the object as seen in the logical level
|
||||
* @param value Entity
|
||||
* @return Reference to the entity created in the store
|
||||
* Creates an object in the store identified. The ID of the {@code value} should be non-{@code null}.
|
||||
* If the ID is {@code null}, then the {@code value}'s ID will be returned
|
||||
* @param value Entity to create in the store
|
||||
* @throws NullPointerException if object or its {@code key} is {@code null}
|
||||
* @see AbstractEntity#getId()
|
||||
* @return Entity representing the {@code value} in the store. It may or may not be the same instance as {@code value}
|
||||
*/
|
||||
V create(K key, V value);
|
||||
V create(V value);
|
||||
|
||||
/**
|
||||
* Returns object with the given {@code key} from the storage or {@code null} if object does not exist.
|
||||
|
|
|
@ -180,7 +180,8 @@ public class ConcurrentHashMapKeycloakTransaction<K, V extends AbstractEntity<K>
|
|||
}
|
||||
|
||||
@Override
|
||||
public void create(K key, V value) {
|
||||
public void create(V value) {
|
||||
K key = value.getId();
|
||||
addTask(key, new CreateOperation(key, value));
|
||||
}
|
||||
|
||||
|
@ -329,7 +330,7 @@ public class ConcurrentHashMapKeycloakTransaction<K, V extends AbstractEntity<K>
|
|||
this.key = key;
|
||||
}
|
||||
|
||||
@Override public void execute() { map.create(key, getValue()); }
|
||||
@Override public void execute() { map.create(getValue()); }
|
||||
@Override public MapOperation getOperation() { return MapOperation.CREATE; }
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ public class ConcurrentHashMapStorage<K, V extends AbstractEntity<K>, M> impleme
|
|||
}
|
||||
|
||||
@Override
|
||||
public V create(K key, V value) {
|
||||
public V create(V value) {
|
||||
return store.putIfAbsent(key, value);
|
||||
}
|
||||
|
||||
|
|
|
@ -214,7 +214,7 @@ public class ConcurrentHashMapStorageProviderFactory implements AmphibianProvide
|
|||
JavaType type = Serialization.MAPPER.getTypeFactory().constructCollectionType(List.class, valueType);
|
||||
|
||||
List<V> values = Serialization.MAPPER.readValue(f, type);
|
||||
values.forEach((V mce) -> store.create(mce.getId(), mce));
|
||||
values.forEach((V mce) -> store.create(mce));
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
|
|
@ -335,7 +335,7 @@ public class MapUserProvider<K> implements UserProvider.Streams, UserCredentialS
|
|||
entity.setUsername(username.toLowerCase());
|
||||
entity.setCreatedTimestamp(Time.currentTimeMillis());
|
||||
|
||||
tx.create(entityId, entity);
|
||||
tx.create(entity);
|
||||
final UserModel userModel = entityToAdapterFunc(realm).apply(entity);
|
||||
|
||||
if (addDefaultRoles) {
|
||||
|
|
|
@ -162,7 +162,7 @@ public class MapUserSessionProvider<UK, CK> implements UserSessionProvider {
|
|||
|
||||
LOG.tracef("createClientSession(%s, %s, %s)%s", realm, client, userSession, getShortStackTrace());
|
||||
|
||||
clientSessionTx.create(entity.getId(), entity);
|
||||
clientSessionTx.create(entity);
|
||||
|
||||
MapUserSessionEntity<UK> userSessionEntity = getUserSessionById(userSessionStore.getKeyConvertor().fromString(userSession.getId()));
|
||||
|
||||
|
@ -227,7 +227,7 @@ public class MapUserSessionProvider<UK, CK> implements UserSessionProvider {
|
|||
throw new ModelDuplicateException("User session exists: " + entity.getId());
|
||||
}
|
||||
|
||||
userSessionTx.create(entity.getId(), entity);
|
||||
userSessionTx.create(entity);
|
||||
}
|
||||
|
||||
UserSessionModel userSession = userEntityToAdapterFunc(realm).apply(entity);
|
||||
|
@ -434,7 +434,7 @@ public class MapUserSessionProvider<UK, CK> implements UserSessionProvider {
|
|||
offlineUserSession.setLastSessionRefresh(currentTime);
|
||||
setUserSessionExpiration(offlineUserSession, userSession.getRealm());
|
||||
|
||||
userSessionTx.create(offlineUserSession.getId(), offlineUserSession);
|
||||
userSessionTx.create(offlineUserSession);
|
||||
|
||||
return userEntityToAdapterFunc(userSession.getRealm()).apply(offlineUserSession);
|
||||
}
|
||||
|
@ -483,7 +483,7 @@ public class MapUserSessionProvider<UK, CK> implements UserSessionProvider {
|
|||
userSessionEntity.get().addAuthenticatedClientSession(clientSession.getClient().getId(), clientSessionStore.getKeyConvertor().keyToString(clientSessionEntity.getId()));
|
||||
}
|
||||
|
||||
clientSessionTx.create(clientSessionEntity.getId(), clientSessionEntity);
|
||||
clientSessionTx.create(clientSessionEntity);
|
||||
|
||||
return clientEntityToAdapterFunc(clientSession.getRealm(),
|
||||
clientSession.getClient(), offlineUserSession).apply(clientSessionEntity);
|
||||
|
@ -570,12 +570,12 @@ public class MapUserSessionProvider<UK, CK> implements UserSessionProvider {
|
|||
|
||||
userSessionEntity.addAuthenticatedClientSession(entry.getKey(), clientSessionStore.getKeyConvertor().keyToString(clientSession.getId()));
|
||||
|
||||
clientSessionTx.create(clientSession.getId(), clientSession);
|
||||
clientSessionTx.create(clientSession);
|
||||
}
|
||||
|
||||
return userSessionEntity;
|
||||
})
|
||||
.forEach(use -> userSessionTx.create(use.getId(), use));
|
||||
.forEach(use -> userSessionTx.create(use));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -118,9 +118,9 @@ public class MapStorageTest extends KeycloakModelTest {
|
|||
MapClientEntity<K1> client1 = new MapClientEntity<>(id1, realmId);
|
||||
MapClientEntity<K2> client2 = new MapClientEntity<>(id2, realmId);
|
||||
|
||||
storageMain.create(clientMain.getId(), clientMain);
|
||||
storage1.create(client1.getId(), client1);
|
||||
storage2.create(client2.getId(), client2);
|
||||
storageMain.create(clientMain);
|
||||
storage1.create(client1);
|
||||
storage2.create(client2);
|
||||
|
||||
return new Object[] {idMain, id1, id2};
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue