KEYCLOAK-18815 Update MapKeycloakTransaction return types to match MapStorage
This commit is contained in:
parent
54a0e84070
commit
1f3650dcd9
19 changed files with 40 additions and 34 deletions
|
@ -103,7 +103,7 @@ public class MapRootAuthenticationSessionProvider<K> implements AuthenticationSe
|
|||
throw new ModelDuplicateException("Root authentication session exists: " + entity.getId());
|
||||
}
|
||||
|
||||
tx.create(entity);
|
||||
entity = tx.create(entity);
|
||||
|
||||
return entityToAdapterFunc(realm).apply(entity);
|
||||
}
|
||||
|
|
|
@ -128,7 +128,7 @@ public class MapPermissionTicketStore<K extends Comparable<K>> implements Permis
|
|||
entity.setOwner(owner);
|
||||
entity.setResourceServerId(resourceServer.getId());
|
||||
|
||||
tx.create(entity);
|
||||
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(entity);
|
||||
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);
|
||||
entity = tx.create(entity);
|
||||
|
||||
return entityToAdapter(entity);
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ public class MapResourceStore<K extends Comparable<K>> implements ResourceStore
|
|||
entity.setResourceServerId(resourceServer.getId());
|
||||
entity.setOwner(owner);
|
||||
|
||||
tx.create(entity);
|
||||
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(entity);
|
||||
entity = tx.create(entity);
|
||||
|
||||
return entityToAdapter(entity);
|
||||
}
|
||||
|
|
|
@ -159,7 +159,7 @@ public class MapClientProvider<K> implements ClientProvider {
|
|||
if (tx.read(entity.getId()) != null) {
|
||||
throw new ModelDuplicateException("Client exists: " + id);
|
||||
}
|
||||
tx.create(entity);
|
||||
entity = tx.create(entity);
|
||||
final ClientModel resource = entityToAdapterFunc(realm).apply(entity);
|
||||
|
||||
// TODO: Sending an event should be extracted to store layer
|
||||
|
|
|
@ -102,7 +102,7 @@ public class MapClientScopeProvider<K> implements ClientScopeProvider {
|
|||
if (tx.read(entity.getId()) != null) {
|
||||
throw new ModelDuplicateException("Client scope exists: " + id);
|
||||
}
|
||||
tx.create(entity);
|
||||
entity = tx.create(entity);
|
||||
return entityToAdapterFunc(realm).apply(entity);
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,6 @@ public class MapStorageUtils {
|
|||
*/
|
||||
public static <K, V extends AbstractEntity<K>> V registerEntityForChanges(MapKeycloakTransaction<K, V, ?> tx, V origEntity) {
|
||||
final V res = tx.read(origEntity.getId(), id -> Serialization.from(origEntity));
|
||||
tx.updateIfChanged(res, AbstractEntity<K>::isUpdated);
|
||||
return res;
|
||||
return tx.updateIfChanged(res, AbstractEntity<K>::isUpdated);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -220,7 +220,7 @@ public class MapGroupProvider<K> implements GroupProvider {
|
|||
if (tx.read(entity.getId()) != null) {
|
||||
throw new ModelDuplicateException("Group exists: " + entityId);
|
||||
}
|
||||
tx.create(entity);
|
||||
entity = tx.create(entity);
|
||||
|
||||
return entityToAdapterFunc(realm).apply(entity);
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ public class MapUserLoginFailureProvider<K> implements UserLoginFailureProvider
|
|||
if (userLoginFailureEntity == null) {
|
||||
userLoginFailureEntity = new MapUserLoginFailureEntity<>(userLoginFailureStore.getKeyConvertor().yieldNewUniqueKey(), realm.getId(), userId);
|
||||
|
||||
userLoginFailureTx.create(userLoginFailureEntity);
|
||||
userLoginFailureEntity = userLoginFailureTx.create(userLoginFailureEntity);
|
||||
}
|
||||
|
||||
return userLoginFailureEntityToAdapterFunc(realm).apply(userLoginFailureEntity);
|
||||
|
|
|
@ -89,7 +89,7 @@ public class MapRealmProvider<K> implements RealmProvider {
|
|||
MapRealmEntity<K> entity = new MapRealmEntity<>(kId);
|
||||
entity.setName(name);
|
||||
|
||||
tx.create(entity);
|
||||
entity = tx.create(entity);
|
||||
return entityToAdapter(entity);
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ public class MapRoleProvider<K> implements RoleProvider {
|
|||
if (tx.read(entity.getId()) != null) {
|
||||
throw new ModelDuplicateException("Role exists: " + id);
|
||||
}
|
||||
tx.create(entity);
|
||||
entity = tx.create(entity);
|
||||
return entityToAdapterFunc(realm).apply(entity);
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ public class MapRoleProvider<K> implements RoleProvider {
|
|||
if (tx.read(entity.getId()) != null) {
|
||||
throw new ModelDuplicateException("Role exists: " + id);
|
||||
}
|
||||
tx.create(entity);
|
||||
entity = tx.create(entity);
|
||||
return entityToAdapterFunc(client.getRealm()).apply(entity);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,8 +29,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 value the value
|
||||
* @return Entity representing the {@code value} in the store. It may or may not be the same instance as {@code value}
|
||||
*/
|
||||
void create(V value);
|
||||
V create(V value);
|
||||
|
||||
/**
|
||||
* Provides possibility to lookup for values by a {@code key} in the underlying store with respect to changes done
|
||||
|
@ -77,8 +78,9 @@ public interface MapKeycloakTransaction<K, V extends AbstractEntity<K>, M> exten
|
|||
* underlying store on commit.
|
||||
*
|
||||
* @param value updated version of the value
|
||||
* @return Entity representing the {@code value} in the store. It may or may not be the same instance as {@code value}
|
||||
*/
|
||||
void update(V value);
|
||||
V update(V value);
|
||||
|
||||
/**
|
||||
* Returns an updated version of the {@code orig} object as updated in this transaction.
|
||||
|
@ -98,17 +100,19 @@ public interface MapKeycloakTransaction<K, V extends AbstractEntity<K>, M> exten
|
|||
*
|
||||
* @param value new version of the value. Must not alter the {@code id} of the entity
|
||||
* @param shouldPut predicate to check in commit phase
|
||||
* @return Entity representing the {@code value} in the store. It may or may not be the same instance as {@code value}
|
||||
* @see AbstractEntity#getId()
|
||||
*/
|
||||
void updateIfChanged(V value, Predicate<V> shouldPut);
|
||||
V updateIfChanged(V value, Predicate<V> shouldPut);
|
||||
|
||||
/**
|
||||
* Instructs this transaction to delete a value associated with the identifier {@code key} from the underlying store
|
||||
* on commit.
|
||||
*
|
||||
* @return Returns {@code true} if the object has been deleted or result cannot be determined, {@code false} otherwise.
|
||||
* @param key identifier of a value
|
||||
*/
|
||||
void delete(K key);
|
||||
boolean delete(K key);
|
||||
|
||||
/**
|
||||
* Instructs this transaction to remove values (identified by {@code mcb} filter) from the underlying store on commit.
|
||||
|
|
|
@ -131,7 +131,7 @@ public interface MapStorage<K, V extends AbstractEntity<K>, M> {
|
|||
*
|
||||
* @return See description. Never returns {@code null}
|
||||
*/
|
||||
public MapKeycloakTransaction<K, V, M> createTransaction(KeycloakSession session);
|
||||
MapKeycloakTransaction<K, V, M> createTransaction(KeycloakSession session);
|
||||
|
||||
/**
|
||||
* Returns a {@link StringKeyConvertor} that is used to convert primary keys
|
||||
|
@ -139,6 +139,6 @@ public interface MapStorage<K, V extends AbstractEntity<K>, M> {
|
|||
*
|
||||
* @return See above. Never returns {@code null}.
|
||||
*/
|
||||
public StringKeyConvertor<K> getKeyConvertor();
|
||||
StringKeyConvertor<K> getKeyConvertor();
|
||||
|
||||
}
|
||||
|
|
|
@ -183,19 +183,21 @@ public class ConcurrentHashMapKeycloakTransaction<K, V extends AbstractEntity<K>
|
|||
}
|
||||
|
||||
@Override
|
||||
public void update(V value) {
|
||||
public V update(V value) {
|
||||
K key = value.getId();
|
||||
addTask(key, new UpdateOperation(value));
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create(V value) {
|
||||
public V create(V value) {
|
||||
K key = value.getId();
|
||||
addTask(key, new CreateOperation(value));
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateIfChanged(V value, Predicate<V> shouldPut) {
|
||||
public V updateIfChanged(V value, Predicate<V> shouldPut) {
|
||||
K key = value.getId();
|
||||
log.tracef("Adding operation UPDATE_IF_CHANGED for %s @ %08x", key, System.identityHashCode(value));
|
||||
|
||||
|
@ -209,12 +211,13 @@ public class ConcurrentHashMapKeycloakTransaction<K, V extends AbstractEntity<K>
|
|||
}
|
||||
@Override public MapOperation getOperation() { return MapOperation.UPDATE; }
|
||||
};
|
||||
tasks.merge(taskKey, op, this::merge);
|
||||
return tasks.merge(taskKey, op, this::merge).getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(K key) {
|
||||
public boolean delete(K key) {
|
||||
addTask(key, new DeleteOperation(key));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -62,10 +62,10 @@ public class UserSessionConcurrentHashMapStorage<K> extends ConcurrentHashMapSto
|
|||
}
|
||||
|
||||
@Override
|
||||
public void delete(K key) {
|
||||
public boolean delete(K key) {
|
||||
ModelCriteriaBuilder<AuthenticatedClientSessionModel> csMcb = clientSessionStore.createCriteriaBuilder().compare(AuthenticatedClientSessionModel.SearchableFields.USER_SESSION_ID, Operator.EQ, key);
|
||||
clientSessionTr.delete(key, withCriteria(csMcb));
|
||||
super.delete(key);
|
||||
return super.delete(key);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -336,7 +336,7 @@ public class MapUserProvider<K> implements UserProvider.Streams, UserCredentialS
|
|||
entity.setUsername(username.toLowerCase());
|
||||
entity.setCreatedTimestamp(Time.currentTimeMillis());
|
||||
|
||||
tx.create(entity);
|
||||
entity = tx.create(entity);
|
||||
final UserModel userModel = entityToAdapterFunc(realm).apply(entity);
|
||||
|
||||
if (addDefaultRoles) {
|
||||
|
|
|
@ -161,7 +161,7 @@ public class MapUserSessionProvider<UK, CK> implements UserSessionProvider {
|
|||
|
||||
LOG.tracef("createClientSession(%s, %s, %s)%s", realm, client, userSession, getShortStackTrace());
|
||||
|
||||
clientSessionTx.create(entity);
|
||||
entity = clientSessionTx.create(entity);
|
||||
|
||||
MapUserSessionEntity<UK> userSessionEntity = getUserSessionById(userSessionStore.getKeyConvertor().fromString(userSession.getId()));
|
||||
|
||||
|
@ -226,7 +226,7 @@ public class MapUserSessionProvider<UK, CK> implements UserSessionProvider {
|
|||
throw new ModelDuplicateException("User session exists: " + entity.getId());
|
||||
}
|
||||
|
||||
userSessionTx.create(entity);
|
||||
entity = userSessionTx.create(entity);
|
||||
}
|
||||
|
||||
UserSessionModel userSession = userEntityToAdapterFunc(realm).apply(entity);
|
||||
|
@ -441,7 +441,7 @@ public class MapUserSessionProvider<UK, CK> implements UserSessionProvider {
|
|||
offlineUserSession.setLastSessionRefresh(currentTime);
|
||||
setUserSessionExpiration(offlineUserSession, userSession.getRealm());
|
||||
|
||||
userSessionTx.create(offlineUserSession);
|
||||
offlineUserSession = userSessionTx.create(offlineUserSession);
|
||||
|
||||
return userEntityToAdapterFunc(userSession.getRealm()).apply(offlineUserSession);
|
||||
}
|
||||
|
@ -490,7 +490,7 @@ public class MapUserSessionProvider<UK, CK> implements UserSessionProvider {
|
|||
userSessionEntity.get().addAuthenticatedClientSession(clientSession.getClient().getId(), clientSessionStore.getKeyConvertor().keyToString(clientSessionEntity.getId()));
|
||||
}
|
||||
|
||||
clientSessionTx.create(clientSessionEntity);
|
||||
clientSessionEntity = clientSessionTx.create(clientSessionEntity);
|
||||
|
||||
return clientEntityToAdapterFunc(clientSession.getRealm(),
|
||||
clientSession.getClient(), offlineUserSession).apply(clientSessionEntity);
|
||||
|
@ -577,7 +577,7 @@ public class MapUserSessionProvider<UK, CK> implements UserSessionProvider {
|
|||
|
||||
userSessionEntity.addAuthenticatedClientSession(entry.getKey(), clientSessionStore.getKeyConvertor().keyToString(clientSession.getId()));
|
||||
|
||||
clientSessionTx.create(clientSession);
|
||||
clientSession = clientSessionTx.create(clientSession);
|
||||
}
|
||||
|
||||
return userSessionEntity;
|
||||
|
|
Loading…
Reference in a new issue