Clean RealmProvider from methods from other areas

Closes #15044
This commit is contained in:
vramik 2023-04-29 13:15:58 +02:00 committed by Michal Hajas
parent a376ec774f
commit 6c6907ef4e
2 changed files with 2 additions and 451 deletions

View file

@ -19,18 +19,13 @@ package org.keycloak.models.map.realm;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.keycloak.models.ClientModel;
import org.keycloak.models.ClientScopeModel;
import org.keycloak.models.GroupModel;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.ModelDuplicateException; import org.keycloak.models.ModelDuplicateException;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;
import org.keycloak.models.RealmModel.SearchableFields; import org.keycloak.models.RealmModel.SearchableFields;
import org.keycloak.models.RealmProvider; import org.keycloak.models.RealmProvider;
import org.keycloak.models.RoleModel;
import org.keycloak.models.map.common.DeepCloner; import org.keycloak.models.map.common.DeepCloner;
import org.keycloak.models.map.storage.MapStorage; import org.keycloak.models.map.storage.MapStorage;
import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator; import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator;
@ -204,280 +199,6 @@ public class MapRealmProvider implements RealmProvider {
return realm.getRealmLocalizationTextsByLocale(locale).get(key); return realm.getRealmLocalizationTextsByLocale(locale).get(key);
} }
@Override
@Deprecated
public ClientModel addClient(RealmModel realm, String id, String clientId) {
return session.clients().addClient(realm, id, clientId);
}
@Override
@Deprecated
public long getClientsCount(RealmModel realm) {
return session.clients().getClientsCount(realm);
}
@Override
@Deprecated
public Stream<ClientModel> getClientsStream(RealmModel realm, Integer firstResult, Integer maxResults) {
return session.clients().getClientsStream(realm, firstResult, maxResults);
}
@Override
@Deprecated
public Stream<ClientModel> getAlwaysDisplayInConsoleClientsStream(RealmModel realm) {
return session.clients().getAlwaysDisplayInConsoleClientsStream(realm);
}
@Override
@Deprecated
public boolean removeClient(RealmModel realm, String id) {
return session.clients().removeClient(realm, id);
}
@Override
@Deprecated
public void removeClients(RealmModel realm) {
session.clients().removeClients(realm);
}
@Override
@Deprecated
public ClientModel getClientById(RealmModel realm, String id) {
return session.clients().getClientById(realm, id);
}
@Override
@Deprecated
public ClientModel getClientByClientId(RealmModel realm, String clientId) {
return session.clients().getClientByClientId(realm, clientId);
}
@Override
@Deprecated
public Stream<ClientModel> searchClientsByClientIdStream(RealmModel realm, String clientId, Integer firstResult, Integer maxResults) {
return session.clients().searchClientsByClientIdStream(realm, clientId, firstResult, maxResults);
}
@Override
@Deprecated
public Stream<ClientModel> searchClientsByAttributes(RealmModel realm, Map<String, String> attributes, Integer firstResult, Integer maxResults) {
return session.clients().searchClientsByAttributes(realm, attributes, firstResult, maxResults);
}
@Override
@Deprecated
public void addClientScopes(RealmModel realm, ClientModel client, Set<ClientScopeModel> clientScopes, boolean defaultScope) {
session.clients().addClientScopes(realm, client, clientScopes, defaultScope);
}
@Override
@Deprecated
public void removeClientScope(RealmModel realm, ClientModel client, ClientScopeModel clientScope) {
session.clients().removeClientScope(realm, client, clientScope);
}
@Override
@Deprecated
public Map<String, ClientScopeModel> getClientScopes(RealmModel realm, ClientModel client, boolean defaultScopes) {
return session.clients().getClientScopes(realm, client, defaultScopes);
}
@Override
@Deprecated
public ClientScopeModel getClientScopeById(RealmModel realm, String id) {
return session.clientScopes().getClientScopeById(realm, id);
}
@Override
@Deprecated
public Stream<ClientScopeModel> getClientScopesStream(RealmModel realm) {
return session.clientScopes().getClientScopesStream(realm);
}
@Override
@Deprecated
public ClientScopeModel addClientScope(RealmModel realm, String id, String name) {
return session.clientScopes().addClientScope(realm, id, name);
}
@Override
@Deprecated
public boolean removeClientScope(RealmModel realm, String id) {
return session.clientScopes().removeClientScope(realm, id);
}
@Override
@Deprecated
public void removeClientScopes(RealmModel realm) {
session.clientScopes().removeClientScopes(realm);
}
@Override
@Deprecated
public Map<ClientModel, Set<String>> getAllRedirectUrisOfEnabledClients(RealmModel realm) {
return session.clients().getAllRedirectUrisOfEnabledClients(realm);
}
@Override
@Deprecated
public void moveGroup(RealmModel realm, GroupModel group, GroupModel toParent) {
session.groups().moveGroup(realm, group, toParent);
}
@Override
@Deprecated
public GroupModel getGroupById(RealmModel realm, String id) {
return session.groups().getGroupById(realm, id);
}
@Override
@Deprecated
public Long getGroupsCount(RealmModel realm, Boolean onlyTopGroups) {
return session.groups().getGroupsCount(realm, onlyTopGroups);
}
@Override
@Deprecated
public Long getGroupsCountByNameContaining(RealmModel realm, String search) {
return session.groups().getGroupsCountByNameContaining(realm, search);
}
@Override
@Deprecated
public boolean removeGroup(RealmModel realm, GroupModel group) {
return session.groups().removeGroup(realm, group);
}
@Override
@Deprecated
public GroupModel createGroup(RealmModel realm, String id, String name, GroupModel toParent) {
return session.groups().createGroup(realm, id, name, toParent);
}
@Override
@Deprecated
public void addTopLevelGroup(RealmModel realm, GroupModel subGroup) {
session.groups().addTopLevelGroup(realm, subGroup);
}
@Override
@Deprecated
public Stream<GroupModel> getGroupsStream(RealmModel realm) {
return session.groups().getGroupsStream(realm);
}
@Override
@Deprecated
public Stream<GroupModel> getGroupsStream(RealmModel realm, Stream<String> ids, String search, Integer first, Integer max) {
return session.groups().getGroupsStream(realm,ids, search, first, max);
}
@Override
@Deprecated
public Stream<GroupModel> getGroupsByRoleStream(RealmModel realm, RoleModel role, Integer firstResult, Integer maxResults) {
return session.groups().getGroupsByRoleStream(realm, role, firstResult, maxResults);
}
@Override
@Deprecated
public Stream<GroupModel> getTopLevelGroupsStream(RealmModel realm) {
return session.groups().getTopLevelGroupsStream(realm);
}
@Override
@Deprecated
public Stream<GroupModel> getTopLevelGroupsStream(RealmModel realm, Integer firstResult, Integer maxResults) {
return session.groups().getTopLevelGroupsStream(realm, firstResult, maxResults);
}
@Override
@Deprecated
public Stream<GroupModel> searchForGroupByNameStream(RealmModel realm, String search, Boolean exact, Integer firstResult, Integer maxResults) {
return session.groups().searchForGroupByNameStream(realm, search, exact, firstResult, maxResults);
}
@Override
public Stream<GroupModel> searchGroupsByAttributes(RealmModel realm, Map<String, String> attributes, Integer firstResult, Integer maxResults) {
return session.groups().searchGroupsByAttributes(realm, attributes, firstResult, maxResults);
}
@Override
@Deprecated
public RoleModel addRealmRole(RealmModel realm, String id, String name) {
return session.roles().addRealmRole(realm, id, name);
}
@Override
@Deprecated
public RoleModel getRealmRole(RealmModel realm, String name) {
return session.roles().getRealmRole(realm, name);
}
@Override
@Deprecated
public Stream<RoleModel> getRealmRolesStream(RealmModel realm, Integer first, Integer max) {
return session.roles().getRealmRolesStream(realm, first, max);
}
@Override
public Stream<RoleModel> getRolesStream(RealmModel realm, Stream<String> ids, String search, Integer first, Integer max) {
return session.roles().getRolesStream(realm, ids, search, first, max);
}
@Override
@Deprecated
public boolean removeRole(RoleModel role) {
return session.roles().removeRole(role);
}
@Override
@Deprecated
public void removeRoles(RealmModel realm) {
session.roles().removeRoles(realm);
}
@Override
@Deprecated
public RoleModel addClientRole(ClientModel client, String id, String name) {
return session.roles().addClientRole(client, name);
}
@Override
@Deprecated
public Stream<RoleModel> getClientRolesStream(ClientModel client, Integer first, Integer max) {
return session.roles().getClientRolesStream(client, first, max);
}
@Override
@Deprecated
public void removeRoles(ClientModel client) {
session.roles().removeRoles(client);
}
@Override
@Deprecated
public RoleModel getRoleById(RealmModel realm, String id) {
return session.roles().getRoleById(realm, id);
}
@Override
@Deprecated
public Stream<RoleModel> searchForRolesStream(RealmModel realm, String search, Integer first, Integer max) {
return session.roles().searchForRolesStream(realm, search, first, max);
}
@Override
@Deprecated
public RoleModel getClientRole(ClientModel client, String name) {
return session.roles().getClientRole(client, name);
}
@Override
@Deprecated
public Stream<RoleModel> searchForClientRolesStream(ClientModel client, String search, Integer first, Integer max) {
return session.roles().searchForClientRolesStream(client, search, first, max);
}
@Override @Override
public void close() { public void close() {
} }

