KEYCLOAK-19726 Fix return types of ModelCriteriaBuilder methods

This commit is contained in:
Hynek Mlnarik 2021-11-03 20:46:32 +01:00 committed by Hynek Mlnařík
parent 93d286fdc7
commit 58d403cf24
23 changed files with 232 additions and 237 deletions

View file

@ -25,8 +25,8 @@ import org.keycloak.models.ModelDuplicateException;
import org.keycloak.models.RealmModel;
import org.keycloak.models.map.storage.MapKeycloakTransaction;
import org.keycloak.models.map.storage.MapStorage;
import org.keycloak.models.map.storage.ModelCriteriaBuilder;
import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator;
import org.keycloak.models.map.storage.criteria.DefaultModelCriteria;
import org.keycloak.models.utils.RealmInfoUtil;
import org.keycloak.sessions.AuthenticationSessionCompoundId;
import org.keycloak.sessions.AuthenticationSessionProvider;
@ -131,7 +131,7 @@ public class MapRootAuthenticationSessionProvider implements AuthenticationSessi
int expired = Time.currentTime() - RealmInfoUtil.getDettachedClientSessionLifespan(realm);
ModelCriteriaBuilder<RootAuthenticationSessionModel> mcb = criteria();
DefaultModelCriteria<RootAuthenticationSessionModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.TIMESTAMP, Operator.LT, expired);
@ -143,7 +143,7 @@ public class MapRootAuthenticationSessionProvider implements AuthenticationSessi
@Override
public void onRealmRemoved(RealmModel realm) {
Objects.requireNonNull(realm, "The provided realm can't be null!");
ModelCriteriaBuilder<RootAuthenticationSessionModel> mcb = criteria();
DefaultModelCriteria<RootAuthenticationSessionModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId());
tx.delete(withCriteria(mcb));

View file