View file

@ -18,18 +18,14 @@
package org.keycloak.models; package org.keycloak.models;
import java.util.Map; import java.util.Map;
import org.keycloak.provider.Provider;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.keycloak.provider.Provider;
/** /**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $ * @version $Revision: 1 $
*/ */
public interface RealmProvider extends Provider /* TODO: Remove in future version */, ClientProvider, ClientScopeProvider, GroupProvider, RoleProvider /* up to here */ { public interface RealmProvider extends Provider {
/** /**
* Creates new realm with the given name. The internal ID will be generated automatically. * Creates new realm with the given name. The internal ID will be generated automatically.
@ -121,170 +117,4 @@ public interface RealmProvider extends Provider /* TODO: Remove in future versio
boolean deleteLocalizationText(RealmModel realm, String locale, String key); boolean deleteLocalizationText(RealmModel realm, String locale, String key);
String getLocalizationTextsById(RealmModel realm, String locale, String key); String getLocalizationTextsById(RealmModel realm, String locale, String key);
// The methods below are going to be removed in future version of Keycloak
// Sadly, we have to copy-paste the declarations from the respective interfaces
// including the "default" body to be able to add a note on deprecation
/**
* @deprecated Use the corresponding method from {@link ClientProvider}. */
@Override
public ClientModel addClient(RealmModel realm, String id, String clientId);
/**
* @deprecated Use the corresponding method from {@link ClientProvider}. */
@Override
default ClientModel addClient(RealmModel realm, String clientId) {
return addClient(realm, null, clientId);
}
/**
* @deprecated Use the corresponding method from {@link ClientProvider}. */
@Override
long getClientsCount(RealmModel realm);
/**
* @deprecated Use the corresponding method from {@link ClientScopeProvider}. */
default ClientScopeModel getClientScopeById(String id, RealmModel realm) {
return getClientScopeById(realm, id);
}
/**
* @deprecated Use the corresponding method from {@link ClientScopeProvider}. */
@Override
ClientScopeModel getClientScopeById(RealmModel realm, String id);
//Role-related methods
/**
* @deprecated Use the corresponding method from {@link RoleProvider}. */
@Override
default RoleModel addRealmRole(RealmModel realm, String name) { return addRealmRole(realm, null, name); }
/**
* @deprecated Use the corresponding method from {@link RoleProvider}. */
@Override
RoleModel addRealmRole(RealmModel realm, String id, String name);
/**
* @deprecated Use the corresponding method from {@link RoleProvider}. */
@Override
RoleModel getRealmRole(RealmModel realm, String name);
/**
* @deprecated Use the corresponding method from {@link RoleProvider}. */
default RoleModel getRoleById(String id, RealmModel realm) {
return getRoleById(realm, id);
}
/**
* @deprecated Use the corresponding method from {@link RoleProvider}. */
default Set<RoleModel> getRealmRoles(RealmModel realm, Integer first, Integer max) {
return getRealmRolesStream(realm, first, max).collect(Collectors.toSet());
}
/**
* @deprecated Use the corresponding method from {@link RoleProvider}. */
default Set<RoleModel> searchForRoles(RealmModel realm, String search, Integer first, Integer max) {
return searchForRolesStream(realm, search, first, max).collect(Collectors.toSet());
}
/**
* @deprecated Use the corresponding method from {@link RoleProvider}. */
default boolean removeRole(RealmModel realm, RoleModel role) {
return removeRole(role);
}
/**
* @deprecated Use the corresponding method from {@link RoleProvider}. */
default RoleModel addClientRole(RealmModel realm, ClientModel client, String name) {
return addClientRole(client, name);
}
/**
* @deprecated Use the corresponding method from {@link RoleProvider}. */
default RoleModel addClientRole(RealmModel realm, ClientModel client, String id, String name) {
return addClientRole(client, id, name);
}
/**
* @deprecated Use the corresponding method from {@link RoleProvider}. */
default RoleModel getClientRole(RealmModel realm, ClientModel client, String name) {
return getClientRole(client, name);
}
/**
* @deprecated Use the corresponding method from {@link RoleProvider}. */
default Set<RoleModel> getClientRoles(RealmModel realm, ClientModel client) {
return getClientRolesStream(client).collect(Collectors.toSet());
}
/**
* @deprecated Use the corresponding method from {@link RoleProvider}. */
default Set<RoleModel> getClientRoles(RealmModel realm, ClientModel client, Integer first, Integer max) {
return getClientRolesStream(client, first, max).collect(Collectors.toSet());
}
/**
* @deprecated Use the corresponding method from {@link RoleProvider}. */
default Set<RoleModel> searchForClientRoles(RealmModel realm, ClientModel client, String search, Integer first, Integer max) {
return searchForClientRolesStream(client, search, first, max).collect(Collectors.toSet());
}
/* GROUP PROVIDER METHODS */
/**
* @deprecated Use the corresponding method from {@link GroupProvider}. */
@Override
void moveGroup(RealmModel realm, GroupModel group, GroupModel toParent);
/**
* @deprecated Use the corresponding method from {@link GroupProvider}. */
@Override
GroupModel getGroupById(RealmModel realm, String id);
/**
* @deprecated Use the corresponding method from {@link GroupProvider}. */
@Override
Long getGroupsCount(RealmModel realm, Boolean onlyTopGroups);
/**
* @deprecated Use the corresponding method from {@link GroupProvider}. */
@Override
Long getGroupsCountByNameContaining(RealmModel realm, String search);
/**
* @deprecated Use the corresponding method from {@link GroupProvider}. */
@Override
boolean removeGroup(RealmModel realm, GroupModel group);
/**
* @deprecated Use the corresponding method from {@link GroupProvider}. */
@Override
default GroupModel createGroup(RealmModel realm, String name) {
return createGroup(realm, null, name, null);
}
/**
* @deprecated Use the corresponding method from {@link GroupProvider}. */
@Override
default GroupModel createGroup(RealmModel realm, String id, String name) {
return createGroup(realm, id, name, null);
}
/**
* @deprecated Use the corresponding method from {@link GroupProvider}. */
@Override
default GroupModel createGroup(RealmModel realm, String name, GroupModel toParent) {
return createGroup(realm, null, name, toParent);
}
/**
* @deprecated Use the corresponding method from {@link GroupProvider}. */
@Override
GroupModel createGroup(RealmModel realm, String id, String name, GroupModel toParent);
/**
* @deprecated Use the corresponding method from {@link GroupProvider}. */
@Override
void addTopLevelGroup(RealmModel realm, GroupModel subGroup);
} }