@ -31,9 +31,9 @@ import org.keycloak.models.map.authorization.adapter.MapPermissionTicketAdapter;
import org.keycloak.models.map.authorization.entity.MapPermissionTicketEntity;
import org.keycloak.models.map.storage.MapKeycloakTransaction;
import org.keycloak.models.map.storage.MapStorage;
import org.keycloak.models.map.storage.ModelCriteriaBuilder;
import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator;
import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator;
import org.keycloak.models.map.storage.criteria.DefaultModelCriteria;
import java.util.Collections;
import java.util.EnumMap;
import java.util.List;
@ -67,8 +67,8 @@ public class MapPermissionTicketStore implements PermissionTicketStore {
return new MapPermissionTicketAdapter(origEntity, authorizationProvider.getStoreFactory());
}
private ModelCriteriaBuilder<PermissionTicket> forResourceServer(String resourceServerId) {
ModelCriteriaBuilder<PermissionTicket> mcb = criteria();
private DefaultModelCriteria<PermissionTicket> forResourceServer(String resourceServerId) {
DefaultModelCriteria<PermissionTicket> mcb = criteria();
return resourceServerId == null
? mcb
@ -78,10 +78,10 @@ public class MapPermissionTicketStore implements PermissionTicketStore {
@Override
public long count(Map<PermissionTicket.FilterOption, String> attributes, String resourceServerId) {
ModelCriteriaBuilder<PermissionTicket> mcb = forResourceServer(resourceServerId).and(
DefaultModelCriteria<PermissionTicket> mcb = forResourceServer(resourceServerId).and(
attributes.entrySet().stream()
.map(this::filterEntryToModelCriteriaBuilder)
.toArray(ModelCriteriaBuilder[]::new)
.map(this::filterEntryToDefaultModelCriteria)
.toArray(DefaultModelCriteria[]::new)
);
return tx.getCount(withCriteria(mcb));
@ -94,7 +94,7 @@ public class MapPermissionTicketStore implements PermissionTicketStore {
String owner = authorizationProvider.getStoreFactory().getResourceStore().findById(resourceId, resourceServer.getId()).getOwner();
// @UniqueConstraint(columnNames = {"OWNER", "REQUESTER", "RESOURCE_SERVER_ID", "RESOURCE_ID", "SCOPE_ID"})
ModelCriteriaBuilder<PermissionTicket> mcb = forResourceServer(resourceServer.getId())
DefaultModelCriteria<PermissionTicket> mcb = forResourceServer(resourceServer.getId())
.compare(SearchableFields.OWNER, Operator.EQ, owner)
.compare(SearchableFields.RESOURCE_ID, Operator.EQ, resourceId)
.compare(SearchableFields.REQUESTER, Operator.EQ, requester);
@ -183,7 +183,7 @@ public class MapPermissionTicketStore implements PermissionTicketStore {
@Override
public List<PermissionTicket> find(Map<PermissionTicket.FilterOption, String> attributes, String resourceServerId, int firstResult, int maxResult) {
ModelCriteriaBuilder<PermissionTicket> mcb = forResourceServer(resourceServerId);
DefaultModelCriteria<PermissionTicket> mcb = forResourceServer(resourceServerId);
if (attributes.containsKey(PermissionTicket.FilterOption.RESOURCE_NAME)) {
String expectedResourceName = attributes.remove(PermissionTicket.FilterOption.RESOURCE_NAME);
@ -201,8 +201,8 @@ public class MapPermissionTicketStore implements PermissionTicketStore {
mcb = mcb.and(
attributes.entrySet().stream()
.map(this::filterEntryToModelCriteriaBuilder)
.toArray(ModelCriteriaBuilder[]::new)
.map(this::filterEntryToDefaultModelCriteria)
.toArray(DefaultModelCriteria[]::new)
);
return tx.read(withCriteria(mcb).pagination(firstResult, maxResult, SearchableFields.ID))
@ -210,11 +210,11 @@ public class MapPermissionTicketStore implements PermissionTicketStore {
.collect(Collectors.toList());
}
private ModelCriteriaBuilder<PermissionTicket> filterEntryToModelCriteriaBuilder(Map.Entry<PermissionTicket.FilterOption, String> entry) {
private DefaultModelCriteria<PermissionTicket> filterEntryToDefaultModelCriteria(Map.Entry<PermissionTicket.FilterOption, String> entry) {
PermissionTicket.FilterOption name = entry.getKey();
String value = entry.getValue();
ModelCriteriaBuilder<PermissionTicket> mcb = criteria();
DefaultModelCriteria<PermissionTicket> mcb = criteria();
switch (name) {
case ID:
case SCOPE_ID:
@ -263,7 +263,7 @@ public class MapPermissionTicketStore implements PermissionTicketStore {
@Override
public List<Resource> findGrantedResources(String requester, String name, int first, int max) {
ModelCriteriaBuilder<PermissionTicket> mcb = criteria();
DefaultModelCriteria<PermissionTicket> mcb = criteria();
mcb = mcb.compare(SearchableFields.REQUESTER, Operator.EQ, requester)
.compare(SearchableFields.GRANTED_TIMESTAMP, Operator.EXISTS);
@ -295,7 +295,7 @@ public class MapPermissionTicketStore implements PermissionTicketStore {
@Override
public List<Resource> findGrantedOwnerResources(String owner, int first, int max) {
ModelCriteriaBuilder<PermissionTicket> mcb = criteria();
DefaultModelCriteria<PermissionTicket> mcb = criteria();
mcb = mcb.compare(SearchableFields.OWNER, Operator.EQ, owner);
return paginatedStream(tx.read(withCriteria(mcb).orderBy(SearchableFields.RESOURCE_ID, ASCENDING))

View file

@ -29,7 +29,6 @@ import org.keycloak.models.map.authorization.adapter.MapPolicyAdapter;
import org.keycloak.models.map.authorization.entity.MapPolicyEntity;
import org.keycloak.models.map.storage.MapKeycloakTransaction;
import org.keycloak.models.map.storage.MapStorage;
import org.keycloak.models.map.storage.ModelCriteriaBuilder;
import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator;
import org.keycloak.models.map.storage.criteria.DefaultModelCriteria;
import org.keycloak.representations.idm.authorization.AbstractPolicyRepresentation;
@ -63,8 +62,8 @@ public class MapPolicyStore implements PolicyStore {
return new MapPolicyAdapter(origEntity, authorizationProvider.getStoreFactory());
}
private ModelCriteriaBuilder<Policy> forResourceServer(String resourceServerId) {
ModelCriteriaBuilder<Policy> mcb = criteria();
private DefaultModelCriteria<Policy> forResourceServer(String resourceServerId) {
DefaultModelCriteria<Policy> mcb = criteria();
return resourceServerId == null
? mcb
@ -77,7 +76,7 @@ public class MapPolicyStore implements PolicyStore {
LOG.tracef("create(%s, %s, %s)%s", representation.getId(), resourceServer.getId(), resourceServer, getShortStackTrace());
// @UniqueConstraint(columnNames = {"NAME", "RESOURCE_SERVER_ID"})
ModelCriteriaBuilder<Policy> mcb = forResourceServer(resourceServer.getId())
DefaultModelCriteria<Policy> mcb = forResourceServer(resourceServer.getId())
.compare(SearchableFields.NAME, Operator.EQ, representation.getName());
if (tx.getCount(withCriteria(mcb)) > 0) {
@ -136,11 +135,11 @@ public class MapPolicyStore implements PolicyStore {
public List<Policy> findByResourceServer(Map<Policy.FilterOption, String[]> attributes, String resourceServerId, int firstResult, int maxResult) {
LOG.tracef("findByResourceServer(%s, %s, %d, %d)%s", attributes, resourceServerId, firstResult, maxResult, getShortStackTrace());
ModelCriteriaBuilder<Policy> mcb = forResourceServer(resourceServerId).and(
DefaultModelCriteria<Policy> mcb = forResourceServer(resourceServerId).and(
attributes.entrySet().stream()
.map(this::filterEntryToModelCriteriaBuilder)
.map(this::filterEntryToDefaultModelCriteria)
.filter(Objects::nonNull)
.toArray(ModelCriteriaBuilder[]::new)
.toArray(DefaultModelCriteria[]::new)
);
if (!attributes.containsKey(Policy.FilterOption.OWNER) && !attributes.containsKey(Policy.FilterOption.ANY_OWNER)) {
@ -154,11 +153,11 @@ public class MapPolicyStore implements PolicyStore {
.collect(Collectors.toList());
}
private ModelCriteriaBuilder<Policy> filterEntryToModelCriteriaBuilder(Map.Entry<Policy.FilterOption, String[]> entry) {
private DefaultModelCriteria<Policy> filterEntryToDefaultModelCriteria(Map.Entry<Policy.FilterOption, String[]> entry) {
Policy.FilterOption name = entry.getKey();
String[] value = entry.getValue();
ModelCriteriaBuilder<Policy> mcb = criteria();
DefaultModelCriteria<Policy> mcb = criteria();
switch (name) {
case ID:
case SCOPE_ID:
@ -220,7 +219,7 @@ public class MapPolicyStore implements PolicyStore {
@Override
public void findByScopeIds(List<String> scopeIds, String resourceId, String resourceServerId, Consumer<Policy> consumer) {
ModelCriteriaBuilder<Policy> mcb = forResourceServer(resourceServerId)
DefaultModelCriteria<Policy> mcb = forResourceServer(resourceServerId)
.compare(SearchableFields.TYPE, Operator.EQ, "scope")
.compare(SearchableFields.SCOPE_ID, Operator.IN, scopeIds);

View file

@ -29,9 +29,9 @@ import org.keycloak.models.map.authorization.adapter.MapResourceAdapter;
import org.keycloak.models.map.authorization.entity.MapResourceEntity;
import org.keycloak.models.map.storage.MapKeycloakTransaction;
import org.keycloak.models.map.storage.MapStorage;
import org.keycloak.models.map.storage.ModelCriteriaBuilder;
import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator;
import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator;
import org.keycloak.models.map.storage.criteria.DefaultModelCriteria;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
@ -61,8 +61,8 @@ public class MapResourceStore implements ResourceStore {
return new MapResourceAdapter(origEntity, authorizationProvider.getStoreFactory());
}
private ModelCriteriaBuilder<Resource> forResourceServer(String resourceServerId) {
ModelCriteriaBuilder<Resource> mcb = criteria();
private DefaultModelCriteria<Resource> forResourceServer(String resourceServerId) {
DefaultModelCriteria<Resource> mcb = criteria();
return resourceServerId == null
? mcb
@ -74,7 +74,7 @@ public class MapResourceStore implements ResourceStore {
public Resource create(String id, String name, ResourceServer resourceServer, String owner) {
LOG.tracef("create(%s, %s, %s, %s)%s", id, name, resourceServer, owner, getShortStackTrace());
// @UniqueConstraint(columnNames = {"NAME", "RESOURCE_SERVER_ID", "OWNER"})
ModelCriteriaBuilder<Resource> mcb = forResourceServer(resourceServer.getId())
DefaultModelCriteria<Resource> mcb = forResourceServer(resourceServer.getId())
.compare(SearchableFields.NAME, Operator.EQ, name)
.compare(SearchableFields.OWNER, Operator.EQ, owner);
@ -156,10 +156,10 @@ public class MapResourceStore implements ResourceStore {
@Override
public List<Resource> findByResourceServer(Map<Resource.FilterOption, String[]> attributes, String resourceServerId, int firstResult, int maxResult) {
LOG.tracef("findByResourceServer(%s, %s, %d, %d)%s", attributes, resourceServerId, firstResult, maxResult, getShortStackTrace());
ModelCriteriaBuilder<Resource> mcb = forResourceServer(resourceServerId).and(
DefaultModelCriteria<Resource> mcb = forResourceServer(resourceServerId).and(
attributes.entrySet().stream()
.map(this::filterEntryToModelCriteriaBuilder)
.toArray(ModelCriteriaBuilder[]::new)
.map(this::filterEntryToDefaultModelCriteria)
.toArray(DefaultModelCriteria[]::new)
);
return tx.read(withCriteria(mcb).pagination(firstResult, maxResult, SearchableFields.NAME))
@ -167,11 +167,11 @@ public class MapResourceStore implements ResourceStore {
.collect(Collectors.toList());
}
private ModelCriteriaBuilder<Resource> filterEntryToModelCriteriaBuilder(Map.Entry<Resource.FilterOption, String[]> entry) {
private DefaultModelCriteria<Resource> filterEntryToDefaultModelCriteria(Map.Entry<Resource.FilterOption, String[]> entry) {
Resource.FilterOption name = entry.getKey();
String[] value = entry.getValue();
ModelCriteriaBuilder<Resource> mcb = criteria();
DefaultModelCriteria<Resource> mcb = criteria();
switch (name) {
case ID:
case SCOPE_ID:
@ -231,7 +231,7 @@ public class MapResourceStore implements ResourceStore {
public void findByType(String type, String owner, String resourceServerId, Consumer<Resource> consumer) {
LOG.tracef("findByType(%s, %s, %s, %s)%s", type, owner, resourceServerId, consumer, getShortStackTrace());
ModelCriteriaBuilder<Resource> mcb = forResourceServer(resourceServerId)
DefaultModelCriteria<Resource> mcb = forResourceServer(resourceServerId)
.compare(SearchableFields.TYPE, Operator.EQ, type);
if (owner != null) {

View file

@ -29,9 +29,9 @@ import org.keycloak.models.map.authorization.adapter.MapScopeAdapter;
import org.keycloak.models.map.authorization.entity.MapScopeEntity;
import org.keycloak.models.map.storage.MapKeycloakTransaction;
import org.keycloak.models.map.storage.MapStorage;
import org.keycloak.models.map.storage.ModelCriteriaBuilder;
import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator;
import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator;
import org.keycloak.models.map.storage.criteria.DefaultModelCriteria;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -59,8 +59,8 @@ public class MapScopeStore implements ScopeStore {
return new MapScopeAdapter(origEntity, authorizationProvider.getStoreFactory());
}
private ModelCriteriaBuilder<Scope> forResourceServer(String resourceServerId) {
ModelCriteriaBuilder<Scope> mcb = criteria();
private DefaultModelCriteria<Scope> forResourceServer(String resourceServerId) {
DefaultModelCriteria<Scope> mcb = criteria();
return resourceServerId == null
? mcb
@ -74,7 +74,7 @@ public class MapScopeStore implements ScopeStore {
// @UniqueConstraint(columnNames = {"NAME", "RESOURCE_SERVER_ID"})
ModelCriteriaBuilder<Scope> mcb = forResourceServer(resourceServer.getId())
DefaultModelCriteria<Scope> mcb = forResourceServer(resourceServer.getId())
.compare(SearchableFields.NAME, Operator.EQ, name);
if (tx.getCount(withCriteria(mcb)) > 0) {
@ -130,7 +130,7 @@ public class MapScopeStore implements ScopeStore {
@Override
public List<Scope> findByResourceServer(Map<Scope.FilterOption, String[]> attributes, String resourceServerId, int firstResult, int maxResult) {
ModelCriteriaBuilder<Scope> mcb = forResourceServer(resourceServerId);
DefaultModelCriteria<Scope> mcb = forResourceServer(resourceServerId);
for (Scope.FilterOption filterOption : attributes.keySet()) {
String[] value = attributes.get(filterOption);

View file

@ -40,10 +40,10 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.keycloak.models.map.storage.MapStorage;
import org.keycloak.models.map.storage.ModelCriteriaBuilder;
import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator;
import static org.keycloak.common.util.StackUtil.getShortStackTrace;
import org.keycloak.models.ClientScopeModel;
import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator;
import org.keycloak.models.map.storage.criteria.DefaultModelCriteria;
import static org.keycloak.models.map.storage.QueryParameters.Order.ASCENDING;
import static org.keycloak.models.map.storage.QueryParameters.withCriteria;
import static org.keycloak.models.map.storage.criteria.DefaultModelCriteria.criteria;
@ -119,7 +119,7 @@ public class MapClientProvider implements ClientProvider {
@Override
public Stream<ClientModel> getClientsStream(RealmModel realm, Integer firstResult, Integer maxResults) {
ModelCriteriaBuilder<ClientModel> mcb = criteria();
DefaultModelCriteria<ClientModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId());
return tx.read(withCriteria(mcb).pagination(firstResult, maxResults, SearchableFields.CLIENT_ID))
@ -128,7 +128,7 @@ public class MapClientProvider implements ClientProvider {
@Override
public Stream<ClientModel> getClientsStream(RealmModel realm) {
ModelCriteriaBuilder<ClientModel> mcb = criteria();
DefaultModelCriteria<ClientModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId());
return tx.read(withCriteria(mcb).orderBy(SearchableFields.CLIENT_ID, ASCENDING))
@ -212,7 +212,7 @@ public class MapClientProvider implements ClientProvider {
@Override
public long getClientsCount(RealmModel realm) {
ModelCriteriaBuilder<ClientModel> mcb = criteria();
DefaultModelCriteria<ClientModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId());
return tx.getCount(withCriteria(mcb));
@ -239,7 +239,7 @@ public class MapClientProvider implements ClientProvider {
}
LOG.tracef("getClientByClientId(%s, %s)%s", realm, clientId, getShortStackTrace());
ModelCriteriaBuilder<ClientModel> mcb = criteria();
DefaultModelCriteria<ClientModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.CLIENT_ID, Operator.EQ, clientId);
@ -256,7 +256,7 @@ public class MapClientProvider implements ClientProvider {
return Stream.empty();
}
ModelCriteriaBuilder<ClientModel> mcb = criteria();
DefaultModelCriteria<ClientModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.CLIENT_ID, Operator.ILIKE, "%" + clientId + "%");
@ -266,7 +266,7 @@ public class MapClientProvider implements ClientProvider {
@Override
public Stream<ClientModel> searchClientsByAttributes(RealmModel realm, Map<String, String> attributes, Integer firstResult, Integer maxResults) {
ModelCriteriaBuilder<ClientModel> mcb = criteria();
DefaultModelCriteria<ClientModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId());
for (Map.Entry<String, String> entry : attributes.entrySet()) {
@ -331,7 +331,7 @@ public class MapClientProvider implements ClientProvider {
@Override
public Map<ClientModel, Set<String>> getAllRedirectUrisOfEnabledClients(RealmModel realm) {
ModelCriteriaBuilder<ClientModel> mcb = criteria();
DefaultModelCriteria<ClientModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.ENABLED, Operator.EQ, Boolean.TRUE);
@ -346,7 +346,7 @@ public class MapClientProvider implements ClientProvider {
}
public void preRemove(RealmModel realm, RoleModel role) {
ModelCriteriaBuilder<ClientModel> mcb = criteria();
DefaultModelCriteria<ClientModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.SCOPE_MAPPING_ROLE, Operator.EQ, role.getId());

View file

@ -32,8 +32,8 @@ import org.keycloak.models.ModelDuplicateException;
import org.keycloak.models.RealmModel;
import org.keycloak.models.map.storage.MapKeycloakTransaction;
import org.keycloak.models.map.storage.MapStorage;
import org.keycloak.models.map.storage.ModelCriteriaBuilder;
import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator;
import org.keycloak.models.map.storage.criteria.DefaultModelCriteria;
import org.keycloak.models.utils.KeycloakModelUtils;
import static org.keycloak.models.map.storage.QueryParameters.Order.ASCENDING;
@ -68,7 +68,7 @@ public class MapClientScopeProvider implements ClientScopeProvider {
@Override
public Stream<ClientScopeModel> getClientScopesStream(RealmModel realm) {
ModelCriteriaBuilder<ClientScopeModel> mcb = criteria();
DefaultModelCriteria<ClientScopeModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId());
return tx.read(withCriteria(mcb).orderBy(SearchableFields.NAME, ASCENDING))
@ -78,7 +78,7 @@ public class MapClientScopeProvider implements ClientScopeProvider {
@Override
public ClientScopeModel addClientScope(RealmModel realm, String id, String name) {
// Check Db constraint: @UniqueConstraint(columnNames = {"REALM_ID", "NAME"})
ModelCriteriaBuilder<ClientScopeModel> mcb = criteria();
DefaultModelCriteria<ClientScopeModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.NAME, Operator.EQ, name);

View file

@ -28,10 +28,10 @@ import org.keycloak.models.RoleModel;
import org.keycloak.models.map.storage.MapKeycloakTransaction;
import org.keycloak.models.map.storage.MapStorage;
import org.keycloak.models.map.storage.ModelCriteriaBuilder;
import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator;
import org.keycloak.models.map.storage.QueryParameters;
import org.keycloak.models.map.storage.criteria.DefaultModelCriteria;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.UnaryOperator;
@ -80,9 +80,9 @@ public class MapGroupProvider implements GroupProvider {
return getGroupsStreamInternal(realm, null, null);
}
private Stream<GroupModel> getGroupsStreamInternal(RealmModel realm, UnaryOperator<ModelCriteriaBuilder<GroupModel>> modifier, UnaryOperator<QueryParameters<GroupModel>> queryParametersModifier) {
private Stream<GroupModel> getGroupsStreamInternal(RealmModel realm, UnaryOperator<DefaultModelCriteria<GroupModel>> modifier, UnaryOperator<QueryParameters<GroupModel>> queryParametersModifier) {
LOG.tracef("getGroupsStream(%s)%s", realm, getShortStackTrace());
ModelCriteriaBuilder<GroupModel> mcb = criteria();
DefaultModelCriteria<GroupModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId());
if (modifier != null) {
@ -101,7 +101,7 @@ public class MapGroupProvider implements GroupProvider {
@Override
public Stream<GroupModel> getGroupsStream(RealmModel realm, Stream<String> ids, String search, Integer first, Integer max) {
ModelCriteriaBuilder<GroupModel> mcb = criteria();
DefaultModelCriteria<GroupModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.ID, Operator.IN, ids)
.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId());
@ -116,7 +116,7 @@ public class MapGroupProvider implements GroupProvider {
@Override
public Long getGroupsCount(RealmModel realm, Boolean onlyTopGroups) {
LOG.tracef("getGroupsCount(%s, %s)%s", realm, onlyTopGroups, getShortStackTrace());
ModelCriteriaBuilder<GroupModel> mcb = criteria();
DefaultModelCriteria<GroupModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId());
if (Objects.equals(onlyTopGroups, Boolean.TRUE)) {
@ -128,7 +128,7 @@ public class MapGroupProvider implements GroupProvider {
@Override
public Long getGroupsCountByNameContaining(RealmModel realm, String search) {
ModelCriteriaBuilder<GroupModel> mcb = criteria();
DefaultModelCriteria<GroupModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.NAME, Operator.ILIKE, "%" + search + "%");
@ -139,7 +139,7 @@ public class MapGroupProvider implements GroupProvider {
public Stream<GroupModel> getGroupsByRoleStream(RealmModel realm, RoleModel role, Integer firstResult, Integer maxResults) {
LOG.tracef("getGroupsByRole(%s, %s, %d, %d)%s", realm, role, firstResult, maxResults, getShortStackTrace());
return getGroupsStreamInternal(realm,
(ModelCriteriaBuilder<GroupModel> mcb) -> mcb.compare(SearchableFields.ASSIGNED_ROLE, Operator.EQ, role.getId()),
(DefaultModelCriteria<GroupModel> mcb) -> mcb.compare(SearchableFields.ASSIGNED_ROLE, Operator.EQ, role.getId()),
qp -> qp.offset(firstResult).limit(maxResults)
);
}
@ -148,7 +148,7 @@ public class MapGroupProvider implements GroupProvider {
public Stream<GroupModel> getTopLevelGroupsStream(RealmModel realm) {
LOG.tracef("getTopLevelGroupsStream(%s)%s", realm, getShortStackTrace());
return getGroupsStreamInternal(realm,
(ModelCriteriaBuilder<GroupModel> mcb) -> mcb.compare(SearchableFields.PARENT_ID, Operator.NOT_EXISTS),
(DefaultModelCriteria<GroupModel> mcb) -> mcb.compare(SearchableFields.PARENT_ID, Operator.NOT_EXISTS),
null
);
}
@ -157,7 +157,7 @@ public class MapGroupProvider implements GroupProvider {
public Stream<GroupModel> getTopLevelGroupsStream(RealmModel realm, Integer firstResult, Integer maxResults) {
LOG.tracef("getTopLevelGroupsStream(%s, %s, %s)%s", realm, firstResult, maxResults, getShortStackTrace());
return getGroupsStreamInternal(realm,
(ModelCriteriaBuilder<GroupModel> mcb) -> mcb.compare(SearchableFields.PARENT_ID, Operator.NOT_EXISTS),
(DefaultModelCriteria<GroupModel> mcb) -> mcb.compare(SearchableFields.PARENT_ID, Operator.NOT_EXISTS),
qp -> qp.offset(firstResult).limit(maxResults)
);
}
@ -167,7 +167,7 @@ public class MapGroupProvider implements GroupProvider {
LOG.tracef("searchForGroupByNameStream(%s, %s, %d, %d)%s", realm, search, firstResult, maxResults, getShortStackTrace());
ModelCriteriaBuilder<GroupModel> mcb = criteria();
DefaultModelCriteria<GroupModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.NAME, Operator.ILIKE, "%" + search + "%");
@ -188,7 +188,7 @@ public class MapGroupProvider implements GroupProvider {
LOG.tracef("createGroup(%s, %s, %s, %s)%s", realm, id, name, toParent, getShortStackTrace());
// Check Db constraint: uniqueConstraints = { @UniqueConstraint(columnNames = {"REALM_ID", "PARENT_GROUP", "NAME"})}
String parentId = toParent == null ? null : toParent.getId();
ModelCriteriaBuilder<GroupModel> mcb = criteria();
DefaultModelCriteria<GroupModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.PARENT_ID, Operator.EQ, parentId)
.compare(SearchableFields.NAME, Operator.EQ, name);
@ -255,7 +255,7 @@ public class MapGroupProvider implements GroupProvider {
}
String parentId = toParent == null ? null : toParent.getId();
ModelCriteriaBuilder<GroupModel> mcb = criteria();
DefaultModelCriteria<GroupModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.PARENT_ID, Operator.EQ, parentId)
.compare(SearchableFields.NAME, Operator.EQ, group.getName());
@ -277,7 +277,7 @@ public class MapGroupProvider implements GroupProvider {
public void addTopLevelGroup(RealmModel realm, GroupModel subGroup) {
LOG.tracef("addTopLevelGroup(%s, %s)%s", realm, subGroup, getShortStackTrace());
ModelCriteriaBuilder<GroupModel> mcb = criteria();
DefaultModelCriteria<GroupModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.PARENT_ID, Operator.EQ, (Object) null)
.compare(SearchableFields.NAME, Operator.EQ, subGroup.getName());
@ -293,7 +293,7 @@ public class MapGroupProvider implements GroupProvider {
public void preRemove(RealmModel realm, RoleModel role) {
LOG.tracef("preRemove(%s, %s)%s", realm, role, getShortStackTrace());
ModelCriteriaBuilder<GroupModel> mcb = criteria();
DefaultModelCriteria<GroupModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.ASSIGNED_ROLE, Operator.EQ, role.getId());
try (Stream<MapGroupEntity> toRemove = tx.read(withCriteria(mcb))) {

View file

@ -23,8 +23,9 @@ import org.keycloak.models.RealmModel;
import org.keycloak.models.UserLoginFailureModel;
import org.keycloak.models.map.storage.MapKeycloakTransaction;
import org.keycloak.models.map.storage.MapStorage;
import org.keycloak.models.map.storage.ModelCriteriaBuilder;
import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator;
import org.keycloak.models.map.storage.criteria.DefaultModelCriteria;
import java.util.function.Function;
import static org.keycloak.common.util.StackUtil.getShortStackTrace;
@ -54,9 +55,9 @@ public class MapUserLoginFailureProvider implements UserLoginFailureProvider {
@Override
public UserLoginFailureModel getUserLoginFailure(RealmModel realm, String userId) {
ModelCriteriaBuilder<UserLoginFailureModel> mcb = criteria();
mcb = mcb.compare(UserLoginFailureModel.SearchableFields.REALM_ID, ModelCriteriaBuilder.Operator.EQ, realm.getId())
.compare(UserLoginFailureModel.SearchableFields.USER_ID, ModelCriteriaBuilder.Operator.EQ, userId);
DefaultModelCriteria<UserLoginFailureModel> mcb = criteria();
mcb = mcb.compare(UserLoginFailureModel.SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(UserLoginFailureModel.SearchableFields.USER_ID, Operator.EQ, userId);
LOG.tracef("getUserLoginFailure(%s, %s)%s", realm, userId, getShortStackTrace());
@ -68,9 +69,9 @@ public class MapUserLoginFailureProvider implements UserLoginFailureProvider {
@Override
public UserLoginFailureModel addUserLoginFailure(RealmModel realm, String userId) {
ModelCriteriaBuilder<UserLoginFailureModel> mcb = criteria();
mcb = mcb.compare(UserLoginFailureModel.SearchableFields.REALM_ID, ModelCriteriaBuilder.Operator.EQ, realm.getId())
.compare(UserLoginFailureModel.SearchableFields.USER_ID, ModelCriteriaBuilder.Operator.EQ, userId);
DefaultModelCriteria<UserLoginFailureModel> mcb = criteria();
mcb = mcb.compare(UserLoginFailureModel.SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(UserLoginFailureModel.SearchableFields.USER_ID, Operator.EQ, userId);
LOG.tracef("addUserLoginFailure(%s, %s)%s", realm, userId, getShortStackTrace());
@ -87,9 +88,9 @@ public class MapUserLoginFailureProvider implements UserLoginFailureProvider {
@Override
public void removeUserLoginFailure(RealmModel realm, String userId) {
ModelCriteriaBuilder<UserLoginFailureModel> mcb = criteria();
mcb = mcb.compare(UserLoginFailureModel.SearchableFields.REALM_ID, ModelCriteriaBuilder.Operator.EQ, realm.getId())
.compare(UserLoginFailureModel.SearchableFields.USER_ID, ModelCriteriaBuilder.Operator.EQ, userId);
DefaultModelCriteria<UserLoginFailureModel> mcb = criteria();
mcb = mcb.compare(UserLoginFailureModel.SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(UserLoginFailureModel.SearchableFields.USER_ID, Operator.EQ, userId);
LOG.tracef("removeUserLoginFailure(%s, %s)%s", realm, userId, getShortStackTrace());
@ -98,8 +99,8 @@ public class MapUserLoginFailureProvider implements UserLoginFailureProvider {
@Override
public void removeAllUserLoginFailures(RealmModel realm) {
ModelCriteriaBuilder<UserLoginFailureModel> mcb = criteria();
mcb = mcb.compare(UserLoginFailureModel.SearchableFields.REALM_ID, ModelCriteriaBuilder.Operator.EQ, realm.getId());
DefaultModelCriteria<UserLoginFailureModel> mcb = criteria();
mcb = mcb.compare(UserLoginFailureModel.SearchableFields.REALM_ID, Operator.EQ, realm.getId());
LOG.tracef("removeAllUserLoginFailures(%s)%s", realm, getShortStackTrace());

View file

@ -34,8 +34,8 @@ import org.keycloak.models.RealmProvider;
import org.keycloak.models.RoleModel;
import org.keycloak.models.map.storage.MapKeycloakTransaction;
import org.keycloak.models.map.storage.MapStorage;
import org.keycloak.models.map.storage.ModelCriteriaBuilder;
import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator;
import org.keycloak.models.map.storage.criteria.DefaultModelCriteria;
import org.keycloak.models.utils.KeycloakModelUtils;
import static org.keycloak.models.map.storage.QueryParameters.Order.ASCENDING;
import static org.keycloak.models.map.storage.QueryParameters.withCriteria;
@ -97,7 +97,7 @@ public class MapRealmProvider implements RealmProvider {
LOG.tracef("getRealmByName(%s)%s", name, getShortStackTrace());
ModelCriteriaBuilder<RealmModel> mcb = criteria();
DefaultModelCriteria<RealmModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.NAME, Operator.EQ, name);
String realmId = tx.read(withCriteria(mcb))
@ -115,13 +115,13 @@ public class MapRealmProvider implements RealmProvider {
@Override
public Stream<RealmModel> getRealmsWithProviderTypeStream(Class<?> type) {
ModelCriteriaBuilder<RealmModel> mcb = criteria();
DefaultModelCriteria<RealmModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.COMPONENT_PROVIDER_TYPE, Operator.EQ, type.getName());
return getRealmsStream(mcb);
}
private Stream<RealmModel> getRealmsStream(ModelCriteriaBuilder<RealmModel> mcb) {
private Stream<RealmModel> getRealmsStream(DefaultModelCriteria<RealmModel> mcb) {
return tx.read(withCriteria(mcb).orderBy(SearchableFields.NAME, ASCENDING))
.map(this::entityToAdapter);
}
@ -160,7 +160,7 @@ public class MapRealmProvider implements RealmProvider {
@Override
public void removeExpiredClientInitialAccess() {
ModelCriteriaBuilder<RealmModel> mcb = criteria();
DefaultModelCriteria<RealmModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.CLIENT_INITIAL_ACCESS, Operator.EXISTS);
tx.read(withCriteria(mcb))

View file

@ -38,8 +38,8 @@ import static org.keycloak.models.map.storage.criteria.DefaultModelCriteria.crit
import org.keycloak.models.RoleContainerModel;
import org.keycloak.models.RoleModel.SearchableFields;
import org.keycloak.models.RoleProvider;
import org.keycloak.models.map.storage.ModelCriteriaBuilder;
import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator;
import org.keycloak.models.map.storage.criteria.DefaultModelCriteria;
public class MapRoleProvider implements RoleProvider {
@ -78,7 +78,7 @@ public class MapRoleProvider implements RoleProvider {
@Override
public Stream<RoleModel> getRealmRolesStream(RealmModel realm, Integer first, Integer max) {
ModelCriteriaBuilder<RoleModel> mcb = criteria();
DefaultModelCriteria<RoleModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.IS_CLIENT_ROLE, Operator.NE, true);
@ -91,7 +91,7 @@ public class MapRoleProvider implements RoleProvider {
LOG.tracef("getRolesStream(%s, %s, %s, %d, %d)%s", realm, ids, search, first, max, getShortStackTrace());
if (ids == null) return Stream.empty();
ModelCriteriaBuilder<RoleModel> mcb = criteria();
DefaultModelCriteria<RoleModel> mcb = criteria();
mcb = mcb.compare(RoleModel.SearchableFields.ID, Operator.IN, ids)
.compare(RoleModel.SearchableFields.REALM_ID, Operator.EQ, realm.getId());
@ -105,7 +105,7 @@ public class MapRoleProvider implements RoleProvider {
@Override
public Stream<RoleModel> getRealmRolesStream(RealmModel realm) {
ModelCriteriaBuilder<RoleModel> mcb = criteria();
DefaultModelCriteria<RoleModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.IS_CLIENT_ROLE, Operator.NE, true);
@ -134,7 +134,7 @@ public class MapRoleProvider implements RoleProvider {
@Override
public Stream<RoleModel> getClientRolesStream(ClientModel client, Integer first, Integer max) {
ModelCriteriaBuilder<RoleModel> mcb = criteria();
DefaultModelCriteria<RoleModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, client.getRealm().getId())
.compare(SearchableFields.CLIENT_ID, Operator.EQ, client.getId());
@ -144,7 +144,7 @@ public class MapRoleProvider implements RoleProvider {
@Override
public Stream<RoleModel> getClientRolesStream(ClientModel client) {
ModelCriteriaBuilder<RoleModel> mcb = criteria();
DefaultModelCriteria<RoleModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, client.getRealm().getId())
.compare(SearchableFields.CLIENT_ID, Operator.EQ, client.getId());
@ -195,7 +195,7 @@ public class MapRoleProvider implements RoleProvider {
}
LOG.tracef("getRealmRole(%s, %s)%s", realm, name, getShortStackTrace());
ModelCriteriaBuilder<RoleModel> mcb = criteria();
DefaultModelCriteria<RoleModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.NAME, Operator.ILIKE, name);
@ -215,7 +215,7 @@ public class MapRoleProvider implements RoleProvider {
}
LOG.tracef("getClientRole(%s, %s)%s", client, name, getShortStackTrace());
ModelCriteriaBuilder<RoleModel> mcb = criteria();
DefaultModelCriteria<RoleModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, client.getRealm().getId())
.compare(SearchableFields.CLIENT_ID, Operator.EQ, client.getId())
.compare(SearchableFields.NAME, Operator.ILIKE, name);
@ -249,7 +249,7 @@ public class MapRoleProvider implements RoleProvider {
if (search == null) {
return Stream.empty();
}
ModelCriteriaBuilder<RoleModel> mcb = criteria();
DefaultModelCriteria<RoleModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.or(
mcb.compare(SearchableFields.NAME, Operator.ILIKE, "%" + search + "%"),
@ -265,7 +265,7 @@ public class MapRoleProvider implements RoleProvider {
if (search == null) {
return Stream.empty();
}
ModelCriteriaBuilder<RoleModel> mcb = criteria();
DefaultModelCriteria<RoleModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, client.getRealm().getId())
.compare(SearchableFields.CLIENT_ID, Operator.EQ, client.getId())
.or(

View file

@ -51,7 +51,7 @@ import org.keycloak.storage.SearchableModelField;
*
* @author hmlnarik
*/
public interface ModelCriteriaBuilder<M> {
public interface ModelCriteriaBuilder<M, Self extends ModelCriteriaBuilder<M, Self>> {
/**
* The operators are very basic ones for this use case. In the real scenario,
@ -117,7 +117,7 @@ public interface ModelCriteriaBuilder<M> {
* @return
* @throws CriterionNotSupported If the operator is not supported for the given field.
*/
ModelCriteriaBuilder<M> compare(SearchableModelField<? super M> modelField, Operator op, Object... value);
Self compare(SearchableModelField<? super M> modelField, Operator op, Object... value);
/**
* Creates and returns a new instance of {@code ModelCriteriaBuilder} that
@ -136,7 +136,7 @@ public interface ModelCriteriaBuilder<M> {
*
* @throws CriterionNotSupported If the operator is not supported for the given field.
*/
ModelCriteriaBuilder<M> and(ModelCriteriaBuilder<M>... builders);
Self and(Self... builders);
/**
* Creates and returns a new instance of {@code ModelCriteriaBuilder} that
@ -155,7 +155,7 @@ public interface ModelCriteriaBuilder<M> {
*
* @throws CriterionNotSupported If the operator is not supported for the given field.
*/
ModelCriteriaBuilder<M> or(ModelCriteriaBuilder<M>... builders);
Self or(Self... builders);
/**
* Creates and returns a new instance of {@code ModelCriteriaBuilder} that
@ -168,6 +168,6 @@ public interface ModelCriteriaBuilder<M> {
* @return
* @throws CriterionNotSupported If the operator is not supported for the given field.
*/
ModelCriteriaBuilder<M> not(ModelCriteriaBuilder<M> builder);
Self not(Self builder);
}

View file

@ -1,5 +1,6 @@
package org.keycloak.models.map.storage;
import org.keycloak.models.map.storage.criteria.DefaultModelCriteria;
import org.keycloak.storage.SearchableModelField;
import java.util.LinkedList;
@ -19,12 +20,12 @@ public class QueryParameters<M> {
private Integer offset;
private Integer limit;
private final List<OrderBy<M>> orderBy = new LinkedList<>();
private ModelCriteriaBuilder<M> mcb;
private DefaultModelCriteria<M> mcb;
public QueryParameters() {
}
public QueryParameters(ModelCriteriaBuilder<M> mcb) {
public QueryParameters(DefaultModelCriteria<M> mcb) {
this.mcb = mcb;
}
@ -35,7 +36,7 @@ public class QueryParameters<M> {
* @param <M> model type
* @return a new {@code QueryParameters} instance
*/
public static <M> QueryParameters<M> withCriteria(ModelCriteriaBuilder<M> mcb) {
public static <M> QueryParameters<M> withCriteria(DefaultModelCriteria<M> mcb) {
return new QueryParameters<>(mcb);
}
@ -98,7 +99,7 @@ public class QueryParameters<M> {
return limit;
}
public ModelCriteriaBuilder<M> getModelCriteriaBuilder() {
public DefaultModelCriteria<M> getModelCriteriaBuilder() {
return mcb;
}

View file

@ -167,8 +167,8 @@ public class ConcurrentHashMapKeycloakTransaction<K, V extends AbstractEntity &
*/
@Override
public Stream<V> read(QueryParameters<M> queryParameters) {
DefaultModelCriteria<M> mcb = (DefaultModelCriteria<M>) queryParameters.getModelCriteriaBuilder();
MapModelCriteriaBuilder<K,V,M> mapMcb = (MapModelCriteriaBuilder<K,V,M>) mcb.flashToModelCriteriaBuilder(map.createCriteriaBuilder());
DefaultModelCriteria<M> mcb = queryParameters.getModelCriteriaBuilder();
MapModelCriteriaBuilder<K,V,M> mapMcb = mcb.flashToModelCriteriaBuilder(map.createCriteriaBuilder());
Predicate<? super V> filterOutAllBulkDeletedObjects = tasks.values().stream()
.filter(BulkDeleteOperation.class::isInstance)
@ -400,8 +400,8 @@ public class ConcurrentHashMapKeycloakTransaction<K, V extends AbstractEntity &
}
public Predicate<V> getFilterForNonDeletedObjects() {
DefaultModelCriteria<M> mcb = (DefaultModelCriteria<M>) queryParameters.getModelCriteriaBuilder();
MapModelCriteriaBuilder<K,V,M> mmcb = (MapModelCriteriaBuilder<K,V,M>) mcb.flashToModelCriteriaBuilder(map.createCriteriaBuilder());
DefaultModelCriteria<M> mcb = queryParameters.getModelCriteriaBuilder();
MapModelCriteriaBuilder<K,V,M> mmcb = mcb.flashToModelCriteriaBuilder(map.createCriteriaBuilder());
Predicate<? super V> entityFilter = mmcb.getEntityFilter();
Predicate<? super K> keyFilter = mmcb.getKeyFilter();

View file

@ -23,7 +23,6 @@ import org.keycloak.models.map.common.AbstractEntity;
import org.keycloak.models.map.common.DeepCloner;
import org.keycloak.models.map.common.UpdatableEntity;
import org.keycloak.models.map.storage.MapStorage;
import org.keycloak.models.map.storage.ModelCriteriaBuilder;
import org.keycloak.models.map.storage.QueryParameters;
import org.keycloak.models.map.storage.criteria.DefaultModelCriteria;
import org.keycloak.storage.SearchableModelField;
@ -126,7 +125,7 @@ public class ConcurrentHashMapStorage<K, V extends AbstractEntity & UpdatableEnt
* @return Number of removed objects (might return {@code -1} if not supported)
*/
public long delete(QueryParameters<M> queryParameters) {
DefaultModelCriteria<M> criteria = (DefaultModelCriteria<M>) queryParameters.getModelCriteriaBuilder();
DefaultModelCriteria<M> criteria = queryParameters.getModelCriteriaBuilder();
if (criteria == null) {
long res = store.size();
@ -135,7 +134,7 @@ public class ConcurrentHashMapStorage<K, V extends AbstractEntity & UpdatableEnt
}
@SuppressWarnings("unchecked")
MapModelCriteriaBuilder<K,V,M> mcb = (MapModelCriteriaBuilder<K,V,M>) criteria.flashToModelCriteriaBuilder(createCriteriaBuilder());
MapModelCriteriaBuilder<K,V,M> mcb = criteria.flashToModelCriteriaBuilder(createCriteriaBuilder());
Predicate<? super K> keyFilter = mcb.getKeyFilter();
Predicate<? super V> entityFilter = mcb.getEntityFilter();
Stream<Entry<K, V>> storeStream = store.entrySet().stream();
@ -162,7 +161,7 @@ public class ConcurrentHashMapStorage<K, V extends AbstractEntity & UpdatableEnt
return sessionTransaction == null ? new ConcurrentHashMapKeycloakTransaction<>(this, keyConvertor, cloner) : sessionTransaction;
}
public ModelCriteriaBuilder<M> createCriteriaBuilder() {
public MapModelCriteriaBuilder<K, V, M> createCriteriaBuilder() {
return new MapModelCriteriaBuilder<>(keyConvertor, fieldPredicates);
}
@ -178,13 +177,13 @@ public class ConcurrentHashMapStorage<K, V extends AbstractEntity & UpdatableEnt
* @return Stream of objects. Never returns {@code null}.
*/
public Stream<V> read(QueryParameters<M> queryParameters) {
DefaultModelCriteria<M> criteria = (DefaultModelCriteria<M>) queryParameters.getModelCriteriaBuilder();
DefaultModelCriteria<M> criteria = queryParameters.getModelCriteriaBuilder();
if (criteria == null) {
return Stream.empty();
}
MapModelCriteriaBuilder<K,V,M> mcb = (MapModelCriteriaBuilder<K,V,M>) criteria.flashToModelCriteriaBuilder(createCriteriaBuilder());
MapModelCriteriaBuilder<K,V,M> mcb = criteria.flashToModelCriteriaBuilder(createCriteriaBuilder());
Stream<Entry<K, V>> stream = store.entrySet().stream();
Predicate<? super K> keyFilter = mcb.getKeyFilter();

View file

@ -65,12 +65,12 @@ import java.util.concurrent.ConcurrentHashMap;
import org.jboss.logging.Logger;
import org.keycloak.models.map.storage.MapStorageProvider;
import org.keycloak.models.map.storage.MapStorageProviderFactory;
import org.keycloak.models.map.storage.ModelCriteriaBuilder;
import org.keycloak.models.map.userSession.MapAuthenticatedClientSessionEntity;
import org.keycloak.models.map.user.MapUserEntity;
import org.keycloak.models.map.userSession.MapUserSessionEntity;
import org.keycloak.provider.EnvironmentDependentProviderFactory;
import org.keycloak.provider.ProviderConfigProperty;
import org.keycloak.models.map.storage.criteria.DefaultModelCriteria;
import org.keycloak.sessions.RootAuthenticationSessionModel;
import java.util.Collections;
import java.util.HashMap;
@ -241,7 +241,7 @@ public class ConcurrentHashMapStorageProviderFactory implements AmphibianProvide
try {
if (storageDirectory != null) {
LOG.debugf("Storing contents to %s", f.getCanonicalPath());
final ModelCriteriaBuilder readAllCriteria = criteria();
final DefaultModelCriteria readAllCriteria = criteria();
Serialization.MAPPER.writeValue(f, store.read(withCriteria(readAllCriteria)));
} else {
LOG.debugf("Not storing contents of %s because directory not set", mapName);

View file

@ -32,7 +32,7 @@ import java.util.stream.Collectors;
*
* @author hmlnarik
*/
public class MapModelCriteriaBuilder<K, V extends AbstractEntity, M> implements ModelCriteriaBuilder<M> {
public class MapModelCriteriaBuilder<K, V extends AbstractEntity, M> implements ModelCriteriaBuilder<M, MapModelCriteriaBuilder<K, V, M>> {
@FunctionalInterface
public static interface UpdatePredicatesFunc<K, V extends AbstractEntity, M> {
@ -70,7 +70,7 @@ public class MapModelCriteriaBuilder<K, V extends AbstractEntity, M> implements
@SafeVarargs
@SuppressWarnings("unchecked")
@Override
public final MapModelCriteriaBuilder<K, V, M> and(ModelCriteriaBuilder<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<V> resEntityFilter = Stream.of(builders).map(MapModelCriteriaBuilder.class::cast).map(MapModelCriteriaBuilder::getEntityFilter).reduce(entityFilter, Predicate::and);
return new MapModelCriteriaBuilder<>(keyConvertor, fieldPredicates, resIndexFilter, resEntityFilter);
@ -79,7 +79,7 @@ public class MapModelCriteriaBuilder<K, V extends AbstractEntity, M> implements
@SafeVarargs
@SuppressWarnings("unchecked")
@Override
public final MapModelCriteriaBuilder<K, V, M> or(ModelCriteriaBuilder<M>... builders) {
public final MapModelCriteriaBuilder<K, V, M> or(MapModelCriteriaBuilder<K, V, M>... builders) {
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);
return new MapModelCriteriaBuilder<>(
@ -92,10 +92,10 @@ public class MapModelCriteriaBuilder<K, V extends AbstractEntity, M> implements
@SuppressWarnings("unchecked")
@Override
public MapModelCriteriaBuilder<K, V, M> not(ModelCriteriaBuilder<M> builder) {
public MapModelCriteriaBuilder<K, V, M> not(MapModelCriteriaBuilder<K, V, M> builder) {
MapModelCriteriaBuilder<K, V, M> b = (MapModelCriteriaBuilder<K, V, M>) builder;
Predicate<? super K> resIndexFilter = b.getKeyFilter() == ALWAYS_TRUE ? ALWAYS_TRUE : b.getKeyFilter().negate();
Predicate<? super V> resEntityFilter = b.getEntityFilter() == ALWAYS_TRUE ? ALWAYS_TRUE : b.getEntityFilter().negate();
Predicate<? super K> resIndexFilter = builder.getKeyFilter() == ALWAYS_TRUE ? ALWAYS_TRUE : builder.getKeyFilter().negate();
Predicate<? super V> resEntityFilter = builder.getEntityFilter() == ALWAYS_TRUE ? ALWAYS_TRUE : builder.getEntityFilter().negate();
return new MapModelCriteriaBuilder<>(
keyConvertor,

View file

@ -23,7 +23,6 @@ import org.keycloak.models.UserSessionModel;
import org.keycloak.models.map.common.AbstractEntity;
import org.keycloak.models.map.common.DeepCloner;
import org.keycloak.models.map.storage.MapKeycloakTransaction;
import org.keycloak.models.map.storage.ModelCriteriaBuilder;
import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator;
import org.keycloak.models.map.storage.QueryParameters;
import org.keycloak.models.map.storage.criteria.DefaultModelCriteria;
@ -56,7 +55,7 @@ public class UserSessionConcurrentHashMapStorage<K> extends ConcurrentHashMapSto
@Override
public long delete(QueryParameters<UserSessionModel> queryParameters) {
Set<String> ids = read(queryParameters).map(AbstractEntity::getId).collect(Collectors.toSet());
ModelCriteriaBuilder<AuthenticatedClientSessionModel> csMcb = DefaultModelCriteria.<AuthenticatedClientSessionModel>criteria()
DefaultModelCriteria<AuthenticatedClientSessionModel> csMcb = DefaultModelCriteria.<AuthenticatedClientSessionModel>criteria()
.compare(AuthenticatedClientSessionModel.SearchableFields.USER_SESSION_ID, Operator.IN, ids);
clientSessionTr.delete(withCriteria(csMcb));
return super.delete(queryParameters);
@ -64,7 +63,7 @@ public class UserSessionConcurrentHashMapStorage<K> extends ConcurrentHashMapSto
@Override
public boolean delete(String key) {
ModelCriteriaBuilder<AuthenticatedClientSessionModel> csMcb = DefaultModelCriteria.<AuthenticatedClientSessionModel>criteria()
DefaultModelCriteria<AuthenticatedClientSessionModel> csMcb = DefaultModelCriteria.<AuthenticatedClientSessionModel>criteria()
.compare(AuthenticatedClientSessionModel.SearchableFields.USER_SESSION_ID, Operator.EQ, key);
clientSessionTr.delete(withCriteria(csMcb));
return super.delete(key);

View file

@ -26,7 +26,7 @@ import java.util.stream.Stream;
* Descriptive model criteria implementation which in other words represents a Boolean formula on searchable fields.
* @author hmlnarik
*/
public class DefaultModelCriteria<M> implements ModelCriteriaBuilder<M> {
public class DefaultModelCriteria<M> implements ModelCriteriaBuilder<M, DefaultModelCriteria<M>> {
private static final DefaultModelCriteria<?> INSTANCE = new DefaultModelCriteria<>(null);
@ -63,18 +63,15 @@ public class DefaultModelCriteria<M> implements ModelCriteriaBuilder<M> {
}
@Override
public DefaultModelCriteria<M> and(ModelCriteriaBuilder<M>... mcbs) {
public DefaultModelCriteria<M> and(DefaultModelCriteria<M>... mcbs) {
if (mcbs.length == 1) {
ModelCriteriaNode<M> toBeChild = ((DefaultModelCriteria<M>) mcbs[0]).node;
if (toBeChild.getNodeOperator() == ExtOperator.AND || toBeChild.getNodeOperator() == ExtOperator.OR) {
return (DefaultModelCriteria<M>) mcbs[0];
}
return compare(mcbs[0].node);
}
final ModelCriteriaNode<M> targetNode = new ModelCriteriaNode<>(ExtOperator.AND);
AtomicBoolean hasFalseNode = new AtomicBoolean(false);
for (ModelCriteriaBuilder<M> mcb : mcbs) {
final ModelCriteriaNode<M> nodeToAdd = ((DefaultModelCriteria<M>) mcb).node;
for (DefaultModelCriteria<M> mcb : mcbs) {
final ModelCriteriaNode<M> nodeToAdd = mcb.node;
getNodesToAddForAndOr(nodeToAdd, ExtOperator.AND)
.filter(ModelCriteriaNode::isNotTrueNode)
.peek(n -> { if (n.isFalseNode()) hasFalseNode.lazySet(true); })
@ -95,18 +92,15 @@ public class DefaultModelCriteria<M> implements ModelCriteriaBuilder<M> {
}
@Override
public DefaultModelCriteria<M> or(ModelCriteriaBuilder<M>... mcbs) {
public DefaultModelCriteria<M> or(DefaultModelCriteria<M>... mcbs) {
if (mcbs.length == 1) {
ModelCriteriaNode<M> toBeChild = ((DefaultModelCriteria<M>) mcbs[0]).node;
if (toBeChild.getNodeOperator() == ExtOperator.AND || toBeChild.getNodeOperator() == ExtOperator.OR) {
return ((DefaultModelCriteria<M>) mcbs[0]);
}
return compare(mcbs[0].node);
}
final ModelCriteriaNode<M> targetNode = new ModelCriteriaNode<>(ExtOperator.OR);
AtomicBoolean hasTrueNode = new AtomicBoolean(false);
for (ModelCriteriaBuilder<M> mcb : mcbs) {
final ModelCriteriaNode<M> nodeToAdd = ((DefaultModelCriteria<M>) mcb).node;
for (DefaultModelCriteria<M> mcb : mcbs) {
final ModelCriteriaNode<M> nodeToAdd = mcb.node;
getNodesToAddForAndOr(nodeToAdd, ExtOperator.OR)
.filter(ModelCriteriaNode::isNotFalseNode)
.peek(n -> { if (n.isTrueNode()) hasTrueNode.lazySet(true); })
@ -127,12 +121,13 @@ public class DefaultModelCriteria<M> implements ModelCriteriaBuilder<M> {
}
@Override
public DefaultModelCriteria<M> not(ModelCriteriaBuilder<M> mcb) {
final ModelCriteriaNode<M> targetNode = new ModelCriteriaNode<>(ExtOperator.NOT);
ModelCriteriaNode<M> toBeChild = ((DefaultModelCriteria<M>) mcb).node;
public DefaultModelCriteria<M> not(DefaultModelCriteria<M> mcb) {
ModelCriteriaNode<M> toBeChild = mcb.node;
if (toBeChild.getNodeOperator() == ExtOperator.NOT) {
return compare(toBeChild.getChildren().get(0).cloneTree());
}
final ModelCriteriaNode<M> targetNode = new ModelCriteriaNode<>(ExtOperator.NOT);
targetNode.addChild(toBeChild.cloneTree());
return compare(targetNode);
}
@ -143,7 +138,7 @@ public class DefaultModelCriteria<M> implements ModelCriteriaBuilder<M> {
* @param mcb {@code ModelCriteriaBuilder} to copy the contents onto
* @return Updated {@code ModelCriteriaBuilder}
*/
public <C extends ModelCriteriaBuilder<M>> C flashToModelCriteriaBuilder(C mcb) {
public <C extends ModelCriteriaBuilder<M, C>> C flashToModelCriteriaBuilder(C mcb) {
if (isEmpty()) {
return mcb;
}

View file

@ -20,6 +20,7 @@ import org.keycloak.models.map.storage.ModelCriteriaBuilder;
import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator;
import org.keycloak.models.map.storage.tree.DefaultTreeNode;
import org.keycloak.storage.SearchableModelField;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Collections;
import java.util.Objects;
@ -35,45 +36,45 @@ public class ModelCriteriaNode<M> extends DefaultTreeNode<ModelCriteriaNode<M>>
public static enum ExtOperator {
AND {
@Override public <M, C extends ModelCriteriaBuilder<M>> C apply(C mcb, ModelCriteriaNode<M> node) {
@Override public <M, C extends ModelCriteriaBuilder<M, C>> C apply(C mcb, ModelCriteriaNode<M> node) {
if (node.getChildren().isEmpty()) {
return null;
}
final ModelCriteriaBuilder[] operands = node.getChildren().stream()
final C[] operands = node.getChildren().stream()
.map(n -> n.flashToModelCriteriaBuilder(mcb))
.filter(Objects::nonNull)
.toArray(ModelCriteriaBuilder[]::new);
return operands.length == 0 ? null : (C) mcb.and(operands);
.toArray(n -> (C[]) Array.newInstance(mcb.getClass(), n));
return operands.length == 0 ? null : mcb.and(operands);
}
@Override public String toString(ModelCriteriaNode<?> node) {
return "(" + node.getChildren().stream().map(ModelCriteriaNode::toString).collect(Collectors.joining(" && ")) + ")";
}
},
OR {
@Override public <M, C extends ModelCriteriaBuilder<M>> C apply(C mcb, ModelCriteriaNode<M> node) {
@Override public <M, C extends ModelCriteriaBuilder<M, C>> C apply(C mcb, ModelCriteriaNode<M> node) {
if (node.getChildren().isEmpty()) {
return null;
}
final ModelCriteriaBuilder[] operands = node.getChildren().stream()
final C[] operands = node.getChildren().stream()
.map(n -> n.flashToModelCriteriaBuilder(mcb))
.filter(Objects::nonNull)
.toArray(ModelCriteriaBuilder[]::new);
return operands.length == 0 ? null : (C) mcb.or(operands);
.toArray(n -> (C[]) Array.newInstance(mcb.getClass(), n));
return operands.length == 0 ? null : mcb.or(operands);
}
@Override public String toString(ModelCriteriaNode<?> node) {
return "(" + node.getChildren().stream().map(ModelCriteriaNode::toString).collect(Collectors.joining(" || ")) + ")";
}
},
NOT {
@Override public <M, C extends ModelCriteriaBuilder<M>> C apply(C mcb, ModelCriteriaNode<M> node) {
return (C) mcb.not(node.getChildren().iterator().next().flashToModelCriteriaBuilder(mcb));
@Override public <M, C extends ModelCriteriaBuilder<M, C>> C apply(C mcb, ModelCriteriaNode<M> node) {
return mcb.not(node.getChildren().iterator().next().flashToModelCriteriaBuilder(mcb));
}
@Override public String toString(ModelCriteriaNode<?> node) {
return "! " + node.getChildren().iterator().next().toString();
}
},
ATOMIC_FORMULA {
@Override public <M, C extends ModelCriteriaBuilder<M>> C apply(C mcb, ModelCriteriaNode<M> node) {
@Override public <M, C extends ModelCriteriaBuilder<M, C>> C apply(C mcb, ModelCriteriaNode<M> node) {
return (C) mcb.compare(
node.field,
node.simpleOperator,
@ -85,16 +86,16 @@ public class ModelCriteriaNode<M> extends DefaultTreeNode<ModelCriteriaNode<M>>
}
},
__FALSE__ {
@Override public <M, C extends ModelCriteriaBuilder<M>> C apply(C mcb, ModelCriteriaNode<M> node) {
return (C) mcb.or();
@Override public <M, C extends ModelCriteriaBuilder<M, C>> C apply(C mcb, ModelCriteriaNode<M> node) {
return mcb.or((C[]) Array.newInstance(mcb.getClass(), 0));
}
@Override public String toString(ModelCriteriaNode<?> node) {
return "__FALSE__";
}
},
__TRUE__ {
@Override public <M, C extends ModelCriteriaBuilder<M>> C apply(C mcb, ModelCriteriaNode<M> node) {
return (C) mcb.and();
@Override public <M, C extends ModelCriteriaBuilder<M, C>> C apply(C mcb, ModelCriteriaNode<M> node) {
return mcb.and((C[]) Array.newInstance(mcb.getClass(), 0));
}
@Override public String toString(ModelCriteriaNode<?> node) {
return "__TRUE__";
@ -102,7 +103,7 @@ public class ModelCriteriaNode<M> extends DefaultTreeNode<ModelCriteriaNode<M>>
}
;
public abstract <M, C extends ModelCriteriaBuilder<M>> C apply(C mcbCreator, ModelCriteriaNode<M> node);
public abstract <M, C extends ModelCriteriaBuilder<M, C>> C apply(C mcbCreator, ModelCriteriaNode<M> node);
public abstract String toString(ModelCriteriaNode<?> node);
}
@ -186,7 +187,7 @@ public class ModelCriteriaNode<M> extends DefaultTreeNode<ModelCriteriaNode<M>>
return getNodeOperator() != ExtOperator.__TRUE__;
}
public <C extends ModelCriteriaBuilder<M>> C flashToModelCriteriaBuilder(C mcb) {
public <C extends ModelCriteriaBuilder<M, C>> C flashToModelCriteriaBuilder(C mcb) {
final C res = nodeOperator.apply(mcb, this);
return res == null ? mcb : res;
}

View file

@ -43,8 +43,8 @@ import org.keycloak.models.UserModel.SearchableFields;
import org.keycloak.models.UserProvider;
import org.keycloak.models.map.storage.MapKeycloakTransaction;
import org.keycloak.models.map.storage.MapStorage;
import org.keycloak.models.map.storage.ModelCriteriaBuilder;
import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator;
import org.keycloak.models.map.storage.criteria.DefaultModelCriteria;
import org.keycloak.storage.StorageId;
import org.keycloak.storage.UserStorageProvider;
import org.keycloak.storage.client.ClientStorageProvider;
@ -154,7 +154,7 @@ public class MapUserProvider implements UserProvider.Streams, UserCredentialStor
public void preRemove(RealmModel realm, IdentityProviderModel provider) {
String socialProvider = provider.getAlias();
LOG.tracef("preRemove[RealmModel realm, IdentityProviderModel provider](%s, %s)%s", realm, socialProvider, getShortStackTrace());
ModelCriteriaBuilder<UserModel> mcb = criteria();
DefaultModelCriteria<UserModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.IDP_AND_USER, Operator.EQ, socialProvider);
@ -189,7 +189,7 @@ public class MapUserProvider implements UserProvider.Streams, UserCredentialStor
@Override
public UserModel getUserByFederatedIdentity(RealmModel realm, FederatedIdentityModel socialLink) {
LOG.tracef("getUserByFederatedIdentity(%s, %s)%s", realm, socialLink, getShortStackTrace());
ModelCriteriaBuilder<UserModel> mcb = criteria();
DefaultModelCriteria<UserModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.IDP_AND_USER, Operator.EQ, socialLink.getIdentityProvider(), socialLink.getUserId());
@ -278,7 +278,7 @@ public class MapUserProvider implements UserProvider.Streams, UserCredentialStor
@Override
public UserModel getServiceAccount(ClientModel client) {
LOG.tracef("getServiceAccount(%s)%s", client.getId(), getShortStackTrace());
ModelCriteriaBuilder<UserModel> mcb = criteria();
DefaultModelCriteria<UserModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, client.getRealm().getId())
.compare(SearchableFields.SERVICE_ACCOUNT_CLIENT, Operator.EQ, client.getId());
@ -301,7 +301,7 @@ public class MapUserProvider implements UserProvider.Streams, UserCredentialStor
@Override
public UserModel addUser(RealmModel realm, String id, String username, boolean addDefaultRoles, boolean addDefaultRequiredActions) {
LOG.tracef("addUser(%s, %s, %s, %s, %s)%s", realm, id, username, addDefaultRoles, addDefaultRequiredActions, getShortStackTrace());
ModelCriteriaBuilder<UserModel> mcb = criteria();
DefaultModelCriteria<UserModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.USERNAME, Operator.EQ, username);
@ -341,7 +341,7 @@ public class MapUserProvider implements UserProvider.Streams, UserCredentialStor
@Override
public void preRemove(RealmModel realm) {
LOG.tracef("preRemove[RealmModel](%s)%s", realm, getShortStackTrace());
ModelCriteriaBuilder<UserModel> mcb = criteria();
DefaultModelCriteria<UserModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId());
tx.delete(withCriteria(mcb));
@ -350,7 +350,7 @@ public class MapUserProvider implements UserProvider.Streams, UserCredentialStor
@Override
public void removeImportedUsers(RealmModel realm, String storageProviderId) {
LOG.tracef("removeImportedUsers(%s, %s)%s", realm, storageProviderId, getShortStackTrace());
ModelCriteriaBuilder<UserModel> mcb = criteria();
DefaultModelCriteria<UserModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.FEDERATION_LINK, Operator.EQ, storageProviderId);
@ -360,7 +360,7 @@ public class MapUserProvider implements UserProvider.Streams, UserCredentialStor
@Override
public void unlinkUsers(RealmModel realm, String storageProviderId) {
LOG.tracef("unlinkUsers(%s, %s)%s", realm, storageProviderId, getShortStackTrace());
ModelCriteriaBuilder<UserModel> mcb = criteria();
DefaultModelCriteria<UserModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.FEDERATION_LINK, Operator.EQ, storageProviderId);
@ -373,7 +373,7 @@ public class MapUserProvider implements UserProvider.Streams, UserCredentialStor
public void preRemove(RealmModel realm, RoleModel role) {
String roleId = role.getId();
LOG.tracef("preRemove[RoleModel](%s, %s)%s", realm, roleId, getShortStackTrace());
ModelCriteriaBuilder<UserModel> mcb = criteria();
DefaultModelCriteria<UserModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.ASSIGNED_ROLE, Operator.EQ, roleId);
@ -386,7 +386,7 @@ public class MapUserProvider implements UserProvider.Streams, UserCredentialStor
public void preRemove(RealmModel realm, GroupModel group) {
String groupId = group.getId();
LOG.tracef("preRemove[GroupModel](%s, %s)%s", realm, groupId, getShortStackTrace());
ModelCriteriaBuilder<UserModel> mcb = criteria();
DefaultModelCriteria<UserModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.ASSIGNED_GROUP, Operator.EQ, groupId);
@ -399,7 +399,7 @@ public class MapUserProvider implements UserProvider.Streams, UserCredentialStor
public void preRemove(RealmModel realm, ClientModel client) {
String clientId = client.getId();
LOG.tracef("preRemove[ClientModel](%s, %s)%s", realm, clientId, getShortStackTrace());
ModelCriteriaBuilder<UserModel> mcb = criteria();
DefaultModelCriteria<UserModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.CONSENT_FOR_CLIENT, Operator.EQ, clientId);
@ -418,7 +418,7 @@ public class MapUserProvider implements UserProvider.Streams, UserCredentialStor
String clientScopeId = clientScope.getId();
LOG.tracef("preRemove[ClientScopeModel](%s)%s", clientScopeId, getShortStackTrace());
ModelCriteriaBuilder<UserModel> mcb = criteria();
DefaultModelCriteria<UserModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, clientScope.getRealm().getId())
.compare(SearchableFields.CONSENT_WITH_CLIENT_SCOPE, Operator.EQ, clientScopeId);
@ -436,7 +436,7 @@ public class MapUserProvider implements UserProvider.Streams, UserCredentialStor
removeImportedUsers(realm, componentId);
}
if (component.getProviderType().equals(ClientStorageProvider.class.getName())) {
ModelCriteriaBuilder<UserModel> mcb = criteria();
DefaultModelCriteria<UserModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.CONSENT_CLIENT_FEDERATION_LINK, Operator.EQ, componentId);
@ -464,7 +464,7 @@ public class MapUserProvider implements UserProvider.Streams, UserCredentialStor
public void grantToAllUsers(RealmModel realm, RoleModel role) {
String roleId = role.getId();
LOG.tracef("grantToAllUsers(%s, %s)%s", realm, roleId, getShortStackTrace());
ModelCriteriaBuilder<UserModel> mcb = criteria();
DefaultModelCriteria<UserModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId());
try (Stream<MapUserEntity> s = tx.read(withCriteria(mcb))) {
@ -482,7 +482,7 @@ public class MapUserProvider implements UserProvider.Streams, UserCredentialStor
public UserModel getUserByUsername(RealmModel realm, String username) {
if (username == null) return null;
LOG.tracef("getUserByUsername(%s, %s)%s", realm, username, getShortStackTrace());
ModelCriteriaBuilder<UserModel> mcb = criteria();
DefaultModelCriteria<UserModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.USERNAME, Operator.ILIKE, username);
@ -495,7 +495,7 @@ public class MapUserProvider implements UserProvider.Streams, UserCredentialStor
@Override
public UserModel getUserByEmail(RealmModel realm, String email) {
LOG.tracef("getUserByEmail(%s, %s)%s", realm, email, getShortStackTrace());
ModelCriteriaBuilder<UserModel> mcb = criteria();
DefaultModelCriteria<UserModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.EMAIL, Operator.EQ, email);
@ -526,7 +526,7 @@ public class MapUserProvider implements UserProvider.Streams, UserCredentialStor
@Override
public int getUsersCount(RealmModel realm, boolean includeServiceAccount) {
LOG.tracef("getUsersCount(%s, %s)%s", realm, includeServiceAccount, getShortStackTrace());
ModelCriteriaBuilder<UserModel> mcb = criteria();
DefaultModelCriteria<UserModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId());
if (! includeServiceAccount) {
@ -539,7 +539,7 @@ public class MapUserProvider implements UserProvider.Streams, UserCredentialStor
@Override
public Stream<UserModel> getUsersStream(RealmModel realm, Integer firstResult, Integer maxResults, boolean includeServiceAccounts) {
LOG.tracef("getUsersStream(%s, %d, %d, %s)%s", realm, firstResult, maxResults, includeServiceAccounts, getShortStackTrace());
ModelCriteriaBuilder<UserModel> mcb = criteria();
DefaultModelCriteria<UserModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId());
if (! includeServiceAccounts) {
@ -569,7 +569,7 @@ public class MapUserProvider implements UserProvider.Streams, UserCredentialStor
public Stream<UserModel> searchForUserStream(RealmModel realm, Map<String, String> attributes, Integer firstResult, Integer maxResults) {
LOG.tracef("searchForUserStream(%s, %s, %d, %d)%s", realm, attributes, firstResult, maxResults, getShortStackTrace());
ModelCriteriaBuilder<UserModel> mcb = criteria();
DefaultModelCriteria<UserModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId());
if (! session.getAttributeOrDefault(UserModel.INCLUDE_SERVICE_ACCOUNT, true)) {
@ -675,7 +675,7 @@ public class MapUserProvider implements UserProvider.Streams, UserCredentialStor
@Override
public Stream<UserModel> getGroupMembersStream(RealmModel realm, GroupModel group, Integer firstResult, Integer maxResults) {
LOG.tracef("getGroupMembersStream(%s, %s, %d, %d)%s", realm, group.getId(), firstResult, maxResults, getShortStackTrace());
ModelCriteriaBuilder<UserModel> mcb = criteria();
DefaultModelCriteria<UserModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.ASSIGNED_GROUP, Operator.EQ, group.getId());
@ -686,7 +686,7 @@ public class MapUserProvider implements UserProvider.Streams, UserCredentialStor
@Override
public Stream<UserModel> searchForUserByUserAttributeStream(RealmModel realm, String attrName, String attrValue) {
LOG.tracef("searchForUserByUserAttributeStream(%s, %s, %s)%s", realm, attrName, attrValue, getShortStackTrace());
ModelCriteriaBuilder<UserModel> mcb = criteria();
DefaultModelCriteria<UserModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.ATTRIBUTE, Operator.EQ, attrName, attrValue);
@ -714,7 +714,7 @@ public class MapUserProvider implements UserProvider.Streams, UserCredentialStor
@Override
public Stream<UserModel> getRoleMembersStream(RealmModel realm, RoleModel role, Integer firstResult, Integer maxResults) {
LOG.tracef("getRoleMembersStream(%s, %s, %d, %d)%s", realm, role, firstResult, maxResults, getShortStackTrace());
ModelCriteriaBuilder<UserModel> mcb = criteria();
DefaultModelCriteria<UserModel> mcb = criteria();
mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.ASSIGNED_ROLE, Operator.EQ, role.getId());

View file

@ -29,7 +29,7 @@ import org.keycloak.models.UserSessionModel;
import org.keycloak.models.UserSessionProvider;
import org.keycloak.models.map.storage.MapKeycloakTransaction;
import org.keycloak.models.map.storage.MapStorage;
import org.keycloak.models.map.storage.ModelCriteriaBuilder;
import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator;
import org.keycloak.models.map.storage.criteria.DefaultModelCriteria;
import java.util.Arrays;
@ -173,12 +173,12 @@ public class MapUserSessionProvider implements UserSessionProvider {
return null;
}
ModelCriteriaBuilder<AuthenticatedClientSessionModel> mcb = criteria();
mcb = mcb.compare(AuthenticatedClientSessionModel.SearchableFields.ID, ModelCriteriaBuilder.Operator.EQ, clientSessionId)
.compare(AuthenticatedClientSessionModel.SearchableFields.USER_SESSION_ID, ModelCriteriaBuilder.Operator.EQ, userSession.getId())
.compare(AuthenticatedClientSessionModel.SearchableFields.REALM_ID, ModelCriteriaBuilder.Operator.EQ, userSession.getRealm().getId())
.compare(AuthenticatedClientSessionModel.SearchableFields.CLIENT_ID, ModelCriteriaBuilder.Operator.EQ, client.getId())
.compare(AuthenticatedClientSessionModel.SearchableFields.IS_OFFLINE, ModelCriteriaBuilder.Operator.EQ, offline);
DefaultModelCriteria<AuthenticatedClientSessionModel> mcb = criteria();
mcb = mcb.compare(AuthenticatedClientSessionModel.SearchableFields.ID, Operator.EQ, clientSessionId)
.compare(AuthenticatedClientSessionModel.SearchableFields.USER_SESSION_ID, Operator.EQ, userSession.getId())
.compare(AuthenticatedClientSessionModel.SearchableFields.REALM_ID, Operator.EQ, userSession.getRealm().getId())
.compare(AuthenticatedClientSessionModel.SearchableFields.CLIENT_ID, Operator.EQ, client.getId())
.compare(AuthenticatedClientSessionModel.SearchableFields.IS_OFFLINE, Operator.EQ, offline);
return clientSessionTx.read(withCriteria(mcb))
.findFirst()
@ -236,8 +236,8 @@ public class MapUserSessionProvider implements UserSessionProvider {
return userEntityToAdapterFunc(realm).apply(userSessionEntity);
}
ModelCriteriaBuilder<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, false)
.compare(UserSessionModel.SearchableFields.ID, ModelCriteriaBuilder.Operator.EQ, id);
DefaultModelCriteria<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, false)
.compare(UserSessionModel.SearchableFields.ID, Operator.EQ, id);
return userSessionTx.read(withCriteria(mcb))
.findFirst()
@ -247,8 +247,8 @@ public class MapUserSessionProvider implements UserSessionProvider {
@Override
public Stream<UserSessionModel> getUserSessionsStream(RealmModel realm, UserModel user) {
ModelCriteriaBuilder<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, false)
.compare(UserSessionModel.SearchableFields.USER_ID, ModelCriteriaBuilder.Operator.EQ, user.getId());
DefaultModelCriteria<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, false)
.compare(UserSessionModel.SearchableFields.USER_ID, Operator.EQ, user.getId());
LOG.tracef("getUserSessionsStream(%s, %s)%s", realm, user, getShortStackTrace());
@ -259,8 +259,8 @@ public class MapUserSessionProvider implements UserSessionProvider {
@Override
public Stream<UserSessionModel> getUserSessionsStream(RealmModel realm, ClientModel client) {
ModelCriteriaBuilder<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, false)
.compare(UserSessionModel.SearchableFields.CLIENT_ID, ModelCriteriaBuilder.Operator.EQ, client.getId());
DefaultModelCriteria<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, false)
.compare(UserSessionModel.SearchableFields.CLIENT_ID, Operator.EQ, client.getId());
LOG.tracef("getUserSessionsStream(%s, %s)%s", realm, client, getShortStackTrace());
@ -274,8 +274,8 @@ public class MapUserSessionProvider implements UserSessionProvider {
Integer firstResult, Integer maxResults) {
LOG.tracef("getUserSessionsStream(%s, %s, %s, %s)%s", realm, client, firstResult, maxResults, getShortStackTrace());
ModelCriteriaBuilder<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, false)
.compare(UserSessionModel.SearchableFields.CLIENT_ID, ModelCriteriaBuilder.Operator.EQ, client.getId());
DefaultModelCriteria<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, false)
.compare(UserSessionModel.SearchableFields.CLIENT_ID, Operator.EQ, client.getId());
return userSessionTx.read(withCriteria(mcb).pagination(firstResult, maxResults,
@ -286,8 +286,8 @@ public class MapUserSessionProvider implements UserSessionProvider {
@Override
public Stream<UserSessionModel> getUserSessionByBrokerUserIdStream(RealmModel realm, String brokerUserId) {
ModelCriteriaBuilder<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, false)
.compare(UserSessionModel.SearchableFields.BROKER_USER_ID, ModelCriteriaBuilder.Operator.EQ, brokerUserId);
DefaultModelCriteria<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, false)
.compare(UserSessionModel.SearchableFields.BROKER_USER_ID, Operator.EQ, brokerUserId);
LOG.tracef("getUserSessionByBrokerUserIdStream(%s, %s)%s", realm, brokerUserId, getShortStackTrace());
@ -298,8 +298,8 @@ public class MapUserSessionProvider implements UserSessionProvider {
@Override
public UserSessionModel getUserSessionByBrokerSessionId(RealmModel realm, String brokerSessionId) {
ModelCriteriaBuilder<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, false)
.compare(UserSessionModel.SearchableFields.BROKER_SESSION_ID, ModelCriteriaBuilder.Operator.EQ, brokerSessionId);
DefaultModelCriteria<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, false)
.compare(UserSessionModel.SearchableFields.BROKER_SESSION_ID, Operator.EQ, brokerSessionId);
LOG.tracef("getUserSessionByBrokerSessionId(%s, %s)%s", realm, brokerSessionId, getShortStackTrace());
@ -331,8 +331,8 @@ public class MapUserSessionProvider implements UserSessionProvider {
@Override
public long getActiveUserSessions(RealmModel realm, ClientModel client) {
ModelCriteriaBuilder<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, false)
.compare(UserSessionModel.SearchableFields.CLIENT_ID, ModelCriteriaBuilder.Operator.EQ, client.getId());
DefaultModelCriteria<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, false)
.compare(UserSessionModel.SearchableFields.CLIENT_ID, Operator.EQ, client.getId());
LOG.tracef("getActiveUserSessions(%s, %s)%s", realm, client, getShortStackTrace());
@ -341,7 +341,7 @@ public class MapUserSessionProvider implements UserSessionProvider {
@Override
public Map<String, Long> getActiveClientSessionStats(RealmModel realm, boolean offline) {
ModelCriteriaBuilder<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, offline);
DefaultModelCriteria<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, offline);
LOG.tracef("getActiveClientSessionStats(%s, %s)%s", realm, offline, getShortStackTrace());
@ -358,8 +358,8 @@ public class MapUserSessionProvider implements UserSessionProvider {
public void removeUserSession(RealmModel realm, UserSessionModel session) {
Objects.requireNonNull(session, "The provided user session can't be null!");
ModelCriteriaBuilder<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, false)
.compare(UserSessionModel.SearchableFields.ID, ModelCriteriaBuilder.Operator.EQ, session.getId());
DefaultModelCriteria<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, false)
.compare(UserSessionModel.SearchableFields.ID, Operator.EQ, session.getId());
LOG.tracef("removeUserSession(%s, %s)%s", realm, session, getShortStackTrace());
@ -368,9 +368,9 @@ public class MapUserSessionProvider implements UserSessionProvider {
@Override
public void removeUserSessions(RealmModel realm, UserModel user) {
ModelCriteriaBuilder<UserSessionModel> mcb = criteria();
mcb = mcb.compare(UserSessionModel.SearchableFields.REALM_ID, ModelCriteriaBuilder.Operator.EQ, realm.getId())
.compare(UserSessionModel.SearchableFields.USER_ID, ModelCriteriaBuilder.Operator.EQ, user.getId());
DefaultModelCriteria<UserSessionModel> mcb = criteria();
mcb = mcb.compare(UserSessionModel.SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(UserSessionModel.SearchableFields.USER_ID, Operator.EQ, user.getId());
LOG.tracef("removeUserSessions(%s, %s)%s", realm, user, getShortStackTrace());
@ -389,7 +389,7 @@ public class MapUserSessionProvider implements UserSessionProvider {
@Override
public void removeUserSessions(RealmModel realm) {
ModelCriteriaBuilder<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, false);
DefaultModelCriteria<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, false);
LOG.tracef("removeUserSessions(%s)%s", realm, getShortStackTrace());
@ -442,13 +442,13 @@ public class MapUserSessionProvider implements UserSessionProvider {
LOG.tracef("removeOfflineUserSession(%s, %s)%s", realm, userSession, getShortStackTrace());
ModelCriteriaBuilder<UserSessionModel> mcb;
DefaultModelCriteria<UserSessionModel> mcb;
if (userSession.isOffline()) {
userSessionTx.delete(userSession.getId());
} else if (userSession.getNote(CORRESPONDING_SESSION_ID) != null) {
String uk = userSession.getNote(CORRESPONDING_SESSION_ID);
mcb = realmAndOfflineCriteriaBuilder(realm, true)
.compare(UserSessionModel.SearchableFields.ID, ModelCriteriaBuilder.Operator.EQ, uk);
.compare(UserSessionModel.SearchableFields.ID, Operator.EQ, uk);
userSessionTx.delete(withCriteria(mcb));
userSession.removeNote(CORRESPONDING_SESSION_ID);
}
@ -477,8 +477,8 @@ public class MapUserSessionProvider implements UserSessionProvider {
@Override
public Stream<UserSessionModel> getOfflineUserSessionsStream(RealmModel realm, UserModel user) {
ModelCriteriaBuilder<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, true)
.compare(UserSessionModel.SearchableFields.USER_ID, ModelCriteriaBuilder.Operator.EQ, user.getId());
DefaultModelCriteria<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, true)
.compare(UserSessionModel.SearchableFields.USER_ID, Operator.EQ, user.getId());
LOG.tracef("getOfflineUserSessionsStream(%s, %s)%s", realm, user, getShortStackTrace());
@ -489,8 +489,8 @@ public class MapUserSessionProvider implements UserSessionProvider {
@Override
public UserSessionModel getOfflineUserSessionByBrokerSessionId(RealmModel realm, String brokerSessionId) {
ModelCriteriaBuilder<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, true)
.compare(UserSessionModel.SearchableFields.BROKER_SESSION_ID, ModelCriteriaBuilder.Operator.EQ, brokerSessionId);
DefaultModelCriteria<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, true)
.compare(UserSessionModel.SearchableFields.BROKER_SESSION_ID, Operator.EQ, brokerSessionId);
LOG.tracef("getOfflineUserSessionByBrokerSessionId(%s, %s)%s", realm, brokerSessionId, getShortStackTrace());
@ -502,8 +502,8 @@ public class MapUserSessionProvider implements UserSessionProvider {
@Override
public Stream<UserSessionModel> getOfflineUserSessionByBrokerUserIdStream(RealmModel realm, String brokerUserId) {
ModelCriteriaBuilder<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, true)
.compare(UserSessionModel.SearchableFields.BROKER_USER_ID, ModelCriteriaBuilder.Operator.EQ, brokerUserId);
DefaultModelCriteria<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, true)
.compare(UserSessionModel.SearchableFields.BROKER_USER_ID, Operator.EQ, brokerUserId);
LOG.tracef("getOfflineUserSessionByBrokerUserIdStream(%s, %s)%s", realm, brokerUserId, getShortStackTrace());
@ -514,8 +514,8 @@ public class MapUserSessionProvider implements UserSessionProvider {
@Override
public long getOfflineSessionsCount(RealmModel realm, ClientModel client) {
ModelCriteriaBuilder<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, true)
.compare(UserSessionModel.SearchableFields.CLIENT_ID, ModelCriteriaBuilder.Operator.EQ, client.getId());
DefaultModelCriteria<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, true)
.compare(UserSessionModel.SearchableFields.CLIENT_ID, Operator.EQ, client.getId());
LOG.tracef("getOfflineSessionsCount(%s, %s)%s", realm, client, getShortStackTrace());
@ -525,8 +525,8 @@ public class MapUserSessionProvider implements UserSessionProvider {
@Override
public Stream<UserSessionModel> getOfflineUserSessionsStream(RealmModel realm, ClientModel client,
Integer firstResult, Integer maxResults) {
ModelCriteriaBuilder<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, true)
.compare(UserSessionModel.SearchableFields.CLIENT_ID, ModelCriteriaBuilder.Operator.EQ, client.getId());
DefaultModelCriteria<UserSessionModel> mcb = realmAndOfflineCriteriaBuilder(realm, true)
.compare(UserSessionModel.SearchableFields.CLIENT_ID, Operator.EQ, client.getId());
LOG.tracef("getOfflineUserSessionsStream(%s, %s, %s, %s)%s", realm, client, firstResult, maxResults, getShortStackTrace());
@ -574,9 +574,9 @@ public class MapUserSessionProvider implements UserSessionProvider {
}
// first get a user entity by ID
ModelCriteriaBuilder<UserSessionModel> mcb = criteria();
mcb = mcb.compare(UserSessionModel.SearchableFields.REALM_ID, ModelCriteriaBuilder.Operator.EQ, realm.getId())
.compare(UserSessionModel.SearchableFields.ID, ModelCriteriaBuilder.Operator.EQ, userSessionId);
DefaultModelCriteria<UserSessionModel> mcb = criteria();
mcb = mcb.compare(UserSessionModel.SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(UserSessionModel.SearchableFields.ID, Operator.EQ, userSessionId);
// check if it's an offline user session
MapUserSessionEntity userSessionEntity = userSessionTx.read(withCriteria(mcb)).findFirst().orElse(null);
@ -587,7 +587,7 @@ public class MapUserSessionProvider implements UserSessionProvider {
} else {
// no session found by the given ID, try to find by corresponding session ID
mcb = realmAndOfflineCriteriaBuilder(realm, true)
.compare(UserSessionModel.SearchableFields.CORRESPONDING_SESSION_ID, ModelCriteriaBuilder.Operator.EQ, userSessionId);
.compare(UserSessionModel.SearchableFields.CORRESPONDING_SESSION_ID, Operator.EQ, userSessionId);
return userSessionTx.read(withCriteria(mcb));
}
@ -595,17 +595,17 @@ public class MapUserSessionProvider implements UserSessionProvider {
String offlineUserSessionId = userSessionEntity.getNote(CORRESPONDING_SESSION_ID);
if (offlineUserSessionId != null) {
mcb = realmAndOfflineCriteriaBuilder(realm, true)
.compare(UserSessionModel.SearchableFields.ID, ModelCriteriaBuilder.Operator.EQ, offlineUserSessionId);
.compare(UserSessionModel.SearchableFields.ID, Operator.EQ, offlineUserSessionId);
return userSessionTx.read(withCriteria(mcb));
}
return Stream.empty();
}
private ModelCriteriaBuilder<UserSessionModel> realmAndOfflineCriteriaBuilder(RealmModel realm, boolean offline) {
private DefaultModelCriteria<UserSessionModel> realmAndOfflineCriteriaBuilder(RealmModel realm, boolean offline) {
return DefaultModelCriteria.<UserSessionModel>criteria()
.compare(UserSessionModel.SearchableFields.REALM_ID, ModelCriteriaBuilder.Operator.EQ, realm.getId())
.compare(UserSessionModel.SearchableFields.IS_OFFLINE, ModelCriteriaBuilder.Operator.EQ, offline);
.compare(UserSessionModel.SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(UserSessionModel.SearchableFields.IS_OFFLINE, Operator.EQ, offline);
}
private MapUserSessionEntity getUserSessionById(String id) {

View file

@ -45,7 +45,7 @@ public class DefaultModelCriteriaTest {
assertThat(v.and(), hasToString("__TRUE__"));
assertThat(v.and(v.or()), hasToString("__FALSE__"));
assertThat(v.and(v.compare(CLIENT_ID, Operator.EQ, 3)), hasToString("(clientId EQ [3])"));
assertThat(v.and(v.compare(CLIENT_ID, Operator.EQ, 3)), hasToString("clientId EQ [3]"));
assertThat(v.and(v.compare(CLIENT_ID, Operator.EQ, 3), v.or()), hasToString("__FALSE__"));
assertThat(v.and(v.compare(CLIENT_ID, Operator.EQ, 4).compare(ID, Operator.EQ, 5)), hasToString("(clientId EQ [4] && id EQ [5])"));
assertThat(v.and(v.compare(CLIENT_ID, Operator.EQ, 4), v.compare(ID, Operator.EQ, 5)), hasToString("(clientId EQ [4] && id EQ [5])"));
@ -57,7 +57,7 @@ public class DefaultModelCriteriaTest {
assertThat(v.or(), hasToString("__FALSE__"));
assertThat(v.or(v.and()), hasToString("__TRUE__"));
assertThat(v.or(v.compare(CLIENT_ID, Operator.EQ, 3)), hasToString("(clientId EQ [3])"));
assertThat(v.or(v.compare(CLIENT_ID, Operator.EQ, 3)), hasToString("clientId EQ [3]"));
assertThat(v.or(v.compare(CLIENT_ID, Operator.EQ, 3), v.and()), hasToString("__TRUE__"));
assertThat(v.or(v.compare(CLIENT_ID, Operator.EQ, 4).compare(ID, Operator.EQ, 5)), hasToString("(clientId EQ [4] && id EQ [5])"));
assertThat(v.or(v.compare(CLIENT_ID, Operator.EQ, 4), v.compare(ID, Operator.EQ, 5)), hasToString("(clientId EQ [4] || id EQ [5])"));