From ed473da22b713d599865b4779445dc843258505b Mon Sep 17 00:00:00 2001 From: Vlasta Ramik Date: Fri, 9 Jun 2023 19:11:20 +0200 Subject: [PATCH] Clean-up of deprecated methods and interfaces Fixes #20877 Co-authored-by: andymunro <48995441+andymunro@users.noreply.github.com> --- .../topics/user-storage/augmenting.adoc | 35 +--- .../topics/keycloak/changes-22_0_0.adoc | 16 +- .../models/cache/infinispan/RealmAdapter.java | 6 - .../org/keycloak/models/jpa/RealmAdapter.java | 6 - .../jpa/JpaUserFederatedStorageProvider.java | 2 +- .../session/UserSessionPersisterProvider.java | 11 - .../storage/adapter/InMemoryUserAdapter.java | 2 +- .../LegacySessionSupportProviderFactory.java | 0 .../LegacySessionSupportProviderImpl.java | 5 - .../LegacySessionSupportSpi.java | 0 .../services/org.keycloak.provider.Spi | 18 ++ .../models/LegacySessionSupportProvider.java | 2 - .../models/UserCredentialManager.java | 2 - .../models/UserModelDefaultMethods.java | 11 - .../models/cache/CachedUserModel.java | 9 - .../org/keycloak/models/cache/UserCache.java | 8 - .../AbstractUserAdapterFederatedStorage.java | 192 +++--------------- .../UserAttributeFederatedStorage.java | 29 +-- .../UserBrokerLinkFederatedStorage.java | 29 +-- .../UserConsentFederatedStorage.java | 29 +-- .../UserFederatedStorageProvider.java | 30 +-- .../UserFederatedUserCredentialStore.java | 48 +---- .../UserGroupMembershipFederatedStorage.java | 49 +---- .../UserRequiredActionsFederatedStorage.java | 29 +-- .../UserRoleMappingsFederatedStorage.java | 29 +-- .../map/datastore/ImportKeycloakSession.java | 79 ------- .../models/map/realm/MapRealmAdapter.java | 6 - .../models/utils/KeycloakModelUtils.java | 11 - .../models/utils/ModelToRepresentation.java | 6 - .../util/IdentityBrokerStateTestHelpers.java | 5 - .../credential/CredentialInputUpdater.java | 10 - .../credential/UserCredentialStore.java | 10 - .../java/org/keycloak/models/GroupModel.java | 10 - .../org/keycloak/models/KeycloakSession.java | 94 --------- .../java/org/keycloak/models/RealmModel.java | 13 -- .../org/keycloak/models/RoleMapperModel.java | 10 - .../java/org/keycloak/models/UserModel.java | 8 - .../org/keycloak/models/UserProvider.java | 51 ----- .../storage/user/UserLookupProvider.java | 8 - .../storage/user/UserQueryProvider.java | 8 - .../services/DefaultKeycloakSession.java | 95 +-------- .../services/util/ScopeMappedUtil.java | 28 +-- .../services/org.keycloak.provider.Spi | 1 - .../UserManagedPermissionServiceTest.java | 2 +- .../federation/ldap/LDAPSyncTest.java | 2 +- .../webauthn/utils/WebAuthnDataWrapper.java | 6 +- 46 files changed, 119 insertions(+), 941 deletions(-) rename {services => model/legacy-services}/src/main/java/org/keycloak/services/legacysessionsupport/LegacySessionSupportProviderFactory.java (100%) rename {services => model/legacy-services}/src/main/java/org/keycloak/services/legacysessionsupport/LegacySessionSupportSpi.java (100%) create mode 100644 model/legacy-services/src/main/resources/META-INF/services/org.keycloak.provider.Spi rename {server-spi-private => model/legacy}/src/main/java/org/keycloak/models/LegacySessionSupportProvider.java (95%) rename {server-spi => model/legacy}/src/main/java/org/keycloak/models/UserCredentialManager.java (99%) diff --git a/docs/documentation/server_development/topics/user-storage/augmenting.adoc b/docs/documentation/server_development/topics/user-storage/augmenting.adoc index bbb3416337..e8670d503d 100644 --- a/docs/documentation/server_development/topics/user-storage/augmenting.adoc +++ b/docs/documentation/server_development/topics/user-storage/augmenting.adoc @@ -26,47 +26,14 @@ public interface UserFederatedStorageProvider extends Provider, UserFederatedUserCredentialStore { ... - Stream getGroupsStream(RealmModel realm, String userId) - void joinGroup(RealmModel realm, String userId, GroupModel group); - void leaveGroup(RealmModel realm, String userId, GroupModel group); - Stream getMembershipStream(RealmModel realm, GroupModel group, Integer firstResult, Integer max); - - ... - - interface Streams extends UserFederatedStorageProvider, - UserAttributeFederatedStorage.Streams, - UserBrokerLinkFederatedStorage.Streams, - UserConsentFederatedStorage.Streams, - UserFederatedUserCredentialStore.Streams, - UserGroupMembershipFederatedStorage.Streams, - UserRequiredActionsFederatedStorage.Streams, - UserRoleMappingsFederatedStorage.Streams { - - ... - - @Override - default List getStoredUsers(RealmModel realm, int first, int max) { - return this.getStoredUsersStream(realm, first, max).collect(Collectors.toList()); - } - - @Override - Stream getStoredUsersStream(RealmModel realm, Integer first, Integer max); - - ... - } } ---- -The `UserFederatedStorageProvider` instance is available on the `KeycloakSession.userFederatedStorage()` method. +The `UserFederatedStorageProvider` instance is available on the `UserStorageUtil.userFederatedStorage(KeycloakSession)` method. It has all different kinds of methods for storing attributes, group and role mappings, different credential types, and required actions. If your external store's datamodel cannot support the full {project_name} feature set, then this service can fill in the gaps. -Also, the `UserFederatedStorageProvider.Streams` interface exists. It makes all collection-based methods in `UserFederatedStorageProvider` -default by providing implementations that delegate to the stream-based variants instead of the other way around. -It allows for implementations to focus on the stream-based approach for processing sets of data and benefit -from the potential memory and performance optimizations of that approach. See <<_stream_based_interfaces,Stream-based interfaces>> for more information. - {project_name} comes with a helper class `org.keycloak.storage.adapter.AbstractUserAdapterFederatedStorage` that will delegate every single `UserModel` method except get/set of username to user federated storage. Override the methods you need to override to delegate to your external storage representations. It is strongly diff --git a/docs/documentation/upgrading/topics/keycloak/changes-22_0_0.adoc b/docs/documentation/upgrading/topics/keycloak/changes-22_0_0.adoc index 6d2d6ed219..9a58e6563f 100644 --- a/docs/documentation/upgrading/topics/keycloak/changes-22_0_0.adoc +++ b/docs/documentation/upgrading/topics/keycloak/changes-22_0_0.adoc @@ -334,4 +334,18 @@ If you are extending the server's REST APIs through the following SPIs: You need to add an empty `META-INF/beans.xml` to the JAR file where your custom providers are packaged. Otherwise, they are not recognized by the server at runtime. -You should also make sure your JAX-RS methods are declaring the expected media types for input and output by marking them with the `@Consumes` and `@Produces` annotations, respectively. \ No newline at end of file +You should also make sure your JAX-RS methods are declaring the expected media types for input and output by marking them with the `@Consumes` and `@Produces` annotations, respectively. + += Deprecated methods from data providers and models + +In earlier versions of Keycloak, provider and model interfaces underwent a cleanup process that involved deprecating certain methods. +In this release the methods were removed and some additional methods were deprecated. The Javadoc for these methods from Keycloak 21 included information about +their corresponding replacements. + +* `RealmModel#searchForGroupByNameStream(String, Integer, Integer)` was removed. +* `UserProvider#getUsersStream(RealmModel, boolean)` was removed. +* `UserSessionPersisterProvider#loadUserSessions(int, int, boolean, int, String)` was removed. +* Interfaces added for Streamification work were removed. Such as `RoleMapperModel.Streams` and similar. +* `Streams` interfaces in federated storage provider classes were deprecated. +* `KeycloakModelUtils#getClientScopeMappings` was removed. +* Deprecated methods from `KeycloakSession` were removed. diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/RealmAdapter.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/RealmAdapter.java index fbe92eae5d..e3a63f12af 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/RealmAdapter.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/RealmAdapter.java @@ -1446,12 +1446,6 @@ public class RealmAdapter implements CachedRealmModel { return cacheSession.getTopLevelGroupsStream(this, first, max); } - @Override - @Deprecated - public Stream searchForGroupByNameStream(String search, Integer first, Integer max) { - return cacheSession.searchForGroupByNameStream( this, search, false, first, max); - } - @Override public boolean removeGroup(GroupModel group) { return cacheSession.removeGroup(this, group); diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java b/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java index 2680759dea..015efe6b5c 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java @@ -1923,12 +1923,6 @@ public class RealmAdapter implements LegacyRealmModel, JpaModel { return session.groups().getTopLevelGroupsStream(this, first, max); } - @Override - @Deprecated - public Stream searchForGroupByNameStream(String search, Integer first, Integer max) { - return session.groups().searchForGroupByNameStream(this, search, false, first, max); - } - @Override public boolean removeGroup(GroupModel group) { return session.groups().removeGroup(this, group); diff --git a/model/jpa/src/main/java/org/keycloak/storage/jpa/JpaUserFederatedStorageProvider.java b/model/jpa/src/main/java/org/keycloak/storage/jpa/JpaUserFederatedStorageProvider.java index d8c537455a..72d5033604 100644 --- a/model/jpa/src/main/java/org/keycloak/storage/jpa/JpaUserFederatedStorageProvider.java +++ b/model/jpa/src/main/java/org/keycloak/storage/jpa/JpaUserFederatedStorageProvider.java @@ -71,7 +71,7 @@ import static org.keycloak.utils.StreamsUtil.closing; * @version $Revision: 1 $ */ public class JpaUserFederatedStorageProvider implements - UserFederatedStorageProvider.Streams, + UserFederatedStorageProvider, UserCredentialStore { protected static final Logger logger = Logger.getLogger(JpaUserFederatedStorageProvider.class); diff --git a/model/legacy-private/src/main/java/org/keycloak/models/session/UserSessionPersisterProvider.java b/model/legacy-private/src/main/java/org/keycloak/models/session/UserSessionPersisterProvider.java index 7d903d96b3..c254981923 100644 --- a/model/legacy-private/src/main/java/org/keycloak/models/session/UserSessionPersisterProvider.java +++ b/model/legacy-private/src/main/java/org/keycloak/models/session/UserSessionPersisterProvider.java @@ -25,9 +25,7 @@ import org.keycloak.models.UserSessionModel; import org.keycloak.provider.Provider; import java.util.Collection; -import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -88,15 +86,6 @@ public interface UserSessionPersisterProvider extends Provider { */ Stream loadUserSessionsStream(RealmModel realm, ClientModel client, boolean offline, Integer firstResult, Integer maxResults); - /** - * Called during startup. For each userSession, it loads also clientSessions - * @deprecated Use {@link #loadUserSessionsStream(Integer, Integer, boolean, String) loadUserSessionsStream} instead. - */ - @Deprecated - default List loadUserSessions(int firstResult, int maxResults, boolean offline, int lastCreatedOn, String lastUserSessionId) { - return loadUserSessionsStream(firstResult, maxResults, offline, lastUserSessionId).collect(Collectors.toList()); - } - /** * Called during startup. For each userSession, it loads also clientSessions. * @param firstResult {@code Integer} Index of the first desired user session. Ignored if negative or {@code null}. diff --git a/model/legacy-private/src/main/java/org/keycloak/storage/adapter/InMemoryUserAdapter.java b/model/legacy-private/src/main/java/org/keycloak/storage/adapter/InMemoryUserAdapter.java index dc8c69dda0..76cd17a762 100644 --- a/model/legacy-private/src/main/java/org/keycloak/storage/adapter/InMemoryUserAdapter.java +++ b/model/legacy-private/src/main/java/org/keycloak/storage/adapter/InMemoryUserAdapter.java @@ -41,7 +41,7 @@ import java.util.stream.Stream; * @author Bill Burke * @version $Revision: 1 $ */ -public class InMemoryUserAdapter extends UserModelDefaultMethods.Streams { +public class InMemoryUserAdapter extends UserModelDefaultMethods { private Long createdTimestamp = Time.currentTimeMillis(); private boolean emailVerified; private boolean enabled; diff --git a/services/src/main/java/org/keycloak/services/legacysessionsupport/LegacySessionSupportProviderFactory.java b/model/legacy-services/src/main/java/org/keycloak/services/legacysessionsupport/LegacySessionSupportProviderFactory.java similarity index 100% rename from services/src/main/java/org/keycloak/services/legacysessionsupport/LegacySessionSupportProviderFactory.java rename to model/legacy-services/src/main/java/org/keycloak/services/legacysessionsupport/LegacySessionSupportProviderFactory.java diff --git a/model/legacy-services/src/main/java/org/keycloak/services/legacysessionsupport/LegacySessionSupportProviderImpl.java b/model/legacy-services/src/main/java/org/keycloak/services/legacysessionsupport/LegacySessionSupportProviderImpl.java index c3a1c431aa..73860a0145 100644 --- a/model/legacy-services/src/main/java/org/keycloak/services/legacysessionsupport/LegacySessionSupportProviderImpl.java +++ b/model/legacy-services/src/main/java/org/keycloak/services/legacysessionsupport/LegacySessionSupportProviderImpl.java @@ -46,9 +46,4 @@ public class LegacySessionSupportProviderImpl implements LegacySessionSupportPro return new UserCredentialStoreManager(session); } - @Override - public UserCache userCache() { - return session.getProvider(UserCache.class); - } - } diff --git a/services/src/main/java/org/keycloak/services/legacysessionsupport/LegacySessionSupportSpi.java b/model/legacy-services/src/main/java/org/keycloak/services/legacysessionsupport/LegacySessionSupportSpi.java similarity index 100% rename from services/src/main/java/org/keycloak/services/legacysessionsupport/LegacySessionSupportSpi.java rename to model/legacy-services/src/main/java/org/keycloak/services/legacysessionsupport/LegacySessionSupportSpi.java diff --git a/model/legacy-services/src/main/resources/META-INF/services/org.keycloak.provider.Spi b/model/legacy-services/src/main/resources/META-INF/services/org.keycloak.provider.Spi new file mode 100644 index 0000000000..eb71290fb7 --- /dev/null +++ b/model/legacy-services/src/main/resources/META-INF/services/org.keycloak.provider.Spi @@ -0,0 +1,18 @@ +# +# Copyright 2023 Red Hat, Inc. and/or its affiliates +# and other contributors as indicated by the @author tags. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +org.keycloak.services.legacysessionsupport.LegacySessionSupportSpi \ No newline at end of file diff --git a/server-spi-private/src/main/java/org/keycloak/models/LegacySessionSupportProvider.java b/model/legacy/src/main/java/org/keycloak/models/LegacySessionSupportProvider.java similarity index 95% rename from server-spi-private/src/main/java/org/keycloak/models/LegacySessionSupportProvider.java rename to model/legacy/src/main/java/org/keycloak/models/LegacySessionSupportProvider.java index 0e39999d18..d1de386bfd 100644 --- a/server-spi-private/src/main/java/org/keycloak/models/LegacySessionSupportProvider.java +++ b/model/legacy/src/main/java/org/keycloak/models/LegacySessionSupportProvider.java @@ -30,6 +30,4 @@ public interface LegacySessionSupportProvider extends Provider { @Deprecated UserCredentialManager userCredentialManager(); - @Deprecated - UserProvider userCache(); } diff --git a/server-spi/src/main/java/org/keycloak/models/UserCredentialManager.java b/model/legacy/src/main/java/org/keycloak/models/UserCredentialManager.java similarity index 99% rename from server-spi/src/main/java/org/keycloak/models/UserCredentialManager.java rename to model/legacy/src/main/java/org/keycloak/models/UserCredentialManager.java index 188fa6cf04..3e66f52145 100644 --- a/server-spi/src/main/java/org/keycloak/models/UserCredentialManager.java +++ b/model/legacy/src/main/java/org/keycloak/models/UserCredentialManager.java @@ -21,8 +21,6 @@ import org.keycloak.credential.CredentialModel; import org.keycloak.credential.UserCredentialStore; import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; import java.util.stream.Stream; /** diff --git a/model/legacy/src/main/java/org/keycloak/models/UserModelDefaultMethods.java b/model/legacy/src/main/java/org/keycloak/models/UserModelDefaultMethods.java index b5005d295a..7ccd6a0777 100644 --- a/model/legacy/src/main/java/org/keycloak/models/UserModelDefaultMethods.java +++ b/model/legacy/src/main/java/org/keycloak/models/UserModelDefaultMethods.java @@ -17,8 +17,6 @@ package org.keycloak.models; -import java.util.stream.Stream; - /** * @author Martin Idel * @version $Revision: 1 $ @@ -60,13 +58,4 @@ public abstract class UserModelDefaultMethods implements UserModel { public String toString() { return getClass().getName() + "@" + getId(); } - - - /** - * @deprecated This interface is no longer necessary, collection-based methods were removed from the parent interface - * and therefore the parent interface can be used directly - */ - @Deprecated - public abstract static class Streams extends UserModelDefaultMethods implements UserModel { - } } diff --git a/model/legacy/src/main/java/org/keycloak/models/cache/CachedUserModel.java b/model/legacy/src/main/java/org/keycloak/models/cache/CachedUserModel.java index 524ea88ecc..b00b566b40 100644 --- a/model/legacy/src/main/java/org/keycloak/models/cache/CachedUserModel.java +++ b/model/legacy/src/main/java/org/keycloak/models/cache/CachedUserModel.java @@ -17,7 +17,6 @@ package org.keycloak.models.cache; import org.keycloak.models.UserModel; -import org.keycloak.models.UserProvider; import java.util.concurrent.ConcurrentMap; @@ -57,12 +56,4 @@ public interface CachedUserModel extends UserModel { * @return */ ConcurrentMap getCachedWith(); - - /** - * @deprecated This interface is no longer necessary, collection-based methods were removed from the parent interface - * and therefore the parent interface can be used directly - */ - @Deprecated - interface Streams extends CachedUserModel, UserModel.Streams { - } } diff --git a/model/legacy/src/main/java/org/keycloak/models/cache/UserCache.java b/model/legacy/src/main/java/org/keycloak/models/cache/UserCache.java index 0f2d2aa898..ab7080817f 100755 --- a/model/legacy/src/main/java/org/keycloak/models/cache/UserCache.java +++ b/model/legacy/src/main/java/org/keycloak/models/cache/UserCache.java @@ -47,12 +47,4 @@ public interface UserCache extends UserProvider { * */ void clear(); - - /** - * @deprecated This interface is no longer necessary, collection-based methods were removed from the parent interface - * and therefore the parent interface can be used directly - */ - @Deprecated - interface Streams extends UserCache, UserProvider.Streams { - } } diff --git a/model/legacy/src/main/java/org/keycloak/storage/adapter/AbstractUserAdapterFederatedStorage.java b/model/legacy/src/main/java/org/keycloak/storage/adapter/AbstractUserAdapterFederatedStorage.java index 219cf0bfee..5e594a4da7 100644 --- a/model/legacy/src/main/java/org/keycloak/storage/adapter/AbstractUserAdapterFederatedStorage.java +++ b/model/legacy/src/main/java/org/keycloak/storage/adapter/AbstractUserAdapterFederatedStorage.java @@ -33,7 +33,6 @@ import org.keycloak.storage.UserStorageUtil; import org.keycloak.storage.federated.UserFederatedStorageProvider; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -73,16 +72,9 @@ public abstract class AbstractUserAdapterFederatedStorage extends UserModelDefau return UserStorageUtil.userFederatedStorage(session); } - /** - * @deprecated Use {@link #getRequiredActionsStream()} instead - */ - public Set getRequiredActions() { - return getFederatedStorage().getRequiredActions(realm, this.getId()); - } - @Override public Stream getRequiredActionsStream() { - return getRequiredActions().stream(); + return getFederatedStorage().getRequiredActionsStream(realm, this.getId()); } @Override @@ -94,7 +86,6 @@ public abstract class AbstractUserAdapterFederatedStorage extends UserModelDefau @Override public void removeRequiredAction(String action) { getFederatedStorage().removeRequiredAction(realm, this.getId(), action); - } @Override @@ -133,20 +124,12 @@ public abstract class AbstractUserAdapterFederatedStorage extends UserModelDefau * Also calls getGroupsInternal() method * to pull group membership from provider. Implementors can override that method * - * - * @return - * @deprecated Use {@link #getGroupsStream()} instead */ - public Set getGroups() { - Set set = new HashSet<>(getFederatedStorage().getGroups(realm, this.getId())); - if (appendDefaultGroups()) set.addAll(realm.getDefaultGroupsStream().collect(Collectors.toSet())); - set.addAll(getGroupsInternal()); - return set; - } - @Override public Stream getGroupsStream() { - return getGroups().stream(); + Stream groups = getFederatedStorage().getGroupsStream(realm, this.getId()); + if (appendDefaultGroups()) groups = Stream.concat(groups, realm.getDefaultGroupsStream()); + return Stream.concat(groups, getGroupsInternal().stream()); } @Override @@ -163,56 +146,38 @@ public abstract class AbstractUserAdapterFederatedStorage extends UserModelDefau @Override public boolean isMemberOf(GroupModel group) { - return RoleUtils.isMember(getGroups().stream(), group); + return RoleUtils.isMember(getGroupsStream(), group); } /** * Gets role mappings from federated storage and automatically appends default roles. * Also calls getRoleMappingsInternal() method * to pull role mappings from provider. Implementors can override that method - * - * - * @return - * - * @deprecated Use {@link #getRealmRoleMappingsStream()} instead */ - public Set getRealmRoleMappings() { - return this.getRoleMappings().stream().filter(RoleUtils::isRealmRole).collect(Collectors.toSet()); - } - @Override public Stream getRealmRoleMappingsStream() { - return getRealmRoleMappings().stream(); + return this.getRoleMappingsStream().filter(RoleUtils::isRealmRole); } /** * Gets role mappings from federated storage and automatically appends default roles. * Also calls getRoleMappingsInternal() method * to pull role mappings from provider. Implementors can override that method - * - * - * @return - * @deprecated Use {@link #getClientRoleMappingsStream(ClientModel)} instead */ - public Set getClientRoleMappings(ClientModel app) { - return getRoleMappings().stream().filter(r -> RoleUtils.isClientRole(r, app)).collect(Collectors.toSet()); - } - @Override public Stream getClientRoleMappingsStream(ClientModel app) { - return getClientRoleMappings(app).stream(); + return getRoleMappingsStream().filter(r -> RoleUtils.isClientRole(r, app)); } @Override public boolean hasRole(RoleModel role) { - return RoleUtils.hasRole(getRoleMappings().stream(), role) - || RoleUtils.hasRoleFromGroup(getGroups().stream(), role, true); + return RoleUtils.hasRole(getRoleMappingsStream(), role) + || RoleUtils.hasRoleFromGroup(getGroupsStream(), role, true); } @Override public void grantRole(RoleModel role) { getFederatedStorage().grantRole(realm, this.getId(), role); - } /** @@ -234,25 +199,26 @@ public abstract class AbstractUserAdapterFederatedStorage extends UserModelDefau * Gets role mappings from federated storage and automatically appends default roles. * Also calls getRoleMappingsInternal() method * to pull role mappings from provider. Implementors can override that method - * - * @return - * - * @deprecated Use {@link #getRoleMappingsStream()} instead */ - public Set getRoleMappings() { - Set set = new HashSet<>(getFederatedRoleMappings()); - if (appendDefaultRolesToRoleMappings()) set.addAll(realm.getDefaultRole().getCompositesStream().collect(Collectors.toSet())); - set.addAll(getRoleMappingsInternal()); - return set; - } - @Override public Stream getRoleMappingsStream() { - return getRoleMappings().stream(); + Stream roleMappings = getFederatedRoleMappingsStream(); + if (appendDefaultRolesToRoleMappings()) { + roleMappings = Stream.concat(roleMappings, realm.getDefaultRole().getCompositesStream()); + } + return Stream.concat(roleMappings, getRoleMappingsInternal().stream()); } + /** + * @deprecated Use {@link #getFederatedRoleMappingsStream()} instead + */ + @Deprecated protected Set getFederatedRoleMappings() { - return getFederatedStorage().getRoleMappings(realm, this.getId()); + return getFederatedRoleMappingsStream().collect(Collectors.toSet()); + } + + protected Stream getFederatedRoleMappingsStream() { + return getFederatedStorage().getRoleMappingsStream(realm, this.getId()); } @Override @@ -363,7 +329,7 @@ public abstract class AbstractUserAdapterFederatedStorage extends UserModelDefau @Override public void setAttribute(String name, List values) { if (UserModel.USERNAME.equals(name)) { - setUsername((values != null && values.size() > 0) ? values.get(0) : null); + setUsername((values != null && !values.isEmpty()) ? values.get(0) : null); } else { getFederatedStorage().setAttribute(realm, this.getId(), mapAttribute(name), values); } @@ -393,20 +359,13 @@ public abstract class AbstractUserAdapterFederatedStorage extends UserModelDefau return attributes; } - /** - * @deprecated Use {@link #getAttributeStream(String)} instead - */ - public List getAttribute(String name) { - if (UserModel.USERNAME.equals(name)) { - return Collections.singletonList(getUsername()); - } - List result = getFederatedStorage().getAttributes(realm, this.getId()).get(mapAttribute(name)); - return (result == null) ? Collections.emptyList() : result; - } - @Override public Stream getAttributeStream(String name) { - return getAttribute(name).stream(); + if (UserModel.USERNAME.equals(name)) { + return Stream.of(getUsername()); + } + List result = getFederatedStorage().getAttributes(realm, this.getId()).get(mapAttribute(name)); + return (result == null) ? Stream.empty() : result.stream(); } protected String mapAttribute(String attributeName) { @@ -459,101 +418,14 @@ public abstract class AbstractUserAdapterFederatedStorage extends UserModelDefau } /** - * The {@link Streams} interface makes all collection-based methods in {@link AbstractUserAdapterFederatedStorage} default by providing - * implementations that delegate to the {@link Stream}-based variants instead of the other way around. - *

- * It allows for implementations to focus on the {@link Stream}-based approach for processing sets of data and benefit - * from the potential memory and performance optimizations of that approach. + * @deprecated This interface is no longer necessary; collection-based methods were removed from the parent interface + * and therefore the parent interface can be used directly */ + @Deprecated public abstract static class Streams extends AbstractUserAdapterFederatedStorage implements UserModel { public Streams(final KeycloakSession session, final RealmModel realm, final ComponentModel storageProviderModel) { super(session, realm, storageProviderModel); } - - // user-related methods. - - @Override - public Set getRequiredActions() { - return this.getRequiredActionsStream().collect(Collectors.toSet()); - } - - @Override - public Stream getRequiredActionsStream() { - return super.getFederatedStorage().getRequiredActionsStream(super.realm, super.getId()); - } - - @Override - public List getAttribute(String name) { - return this.getAttributeStream(name).collect(Collectors.toList()); - } - - @Override - public Stream getAttributeStream(String name) { - if (UserModel.USERNAME.equals(name)) { - return Stream.of(getUsername()); - } - List result = super.getFederatedStorage().getAttributes(realm, this.getId()).get(super.mapAttribute(name)); - return (result == null) ? Stream.empty() : result.stream(); - } - - // group-related methods. - - @Override - public Set getGroups() { - return this.getGroupsStream().collect(Collectors.toSet()); - } - - @Override - public Stream getGroupsStream() { - Stream groups = getFederatedStorage().getGroupsStream(realm, this.getId()); - if (appendDefaultGroups()) groups = Stream.concat(groups, realm.getDefaultGroupsStream()); - return Stream.concat(groups, getGroupsInternal().stream()); - } - - @Override - public boolean isMemberOf(GroupModel group) { - return RoleUtils.isMember(this.getGroupsStream(), group); - } - - // role-related methods. - - @Override - public Set getRealmRoleMappings() { - return this.getRealmRoleMappingsStream().collect(Collectors.toSet()); - } - - @Override - public Stream getRealmRoleMappingsStream() { - return getRoleMappingsStream().filter(RoleUtils::isRealmRole); - } - - @Override - public Set getClientRoleMappings(ClientModel app) { - return this.getClientRoleMappingsStream(app).collect(Collectors.toSet()); - } - - @Override - public Stream getClientRoleMappingsStream(ClientModel app) { - return getRoleMappingsStream().filter(r -> RoleUtils.isClientRole(r, app)); - } - - @Override - public Set getRoleMappings() { - return this.getRoleMappingsStream().collect(Collectors.toSet()); - } - - @Override - public Stream getRoleMappingsStream() { - Stream roleMappings = getFederatedRoleMappings().stream(); - if (appendDefaultRolesToRoleMappings()) roleMappings = Stream.concat(roleMappings, realm.getDefaultRole().getCompositesStream()); - return Stream.concat(roleMappings, getRoleMappingsInternal().stream()); - } - - @Override - public boolean hasRole(RoleModel role) { - return RoleUtils.hasRole(this.getRoleMappingsStream(), role) - || RoleUtils.hasRoleFromGroup(this.getGroupsStream(), role, true); - } } } diff --git a/model/legacy/src/main/java/org/keycloak/storage/federated/UserAttributeFederatedStorage.java b/model/legacy/src/main/java/org/keycloak/storage/federated/UserAttributeFederatedStorage.java index c27ca677b8..f3da662b51 100644 --- a/model/legacy/src/main/java/org/keycloak/storage/federated/UserAttributeFederatedStorage.java +++ b/model/legacy/src/main/java/org/keycloak/storage/federated/UserAttributeFederatedStorage.java @@ -20,7 +20,6 @@ import org.keycloak.common.util.MultivaluedHashMap; import org.keycloak.models.RealmModel; import java.util.List; -import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -33,12 +32,6 @@ public interface UserAttributeFederatedStorage { void removeAttribute(RealmModel realm, String userId, String name); MultivaluedHashMap getAttributes(RealmModel realm, String userId); - /** - * @deprecated Use {@link #getUsersByUserAttributeStream(RealmModel, String, String) getUsersByUserAttributeStream} instead. - */ - @Deprecated - List getUsersByUserAttribute(RealmModel realm, String name, String value); - /** * Searches for federated users that have an attribute with the specified {@code name} and {@code value}. * @@ -47,27 +40,13 @@ public interface UserAttributeFederatedStorage { * @param value the attribute value. * @return a non-null {@link Stream} of users that match the search criteria. */ - default Stream getUsersByUserAttributeStream(RealmModel realm, String name, String value) { - List users = this.getUsersByUserAttribute(realm, name, value); - return users != null ? users.stream() : Stream.empty(); - } + Stream getUsersByUserAttributeStream(RealmModel realm, String name, String value); /** - * The {@link Streams} interface makes all collection-based methods in {@link UserAttributeFederatedStorage} - * default by providing implementations that delegate to the {@link Stream}-based variants instead of the other way - * around. - *

- * It allows for implementations to focus on the {@link Stream}-based approach for processing sets of data and benefit - * from the potential memory and performance optimizations of that approach. + * @deprecated This interface is no longer necessary; collection-based methods were removed from the parent interface + * and therefore the parent interface can be used directly */ + @Deprecated interface Streams extends UserAttributeFederatedStorage { - - @Override - default List getUsersByUserAttribute(RealmModel realm, String name, String value) { - return this.getUsersByUserAttributeStream(realm, name, value).collect(Collectors.toList()); - } - - @Override - Stream getUsersByUserAttributeStream(RealmModel realm, String name, String value); } } diff --git a/model/legacy/src/main/java/org/keycloak/storage/federated/UserBrokerLinkFederatedStorage.java b/model/legacy/src/main/java/org/keycloak/storage/federated/UserBrokerLinkFederatedStorage.java index e0140cd148..5ddc9cfdd5 100644 --- a/model/legacy/src/main/java/org/keycloak/storage/federated/UserBrokerLinkFederatedStorage.java +++ b/model/legacy/src/main/java/org/keycloak/storage/federated/UserBrokerLinkFederatedStorage.java @@ -20,8 +20,6 @@ import org.keycloak.models.FederatedIdentityModel; import org.keycloak.models.IdentityProviderModel; import org.keycloak.models.RealmModel; -import java.util.Set; -import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -35,12 +33,6 @@ public interface UserBrokerLinkFederatedStorage { void preRemove(RealmModel realm, IdentityProviderModel provider); void updateFederatedIdentity(RealmModel realm, String userId, FederatedIdentityModel federatedIdentityModel); - /** - * @deprecated Use {@link #getFederatedIdentitiesStream(String, RealmModel) getFederatedIdentitiesStream} instead. - */ - @Deprecated - Set getFederatedIdentities(String userId, RealmModel realm); - /** * Obtains the identities of the federated user identified by {@code userId}. * @@ -48,28 +40,15 @@ public interface UserBrokerLinkFederatedStorage { * @param realm a reference to the realm. * @return a non-null {@link Stream} of federated identities associated with the user. */ - default Stream getFederatedIdentitiesStream(String userId, RealmModel realm) { - Set value = this.getFederatedIdentities(userId, realm); - return value != null ? value.stream() : Stream.empty(); - } + Stream getFederatedIdentitiesStream(String userId, RealmModel realm); FederatedIdentityModel getFederatedIdentity(String userId, String socialProvider, RealmModel realm); /** - * The {@link Streams} interface makes all collection-based methods in {@link UserBrokerLinkFederatedStorage} - * default by providing implementations that delegate to the {@link Stream}-based variants instead of the other way - * around. - *

- * It allows for implementations to focus on the {@link Stream}-based approach for processing sets of data and benefit - * from the potential memory and performance optimizations of that approach. + * @deprecated This interface is no longer necessary; collection-based methods were removed from the parent interface + * and therefore the parent interface can be used directly */ + @Deprecated interface Streams extends UserBrokerLinkFederatedStorage { - @Override - default Set getFederatedIdentities(String userId, RealmModel realm) { - return this.getFederatedIdentitiesStream(userId, realm).collect(Collectors.toSet()); - } - - @Override - Stream getFederatedIdentitiesStream(String userId, RealmModel realm); } } diff --git a/model/legacy/src/main/java/org/keycloak/storage/federated/UserConsentFederatedStorage.java b/model/legacy/src/main/java/org/keycloak/storage/federated/UserConsentFederatedStorage.java index f0078d5e5f..768b354313 100644 --- a/model/legacy/src/main/java/org/keycloak/storage/federated/UserConsentFederatedStorage.java +++ b/model/legacy/src/main/java/org/keycloak/storage/federated/UserConsentFederatedStorage.java @@ -19,8 +19,6 @@ package org.keycloak.storage.federated; import org.keycloak.models.RealmModel; import org.keycloak.models.UserConsentModel; -import java.util.List; -import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -31,12 +29,6 @@ public interface UserConsentFederatedStorage { void addConsent(RealmModel realm, String userId, UserConsentModel consent); UserConsentModel getConsentByClient(RealmModel realm, String userId, String clientInternalId); - /** - * @deprecated Use {@link #getConsentsStream(RealmModel, String) getConsentsStream} instead. - */ - @Deprecated - List getConsents(RealmModel realm, String userId); - /** * Obtains the consents associated with the federated user identified by {@code userId}. * @@ -44,29 +36,16 @@ public interface UserConsentFederatedStorage { * @param userId the user identifier. * @return a non-null {@link Stream} of consents associated with the user. */ - default Stream getConsentsStream(RealmModel realm, String userId) { - List value = this.getConsents(realm, userId); - return value != null ? value.stream() : Stream.empty(); - } + Stream getConsentsStream(RealmModel realm, String userId); void updateConsent(RealmModel realm, String userId, UserConsentModel consent); boolean revokeConsentForClient(RealmModel realm, String userId, String clientInternalId); /** - * The {@link Streams} interface makes all collection-based methods in {@link UserConsentFederatedStorage} - * default by providing implementations that delegate to the {@link Stream}-based variants instead of the other way - * around. - *

- * It allows for implementations to focus on the {@link Stream}-based approach for processing sets of data and benefit - * from the potential memory and performance optimizations of that approach. + * @deprecated This interface is no longer necessary, collection-based methods were removed from the parent interface + * and therefore the parent interface can be used directly */ + @Deprecated interface Streams extends UserConsentFederatedStorage { - @Override - default List getConsents(RealmModel realm, String userId) { - return this.getConsentsStream(realm, userId).collect(Collectors.toList()); - } - - @Override - Stream getConsentsStream(RealmModel realm, String userId); } } diff --git a/model/legacy/src/main/java/org/keycloak/storage/federated/UserFederatedStorageProvider.java b/model/legacy/src/main/java/org/keycloak/storage/federated/UserFederatedStorageProvider.java index fcc66212dc..345ab7d0be 100755 --- a/model/legacy/src/main/java/org/keycloak/storage/federated/UserFederatedStorageProvider.java +++ b/model/legacy/src/main/java/org/keycloak/storage/federated/UserFederatedStorageProvider.java @@ -27,8 +27,6 @@ import org.keycloak.models.RoleModel; import org.keycloak.models.UserModel; import org.keycloak.provider.Provider; -import java.util.List; -import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -45,12 +43,6 @@ public interface UserFederatedStorageProvider extends Provider, UserRoleMappingsFederatedStorage, UserFederatedUserCredentialStore { - /** - * @deprecated Use {@link #getStoredUsersStream(RealmModel, Integer, Integer) getStoredUsersStream} instead. - */ - @Deprecated - List getStoredUsers(RealmModel realm, int first, int max); - /** * Obtains the ids of all federated users in the realm. * @@ -59,10 +51,7 @@ public interface UserFederatedStorageProvider extends Provider, * @param max maximum number of results to return. Ignored if negative or {@code null}. * @return a non-null {@link Stream} of federated user ids. */ - default Stream getStoredUsersStream(RealmModel realm, Integer first, Integer max) { - List value = this.getStoredUsers(realm, first, max); - return value != null ? value.stream() : Stream.empty(); - } + Stream getStoredUsersStream(RealmModel realm, Integer first, Integer max); int getStoredUsersCount(RealmModel realm); @@ -83,13 +72,10 @@ public interface UserFederatedStorageProvider extends Provider, void preRemove(RealmModel realm, ComponentModel model); /** - * The {@link UserFederatedStorageProvider.Streams} interface makes all collection-based methods in {@link UserFederatedStorageProvider} - * default by providing implementations that delegate to the {@link Stream}-based variants instead of the other way - * around. - *

- * It allows for implementations to focus on the {@link Stream}-based approach for processing sets of data and benefit - * from the potential memory and performance optimizations of that approach. + * @deprecated This interface is no longer necessary; collection-based methods were removed from the parent interface + * and therefore the parent interface can be used directly */ + @Deprecated interface Streams extends UserFederatedStorageProvider, UserAttributeFederatedStorage.Streams, UserBrokerLinkFederatedStorage.Streams, @@ -98,13 +84,5 @@ public interface UserFederatedStorageProvider extends Provider, UserGroupMembershipFederatedStorage.Streams, UserRequiredActionsFederatedStorage.Streams, UserRoleMappingsFederatedStorage.Streams { - - @Override - default List getStoredUsers(RealmModel realm, int first, int max) { - return this.getStoredUsersStream(realm, first, max).collect(Collectors.toList()); - } - - @Override - Stream getStoredUsersStream(RealmModel realm, Integer first, Integer max); } } diff --git a/model/legacy/src/main/java/org/keycloak/storage/federated/UserFederatedUserCredentialStore.java b/model/legacy/src/main/java/org/keycloak/storage/federated/UserFederatedUserCredentialStore.java index 8b943d8fed..15f43c8679 100644 --- a/model/legacy/src/main/java/org/keycloak/storage/federated/UserFederatedUserCredentialStore.java +++ b/model/legacy/src/main/java/org/keycloak/storage/federated/UserFederatedUserCredentialStore.java @@ -20,8 +20,6 @@ import org.keycloak.credential.CredentialModel; import org.keycloak.models.RealmModel; import org.keycloak.provider.Provider; -import java.util.List; -import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -34,12 +32,6 @@ public interface UserFederatedUserCredentialStore extends Provider { boolean removeStoredCredential(RealmModel realm, String userId, String id); CredentialModel getStoredCredentialById(RealmModel realm, String userId, String id); - /** - * @deprecated Use {@link #getStoredCredentialsStream(RealmModel, String) getStoredCredentialsStream} instead. - */ - @Deprecated - List getStoredCredentials(RealmModel realm, String userId); - /** * Obtains the credentials associated with the federated user identified by {@code userId}. * @@ -47,16 +39,7 @@ public interface UserFederatedUserCredentialStore extends Provider { * @param userId the user identifier. * @return a non-null {@link Stream} of credentials. */ - default Stream getStoredCredentialsStream(RealmModel realm, String userId) { - List value = this.getStoredCredentials(realm, userId); - return value != null ? value.stream() : Stream.empty(); - } - - /** - * @deprecated Use {@link #getStoredCredentialsByTypeStream(RealmModel, String, String) getStoredCredentialsByTypeStream} instead. - */ - @Deprecated - List getStoredCredentialsByType(RealmModel realm, String userId, String type); + Stream getStoredCredentialsStream(RealmModel realm, String userId); /** * Obtains the credentials of type {@code type} that are associated with the federated user identified by {@code userId}. @@ -66,36 +49,15 @@ public interface UserFederatedUserCredentialStore extends Provider { * @param type the credential type. * @return a non-null {@link Stream} of credentials. */ - default Stream getStoredCredentialsByTypeStream(RealmModel realm, String userId, String type) { - List value = this.getStoredCredentialsByType(realm, userId, type); - return value != null ? value.stream() : Stream.empty(); - } + Stream getStoredCredentialsByTypeStream(RealmModel realm, String userId, String type); CredentialModel getStoredCredentialByNameAndType(RealmModel realm, String userId, String name, String type); /** - * The {@link Streams} interface makes all collection-based methods in {@link UserFederatedUserCredentialStore} - * default by providing implementations that delegate to the {@link Stream}-based variants instead of the other way - * around. - *

- * It allows for implementations to focus on the {@link Stream}-based approach for processing sets of data and benefit - * from the potential memory and performance optimizations of that approach. + * @deprecated This interface is no longer necessary; collection-based methods were removed from the parent interface + * and therefore the parent interface can be used directly */ + @Deprecated interface Streams extends UserFederatedUserCredentialStore { - @Override - default List getStoredCredentials(RealmModel realm, String userId) { - return this.getStoredCredentialsStream(realm, userId).collect(Collectors.toList()); - } - - @Override - Stream getStoredCredentialsStream(RealmModel realm, String userId); - - @Override - default List getStoredCredentialsByType(RealmModel realm, String userId, String type) { - return this.getStoredCredentialsByTypeStream(realm, userId, type).collect(Collectors.toList()); - } - - @Override - Stream getStoredCredentialsByTypeStream(RealmModel realm, String userId, String type); } } diff --git a/model/legacy/src/main/java/org/keycloak/storage/federated/UserGroupMembershipFederatedStorage.java b/model/legacy/src/main/java/org/keycloak/storage/federated/UserGroupMembershipFederatedStorage.java index 46189304a7..22b0ea5056 100644 --- a/model/legacy/src/main/java/org/keycloak/storage/federated/UserGroupMembershipFederatedStorage.java +++ b/model/legacy/src/main/java/org/keycloak/storage/federated/UserGroupMembershipFederatedStorage.java @@ -19,9 +19,6 @@ package org.keycloak.storage.federated; import org.keycloak.models.GroupModel; import org.keycloak.models.RealmModel; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -30,12 +27,6 @@ import java.util.stream.Stream; */ public interface UserGroupMembershipFederatedStorage { - /** - * @deprecated Use {@link #getGroupsStream(RealmModel, String) getGroupsStream} instead. - */ - @Deprecated - Set getGroups(RealmModel realm, String userId); - /** * Obtains the groups associated with the federated user. * @@ -43,20 +34,11 @@ public interface UserGroupMembershipFederatedStorage { * @param userId the user identifier. * @return a non-null {@code Stream} of groups. */ - default Stream getGroupsStream(RealmModel realm, String userId) { - Set value = this.getGroups(realm, userId); - return value != null ? value.stream() : Stream.empty(); - } + Stream getGroupsStream(RealmModel realm, String userId); void joinGroup(RealmModel realm, String userId, GroupModel group); void leaveGroup(RealmModel realm, String userId, GroupModel group); - /** - * @deprecated Use {@link #getMembershipStream(RealmModel, GroupModel, Integer, Integer) getMembershipStream} instead. - */ - @Deprecated - List getMembership(RealmModel realm, GroupModel group, int firstResult, int max); - /** * Obtains the federated users that are members of the given {@code group} in the specified {@code realm}. * @@ -66,34 +48,13 @@ public interface UserGroupMembershipFederatedStorage { * @param max maximum number of results to return. Ignored if negative or {@code null}. * @return a non-null {@code Stream} of federated user ids that are members of the group in the realm. */ - default Stream getMembershipStream(RealmModel realm, GroupModel group, Integer firstResult, Integer max) { - List value = this.getMembership(realm, group, firstResult, max); - return value != null ? value.stream() : Stream.empty(); - } + Stream getMembershipStream(RealmModel realm, GroupModel group, Integer firstResult, Integer max); /** - * The {@link Streams} interface makes all collection-based methods in {@link UserGroupMembershipFederatedStorage} - * default by providing implementations that delegate to the {@link Stream}-based variants instead of the other way - * around. - *

- * It allows for implementations to focus on the {@link Stream}-based approach for processing sets of data and benefit - * from the potential memory and performance optimizations of that approach. + * @deprecated This interface is no longer necessary; collection-based methods were removed from the parent interface + * and therefore the parent interface can be used directly */ + @Deprecated interface Streams extends UserGroupMembershipFederatedStorage { - @Override - default Set getGroups(RealmModel realm, String userId) { - return getGroupsStream(realm, userId).collect(Collectors.toSet()); - } - - @Override - Stream getGroupsStream(RealmModel realm, String userId); - - @Override - default List getMembership(RealmModel realm, GroupModel group, int firstResult, int max) { - return this.getMembershipStream(realm, group, firstResult, max).collect(Collectors.toList()); - } - - @Override - Stream getMembershipStream(RealmModel realm, GroupModel group, Integer firstResult, Integer max); } } diff --git a/model/legacy/src/main/java/org/keycloak/storage/federated/UserRequiredActionsFederatedStorage.java b/model/legacy/src/main/java/org/keycloak/storage/federated/UserRequiredActionsFederatedStorage.java index 165542aaf2..bea45f3491 100644 --- a/model/legacy/src/main/java/org/keycloak/storage/federated/UserRequiredActionsFederatedStorage.java +++ b/model/legacy/src/main/java/org/keycloak/storage/federated/UserRequiredActionsFederatedStorage.java @@ -18,8 +18,6 @@ package org.keycloak.storage.federated; import org.keycloak.models.RealmModel; -import java.util.Set; -import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -28,12 +26,6 @@ import java.util.stream.Stream; */ public interface UserRequiredActionsFederatedStorage { - /** - * @deprecated Use {@link #getRequiredActionsStream(RealmModel, String) getRequiredActionsStream} instead. - */ - @Deprecated - Set getRequiredActions(RealmModel realm, String userId); - /** * Obtains the names of required actions associated with the federated user identified by {@code userId}. * @@ -41,29 +33,16 @@ public interface UserRequiredActionsFederatedStorage { * @param userId the user identifier. * @return a non-null {@link Stream} of required action names. */ - default Stream getRequiredActionsStream(RealmModel realm, String userId) { - Set value = this.getRequiredActions(realm, userId); - return value != null ? value.stream() : Stream.empty(); - } + Stream getRequiredActionsStream(RealmModel realm, String userId); void addRequiredAction(RealmModel realm, String userId, String action); void removeRequiredAction(RealmModel realm, String userId, String action); /** - * The {@link Streams} interface makes all collection-based methods in {@link UserRequiredActionsFederatedStorage} - * default by providing implementations that delegate to the {@link Stream}-based variants instead of the other way - * around. - *

- * It allows for implementations to focus on the {@link Stream}-based approach for processing sets of data and benefit - * from the potential memory and performance optimizations of that approach. + * @deprecated This interface is no longer necessary; collection-based methods were removed from the parent interface + * and therefore the parent interface can be used directly */ + @Deprecated interface Streams extends UserRequiredActionsFederatedStorage { - @Override - default Set getRequiredActions(RealmModel realm, String userId) { - return this.getRequiredActionsStream(realm, userId).collect(Collectors.toSet()); - } - - @Override - Stream getRequiredActionsStream(RealmModel realm, String userId); } } diff --git a/model/legacy/src/main/java/org/keycloak/storage/federated/UserRoleMappingsFederatedStorage.java b/model/legacy/src/main/java/org/keycloak/storage/federated/UserRoleMappingsFederatedStorage.java index 3d8c0d0357..a63e70028f 100644 --- a/model/legacy/src/main/java/org/keycloak/storage/federated/UserRoleMappingsFederatedStorage.java +++ b/model/legacy/src/main/java/org/keycloak/storage/federated/UserRoleMappingsFederatedStorage.java @@ -19,8 +19,6 @@ package org.keycloak.storage.federated; import org.keycloak.models.RealmModel; import org.keycloak.models.RoleModel; -import java.util.Set; -import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -29,12 +27,6 @@ import java.util.stream.Stream; */ public interface UserRoleMappingsFederatedStorage { - /** - * @deprecated Use {@link #getRoleMappingsStream(RealmModel, String) getRoleMappingsStream} instead. - */ - @Deprecated - Set getRoleMappings(RealmModel realm,String userId); - void grantRole(RealmModel realm, String userId, RoleModel role); /** @@ -44,28 +36,15 @@ public interface UserRoleMappingsFederatedStorage { * @param userId the user identifier. * @return a non-null {@code Stream} of roles. */ - default Stream getRoleMappingsStream(RealmModel realm, String userId) { - Set value = this.getRoleMappings(realm, userId); - return value != null ? value.stream() : Stream.empty(); - } + Stream getRoleMappingsStream(RealmModel realm, String userId); void deleteRoleMapping(RealmModel realm, String userId, RoleModel role); /** - * The {@link Streams} interface makes all collection-based methods in {@link UserRoleMappingsFederatedStorage} - * default by providing implementations that delegate to the {@link Stream}-based variants instead of the other way - * around. - *

- * It allows for implementations to focus on the {@link Stream}-based approach for processing sets of data and benefit - * from the potential memory and performance optimizations of that approach. + * @deprecated This interface is no longer necessary; collection-based methods were removed from the parent interface + * and therefore the parent interface can be used directly */ + @Deprecated interface Streams extends UserRoleMappingsFederatedStorage { - @Override - default Set getRoleMappings(RealmModel realm, String userId) { - return getRoleMappingsStream(realm, userId).collect(Collectors.toSet()); - } - - @Override - Stream getRoleMappingsStream(RealmModel realm, String userId); } } diff --git a/model/map/src/main/java/org/keycloak/models/map/datastore/ImportKeycloakSession.java b/model/map/src/main/java/org/keycloak/models/map/datastore/ImportKeycloakSession.java index 2a1eb781f2..5c0cd117de 100644 --- a/model/map/src/main/java/org/keycloak/models/map/datastore/ImportKeycloakSession.java +++ b/model/map/src/main/java/org/keycloak/models/map/datastore/ImportKeycloakSession.java @@ -39,7 +39,6 @@ import org.keycloak.models.RoleSpi; import org.keycloak.models.SingleUseObjectProvider; import org.keycloak.models.ThemeManager; import org.keycloak.models.TokenManager; -import org.keycloak.models.UserCredentialManager; import org.keycloak.models.UserLoginFailureProvider; import org.keycloak.models.UserProvider; import org.keycloak.models.UserSessionProvider; @@ -275,89 +274,11 @@ public class ImportKeycloakSession implements KeycloakSession { session.close(); } - @Override - @Deprecated - public UserProvider userCache() { - throw new ModelException("not supported"); - } - @Override public UserProvider users() { return userProvider; } - @Override - @Deprecated - public ClientProvider clientStorageManager() { - throw new ModelException("not supported"); - } - - @Override - @Deprecated - public ClientScopeProvider clientScopeStorageManager() { - throw new ModelException("not supported"); - } - - @Override - @Deprecated - public RoleProvider roleStorageManager() { - throw new ModelException("not supported"); - } - - @Override - @Deprecated - public GroupProvider groupStorageManager() { - throw new ModelException("not supported"); - } - - @Override - @Deprecated - public UserProvider userStorageManager() { - throw new ModelException("not supported"); - } - - @Override - @Deprecated - public UserCredentialManager userCredentialManager() { - throw new ModelException("not supported"); - } - - @Override - @Deprecated - public UserProvider userLocalStorage() { - throw new ModelException("not supported"); - } - - @Override - @Deprecated - public RealmProvider realmLocalStorage() { - throw new ModelException("not supported"); - } - - @Override - @Deprecated - public ClientProvider clientLocalStorage() { - throw new ModelException("not supported"); - } - - @Override - @Deprecated - public ClientScopeProvider clientScopeLocalStorage() { - throw new ModelException("not supported"); - } - - @Override - @Deprecated - public GroupProvider groupLocalStorage() { - throw new ModelException("not supported"); - } - - @Override - @Deprecated - public RoleProvider roleLocalStorage() { - throw new ModelException("not supported"); - } - @Override public KeyManager keys() { throw new ModelException("not supported"); diff --git a/model/map/src/main/java/org/keycloak/models/map/realm/MapRealmAdapter.java b/model/map/src/main/java/org/keycloak/models/map/realm/MapRealmAdapter.java index 4e1f96daed..8c9c1a41de 100644 --- a/model/map/src/main/java/org/keycloak/models/map/realm/MapRealmAdapter.java +++ b/model/map/src/main/java/org/keycloak/models/map/realm/MapRealmAdapter.java @@ -1445,12 +1445,6 @@ public class MapRealmAdapter extends AbstractRealmModel implemen return session.groups().getTopLevelGroupsStream(this, first, max); } - @Override - @Deprecated - public Stream searchForGroupByNameStream(String search, Integer first, Integer max) { - return session.groups().searchForGroupByNameStream(this, search, false, first, max); - } - @Override public boolean removeGroup(GroupModel group) { return session.groups().removeGroup(this, group); diff --git a/server-spi-private/src/main/java/org/keycloak/models/utils/KeycloakModelUtils.java b/server-spi-private/src/main/java/org/keycloak/models/utils/KeycloakModelUtils.java index 3374402d77..38a06862f5 100755 --- a/server-spi-private/src/main/java/org/keycloak/models/utils/KeycloakModelUtils.java +++ b/server-spi-private/src/main/java/org/keycloak/models/utils/KeycloakModelUtils.java @@ -763,17 +763,6 @@ public final class KeycloakModelUtils { return normalized; } - /** - * @param client {@link ClientModel} - * @param container {@link ScopeContainerModel} - * @return - * @deprecated Use {@link #getClientScopeMappingsStream(ClientModel, ScopeContainerModel)} getClientScopeMappingsStream} instead. - */ - @Deprecated - public static Set getClientScopeMappings(ClientModel client, ScopeContainerModel container) { - return getClientScopeMappingsStream(client, container).collect(Collectors.toSet()); - } - public static Stream getClientScopeMappingsStream(ClientModel client, ScopeContainerModel container) { return container.getScopeMappingsStream() .filter(role -> role.getContainer() instanceof ClientModel && diff --git a/server-spi-private/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java b/server-spi-private/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java index fe53f42666..40bcaa6007 100755 --- a/server-spi-private/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java +++ b/server-spi-private/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java @@ -170,12 +170,6 @@ public class ModelToRepresentation { return groups.map(g -> toGroupHierarchy(g, full, attributes)); } - @Deprecated - public static Stream searchForGroupByName(RealmModel realm, boolean full, String search, Integer first, Integer max) { - return realm.searchForGroupByNameStream(search, first, max) - .map(g -> toGroupHierarchy(g, full, search)); - } - public static Stream searchForGroupByName(KeycloakSession session, RealmModel realm, boolean full, String search, Boolean exact, Integer first, Integer max) { return session.groups().searchForGroupByNameStream(realm, search, exact, first, max) .map(g -> toGroupHierarchy(g, full, search, exact)); diff --git a/server-spi-private/src/test/java/org/keycloak/broker/provider/util/IdentityBrokerStateTestHelpers.java b/server-spi-private/src/test/java/org/keycloak/broker/provider/util/IdentityBrokerStateTestHelpers.java index 96db5c8fb2..acea768b6e 100644 --- a/server-spi-private/src/test/java/org/keycloak/broker/provider/util/IdentityBrokerStateTestHelpers.java +++ b/server-spi-private/src/test/java/org/keycloak/broker/provider/util/IdentityBrokerStateTestHelpers.java @@ -1653,11 +1653,6 @@ public class IdentityBrokerStateTestHelpers { return null; } - @Override - public Stream searchForGroupByNameStream(String search, Integer first, Integer max) { - return null; - } - @Override public boolean removeGroup(GroupModel group) { return false; diff --git a/server-spi/src/main/java/org/keycloak/credential/CredentialInputUpdater.java b/server-spi/src/main/java/org/keycloak/credential/CredentialInputUpdater.java index 9f1e3b1dc6..7414fbc18f 100644 --- a/server-spi/src/main/java/org/keycloak/credential/CredentialInputUpdater.java +++ b/server-spi/src/main/java/org/keycloak/credential/CredentialInputUpdater.java @@ -19,8 +19,6 @@ package org.keycloak.credential; import org.keycloak.models.RealmModel; import org.keycloak.models.UserModel; -import java.util.Set; -import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -41,12 +39,4 @@ public interface CredentialInputUpdater { * @return a non-null {@link Stream} of credential types. */ Stream getDisableableCredentialTypesStream(RealmModel realm, UserModel user); - - /** - * @deprecated This interface is no longer necessary, collection-based methods were removed from the parent interface - * and therefore the parent interface can be used directly - */ - @Deprecated - interface Streams extends CredentialInputUpdater { - } } diff --git a/server-spi/src/main/java/org/keycloak/credential/UserCredentialStore.java b/server-spi/src/main/java/org/keycloak/credential/UserCredentialStore.java index 9d9a7e5bb2..b8ebedde59 100644 --- a/server-spi/src/main/java/org/keycloak/credential/UserCredentialStore.java +++ b/server-spi/src/main/java/org/keycloak/credential/UserCredentialStore.java @@ -17,12 +17,9 @@ package org.keycloak.credential; import org.keycloak.models.RealmModel; -import org.keycloak.models.SubjectCredentialManager; import org.keycloak.models.UserModel; import org.keycloak.provider.Provider; -import java.util.List; -import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -70,11 +67,4 @@ public interface UserCredentialStore extends Provider { //list operations boolean moveCredentialTo(RealmModel realm, UserModel user, String id, String newPreviousCredentialId); - /** - * @deprecated This interface is no longer necessary, collection-based methods were removed from the parent interface - * and therefore the parent interface can be used directly - */ - @Deprecated - interface Streams extends UserCredentialStore { - } } diff --git a/server-spi/src/main/java/org/keycloak/models/GroupModel.java b/server-spi/src/main/java/org/keycloak/models/GroupModel.java index 7edb5d537f..932e6627c2 100755 --- a/server-spi/src/main/java/org/keycloak/models/GroupModel.java +++ b/server-spi/src/main/java/org/keycloak/models/GroupModel.java @@ -23,8 +23,6 @@ import org.keycloak.storage.SearchableModelField; import java.util.Comparator; import java.util.List; import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -130,12 +128,4 @@ public interface GroupModel extends RoleMapperModel { * @param subGroup */ void removeChild(GroupModel subGroup); - - /** - * @deprecated This interface is no longer necessary, collection-based methods were removed from the parent interface - * and therefore the parent interface can be used directly - */ - @Deprecated - interface Streams extends GroupModel, RoleMapperModel { - } } diff --git a/server-spi/src/main/java/org/keycloak/models/KeycloakSession.java b/server-spi/src/main/java/org/keycloak/models/KeycloakSession.java index 6af9ef3d74..3b952b68c0 100755 --- a/server-spi/src/main/java/org/keycloak/models/KeycloakSession.java +++ b/server-spi/src/main/java/org/keycloak/models/KeycloakSession.java @@ -203,20 +203,8 @@ public interface KeycloakSession extends AutoCloseable { SingleUseObjectProvider singleUseObjects(); - - void close(); - /** - * The user cache - * - * @deprecated The access to the UserCache interface is no longer possible here, and this method is about to be removed. - * Adjust your code according to the Keycloak 19 Upgrading Guide. - * @return may be null if cache is disabled - */ - @Deprecated - UserProvider userCache(); - /** * A cached view of all users in system including users loaded by UserStorageProviders * @@ -224,88 +212,6 @@ public interface KeycloakSession extends AutoCloseable { */ UserProvider users(); - /** - * @return ClientStorageManager instance - */ - @Deprecated - ClientProvider clientStorageManager(); - - /** - * @return ClientScopeStorageManager instance - * @deprecated Use {@link #clientScopes()} instead - */ - @Deprecated - ClientScopeProvider clientScopeStorageManager(); - - /** - * @return RoleStorageManager instance - */ - @Deprecated - RoleProvider roleStorageManager(); - - /** - * @return GroupStorageManager instance - */ - @Deprecated - GroupProvider groupStorageManager(); - - /** - * Un-cached view of all users in system including users loaded by UserStorageProviders - * - * @return - */ - @Deprecated - UserProvider userStorageManager(); - - /** - * Service that allows you to valid and update credentials for a user - * @deprecated Use {@link UserModel#credentialManager()} instead. - * @return - */ - @Deprecated - UserCredentialManager userCredentialManager(); - - /** - * Keycloak specific local storage for users. No cache in front, this api talks directly to database configured for Keycloak - */ - @Deprecated - UserProvider userLocalStorage(); - - @Deprecated - RealmProvider realmLocalStorage(); - - /** - * Keycloak specific local storage for clients. No cache in front, this api talks directly to database configured for Keycloak - * - * @deprecated Access to the legacy store is no longer possible via this method. Adjust your code according to the Keycloak 19 Upgrading Guide. - */ - @Deprecated - ClientProvider clientLocalStorage(); - - /** - * Keycloak specific local storage for client scopes. No cache in front, this api talks directly to database configured for Keycloak - * - * @deprecated Access to the legacy store is no longer possible via this method. Adjust your code according to the Keycloak 19 Upgrading Guide. - */ - @Deprecated - ClientScopeProvider clientScopeLocalStorage(); - - /** - * Keycloak specific local storage for groups. No cache in front, this api talks directly to storage configured for Keycloak - * - * @deprecated Access to the legacy store is no longer possible via this method. Adjust your code according to the Keycloak 19 Upgrading Guide. - */ - @Deprecated - GroupProvider groupLocalStorage(); - - /** - * Keycloak specific local storage for roles. No cache in front, this api talks directly to storage configured for Keycloak - * - * @deprecated Access to the legacy store is no longer possible via this method. Adjust your code according to the Keycloak 19 Upgrading Guide. - */ - @Deprecated - RoleProvider roleLocalStorage(); - /** * Key manager * diff --git a/server-spi/src/main/java/org/keycloak/models/RealmModel.java b/server-spi/src/main/java/org/keycloak/models/RealmModel.java index 79c3d5ac4c..b2eb909301 100755 --- a/server-spi/src/main/java/org/keycloak/models/RealmModel.java +++ b/server-spi/src/main/java/org/keycloak/models/RealmModel.java @@ -24,10 +24,8 @@ import org.keycloak.provider.Provider; import org.keycloak.provider.ProviderEvent; import org.keycloak.storage.SearchableModelField; -import java.util.List; import java.util.Map; import java.util.Set; -import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -669,17 +667,6 @@ public interface RealmModel extends RoleContainerModel { */ Stream getTopLevelGroupsStream(Integer first, Integer max); - /** - * Searches for groups by provided name. Results that match the given filter are returned as a stream. - * @param search {@code String} Name of a group to be used as a filter. - * @param first {@code Integer} Index of the first desired group. Ignored if negative or {@code null}. - * @param max {@code Integer} Maximum number of returned groups. Ignored if negative or {@code null}. - * @return Stream of {@link GroupModel}. Never returns {@code null}. - * @deprecated Use {@link GroupProvider#searchForGroupByNameStream(RealmModel, String, Boolean, Integer, Integer)} instead. - */ - @Deprecated - Stream searchForGroupByNameStream(String search, Integer first, Integer max); - boolean removeGroup(GroupModel group); void moveGroup(GroupModel group, GroupModel toParent); diff --git a/server-spi/src/main/java/org/keycloak/models/RoleMapperModel.java b/server-spi/src/main/java/org/keycloak/models/RoleMapperModel.java index 6679652e7b..884e20dd13 100755 --- a/server-spi/src/main/java/org/keycloak/models/RoleMapperModel.java +++ b/server-spi/src/main/java/org/keycloak/models/RoleMapperModel.java @@ -18,8 +18,6 @@ package org.keycloak.models; import java.util.Objects; -import java.util.Set; -import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -85,12 +83,4 @@ public interface RoleMapperModel { * @param role Role to remove */ void deleteRoleMapping(RoleModel role); - - /** - * @deprecated This interface is no longer necessary, collection-based methods were removed from the parent interface - * and therefore the parent interface can be used directly - */ - @Deprecated - interface Streams extends RoleMapperModel { - } } diff --git a/server-spi/src/main/java/org/keycloak/models/UserModel.java b/server-spi/src/main/java/org/keycloak/models/UserModel.java index e664247fe2..475228b54d 100755 --- a/server-spi/src/main/java/org/keycloak/models/UserModel.java +++ b/server-spi/src/main/java/org/keycloak/models/UserModel.java @@ -272,12 +272,4 @@ public interface UserModel extends RoleMapperModel { VERIFY_PROFILE, UPDATE_EMAIL } - - /** - * @deprecated This interface is no longer necessary, collection-based methods were removed from the parent interface - * and therefore the parent interface can be used directly - */ - @Deprecated - interface Streams extends UserModel, RoleMapperModel { - } } diff --git a/server-spi/src/main/java/org/keycloak/models/UserProvider.java b/server-spi/src/main/java/org/keycloak/models/UserProvider.java index 04de1c1abf..00634e61ec 100755 --- a/server-spi/src/main/java/org/keycloak/models/UserProvider.java +++ b/server-spi/src/main/java/org/keycloak/models/UserProvider.java @@ -24,11 +24,6 @@ import org.keycloak.storage.user.UserLookupProvider; import org.keycloak.storage.user.UserQueryProvider; import org.keycloak.storage.user.UserRegistrationProvider; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -72,42 +67,6 @@ public interface UserProvider extends Provider, */ UserModel getServiceAccount(ClientModel client); - /** - * Obtains the users associated with the specified realm. - * - * @param realm a reference to the realm being used for the search. - * @param includeServiceAccounts {@code true} if service accounts should be included in the result; {@code false} otherwise. - * @return a non-null {@link Stream} of users associated withe the realm. - * - * @deprecated Use {@link UserQueryProvider#searchForUserStream(RealmModel, Map)} with - * {@link UserModel#INCLUDE_SERVICE_ACCOUNT} within params instead. - */ - @Deprecated - default Stream getUsersStream(RealmModel realm, boolean includeServiceAccounts) { - Map searchAttributes = new HashMap<>(1); - searchAttributes.put(UserModel.INCLUDE_SERVICE_ACCOUNT, Boolean.toString(includeServiceAccounts)); - return this.searchForUserStream(realm, searchAttributes); - } - - /** - * Obtains the users associated with the specified realm. - * - * @param realm a reference to the realm being used for the search. - * @param firstResult first result to return. Ignored if negative, zero, or {@code null}. - * @param maxResults maximum number of results to return. Ignored if negative or {@code null}. - * @param includeServiceAccounts {@code true} if service accounts should be included in the result; {@code false} otherwise. - * @return a non-null {@link Stream} of users associated withe the realm. - * - * @deprecated Use {@link UserQueryProvider#searchForUserStream(RealmModel, Map, Integer, Integer)} - * with {@link UserModel#INCLUDE_SERVICE_ACCOUNT} within params - */ - @Deprecated - default Stream getUsersStream(RealmModel realm, Integer firstResult, Integer maxResults, boolean includeServiceAccounts) { - Map searchAttributes = new HashMap<>(1); - searchAttributes.put(UserModel.INCLUDE_SERVICE_ACCOUNT, Boolean.toString(includeServiceAccounts)); - return this.searchForUserStream(realm, searchAttributes, firstResult, maxResults); - } - /** * Adds a new user into the storage. *

@@ -337,14 +296,4 @@ public interface UserProvider extends Provider, * @param component the component model */ void preRemove(RealmModel realm, ComponentModel component); - - void close(); - - /** - * @deprecated This interface is no longer necessary, collection-based methods were removed from the parent interface - * and therefore the parent interface can be used directly - */ - @Deprecated - interface Streams extends UserProvider, UserQueryProvider, UserLookupProvider { - } } diff --git a/server-spi/src/main/java/org/keycloak/storage/user/UserLookupProvider.java b/server-spi/src/main/java/org/keycloak/storage/user/UserLookupProvider.java index a8d5baa2d1..a486dda646 100644 --- a/server-spi/src/main/java/org/keycloak/storage/user/UserLookupProvider.java +++ b/server-spi/src/main/java/org/keycloak/storage/user/UserLookupProvider.java @@ -71,12 +71,4 @@ public interface UserLookupProvider { * @throws org.keycloak.models.ModelDuplicateException when there are more users with same email */ UserModel getUserByEmail(RealmModel realm, String email); - - /** - * @deprecated This interface is no longer necessary, collection-based methods were removed from the parent interface - * and therefore the parent interface can be used directly - */ - @Deprecated - interface Streams extends UserLookupProvider { - } } diff --git a/server-spi/src/main/java/org/keycloak/storage/user/UserQueryProvider.java b/server-spi/src/main/java/org/keycloak/storage/user/UserQueryProvider.java index c1f020541b..aaa3b8cdf2 100644 --- a/server-spi/src/main/java/org/keycloak/storage/user/UserQueryProvider.java +++ b/server-spi/src/main/java/org/keycloak/storage/user/UserQueryProvider.java @@ -23,12 +23,4 @@ package org.keycloak.storage.user; * It's a combination of {@link UserQueryMethodsProvider} and {@link UserCountMethodsProvider} */ public interface UserQueryProvider extends UserQueryMethodsProvider, UserCountMethodsProvider { - - /** - * @deprecated This interface is no longer necessary, collection-based methods were removed from the parent interface - * and therefore the parent interface can be used directly - */ - @Deprecated - interface Streams extends UserQueryProvider { - } } diff --git a/services/src/main/java/org/keycloak/services/DefaultKeycloakSession.java b/services/src/main/java/org/keycloak/services/DefaultKeycloakSession.java index 0aef15c8fe..582d8adf3e 100644 --- a/services/src/main/java/org/keycloak/services/DefaultKeycloakSession.java +++ b/services/src/main/java/org/keycloak/services/DefaultKeycloakSession.java @@ -36,7 +36,6 @@ import org.keycloak.models.RoleProvider; import org.keycloak.models.SingleUseObjectProvider; import org.keycloak.models.ThemeManager; import org.keycloak.models.TokenManager; -import org.keycloak.models.UserCredentialManager; import org.keycloak.models.UserLoginFailureProvider; import org.keycloak.models.UserProvider; import org.keycloak.models.UserSessionProvider; @@ -46,7 +45,6 @@ import org.keycloak.provider.ProviderFactory; import org.keycloak.provider.InvalidationHandler.InvalidableObjectType; import org.keycloak.provider.InvalidationHandler.ObjectType; import org.keycloak.services.clientpolicy.ClientPolicyManager; -import org.keycloak.models.LegacySessionSupportProvider; import org.keycloak.sessions.AuthenticationSessionProvider; import org.keycloak.storage.DatastoreProvider; import org.keycloak.vault.DefaultVaultTranscriber; @@ -78,8 +76,6 @@ public class DefaultKeycloakSession implements KeycloakSession { private final Map attributes = new HashMap<>(); private final Map> invalidationMap = new HashMap<>(); private DatastoreProvider datastoreProvider; - @Deprecated - private UserCredentialManager userCredentialStorageManager; private final KeycloakContext context; private KeyManager keyManager; private ThemeManager themeManager; @@ -107,16 +103,6 @@ public class DefaultKeycloakSession implements KeycloakSession { return this.datastoreProvider; } - @Override - @Deprecated - public UserProvider userCache() { - LegacySessionSupportProvider provider = this.getProvider(LegacySessionSupportProvider.class); - if (provider == null) { - throw new IllegalStateException("legacy support for userCache is not enabled"); - } - return provider.userCache(); - } - @Override public void invalidate(InvalidableObjectType type, Object... ids) { factory.invalidate(this, type, ids); @@ -172,91 +158,13 @@ public class DefaultKeycloakSession implements KeycloakSession { return factory; } - @Override - @Deprecated - public UserProvider userLocalStorage() { - throw new IllegalStateException("Access to the legacy store is no longer possible via this method. Adjust your code according to the Keycloak 19 Upgrading Guide."); - } - - @Override - @Deprecated - public RealmProvider realmLocalStorage() { - throw new IllegalStateException("Access to the legacy store is no longer possible via this method. Adjust your code according to the Keycloak 19 Upgrading Guide."); - } - - @Override - @Deprecated - public ClientProvider clientLocalStorage() { - throw new IllegalStateException("Access to the legacy store is no longer possible via this method. Adjust your code according to the Keycloak 19 Upgrading Guide."); - } - - @Override - @Deprecated - public ClientScopeProvider clientScopeLocalStorage() { - throw new IllegalStateException("Access to the legacy store is no longer possible via this method. Adjust your code according to the Keycloak 19 Upgrading Guide."); - } - - @Override - @Deprecated - public GroupProvider groupLocalStorage() { - throw new IllegalStateException("Access to the legacy store is no longer possible via this method. Adjust your code according to the Keycloak 19 Upgrading Guide."); - } - - @Override - @Deprecated - public ClientProvider clientStorageManager() { - throw new IllegalStateException("Access to the legacy store is no longer possible via this method. Adjust your code according to the Keycloak 19 Upgrading Guide."); - } - - @Override - @Deprecated - public ClientScopeProvider clientScopeStorageManager() { - throw new IllegalStateException("Access to the legacy store is no longer possible via this method. Adjust your code according to the Keycloak 19 Upgrading Guide."); - } - - @Override - @Deprecated - public RoleProvider roleLocalStorage() { - throw new IllegalStateException("Access to the legacy store is no longer possible via this method. Adjust your code according to the Keycloak 19 Upgrading Guide."); - } - - @Override - @Deprecated - public RoleProvider roleStorageManager() { - throw new IllegalStateException("Access to the legacy store is no longer possible via this method. Adjust your code according to the Keycloak 19 Upgrading Guide."); - } - - @Override - @Deprecated - public GroupProvider groupStorageManager() { - throw new IllegalStateException("Access to the legacy store is no longer possible via this method. Adjust your code according to the Keycloak 19 Upgrading Guide."); - } - - @Override - @Deprecated - public UserProvider userStorageManager() { - throw new IllegalStateException("Access to the legacy store is no longer possible via this method. Adjust your code according to the Keycloak 19 Upgrading Guide."); - } - @Override public UserProvider users() { return getDatastoreProvider().users(); } - @Override - @Deprecated - public UserCredentialManager userCredentialManager() { - if (userCredentialStorageManager == null) { - LegacySessionSupportProvider provider = this.getProvider(LegacySessionSupportProvider.class); - if (provider == null) { - throw new IllegalStateException("legacy support for a UserCredentialManager is not enabled"); - } - userCredentialStorageManager = provider.userCredentialManager(); - } - return userCredentialStorageManager; - } - @SuppressWarnings("unchecked") + @Override public T getProvider(Class clazz) { Integer hash = clazz.hashCode(); T provider = (T) providers.get(hash); @@ -274,6 +182,7 @@ public class DefaultKeycloakSession implements KeycloakSession { } @SuppressWarnings("unchecked") + @Override public T getProvider(Class clazz, String id) { Integer hash = clazz.hashCode() + id.hashCode(); T provider = (T) providers.get(hash); diff --git a/services/src/main/java/org/keycloak/services/util/ScopeMappedUtil.java b/services/src/main/java/org/keycloak/services/util/ScopeMappedUtil.java index fbcc3ebd02..1ae91e6ccd 100644 --- a/services/src/main/java/org/keycloak/services/util/ScopeMappedUtil.java +++ b/services/src/main/java/org/keycloak/services/util/ScopeMappedUtil.java @@ -18,35 +18,27 @@ package org.keycloak.services.util; import org.keycloak.models.ClientModel; -import org.keycloak.models.RoleModel; import org.keycloak.models.ScopeContainerModel; import org.keycloak.models.utils.KeycloakModelUtils; import org.keycloak.models.utils.ModelToRepresentation; import org.keycloak.representations.idm.ClientMappingsRepresentation; import org.keycloak.representations.idm.RoleRepresentation; -import java.util.LinkedList; import java.util.List; -import java.util.Set; +import java.util.stream.Collectors; public class ScopeMappedUtil { public static ClientMappingsRepresentation toClientMappingsRepresentation(ClientModel client, ScopeContainerModel scopeContainer) { - Set roleMappings = KeycloakModelUtils.getClientScopeMappings(client, scopeContainer); + List roles = KeycloakModelUtils.getClientScopeMappingsStream(client, scopeContainer) + .map(role -> ModelToRepresentation.toBriefRepresentation(role)) + .collect(Collectors.toList()); - if (!roleMappings.isEmpty()) { + if (roles.isEmpty()) return null; - ClientMappingsRepresentation mappings = new ClientMappingsRepresentation(); - mappings.setId(client.getId()); - mappings.setClient(client.getClientId()); - List roles = new LinkedList<>(); - mappings.setMappings(roles); - for (RoleModel role : roleMappings) { - roles.add(ModelToRepresentation.toBriefRepresentation(role)); - } - - return mappings; - } else { - return null; - } + ClientMappingsRepresentation mappings = new ClientMappingsRepresentation(); + mappings.setId(client.getId()); + mappings.setClient(client.getClientId()); + mappings.setMappings(roles); + return mappings; } } diff --git a/services/src/main/resources/META-INF/services/org.keycloak.provider.Spi b/services/src/main/resources/META-INF/services/org.keycloak.provider.Spi index 1b5b991a72..6238b9bc2a 100755 --- a/services/src/main/resources/META-INF/services/org.keycloak.provider.Spi +++ b/services/src/main/resources/META-INF/services/org.keycloak.provider.Spi @@ -29,5 +29,4 @@ org.keycloak.protocol.oidc.grants.ciba.channel.AuthenticationChannelSpi org.keycloak.protocol.oidc.grants.ciba.resolvers.CIBALoginUserResolverSpi org.keycloak.protocol.oidc.rar.AuthorizationRequestParserSpi org.keycloak.services.resources.admin.ext.AdminRealmResourceSpi -org.keycloak.services.legacysessionsupport.LegacySessionSupportSpi org.keycloak.theme.freemarker.FreeMarkerSPI \ No newline at end of file diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/UserManagedPermissionServiceTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/UserManagedPermissionServiceTest.java index 5b6e3125bc..4fb14dcada 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/UserManagedPermissionServiceTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/authz/UserManagedPermissionServiceTest.java @@ -1066,7 +1066,7 @@ public class UserManagedPermissionServiceTest extends AbstractResourceServerTest Resource resource = policy.getResources().iterator().next(); assertEquals("Resource A", resource.getName()); - realm.removeGroup(realm.searchForGroupByNameStream("group_remove", -1, -1).findAny().get()); + realm.removeGroup(session.groups().searchForGroupByNameStream(realm, "group_remove", false, null, null).findAny().get()); filters = new HashMap<>(); diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPSyncTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPSyncTest.java index b4a220e1f2..bc17b0ab6a 100755 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPSyncTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPSyncTest.java @@ -512,7 +512,7 @@ public class LDAPSyncTest extends AbstractLDAPTest { RealmModel appRealm = ctx.getRealm(); // Remove all users from model - UserStoragePrivateUtil.userLocalStorage(session).getUsersStream(ctx.getRealm(), true) + UserStoragePrivateUtil.userLocalStorage(session).searchForUserStream(ctx.getRealm(), Map.of()) .peek(user -> System.out.println("trying to delete user: " + user.getUsername())) .collect(Collectors.toList()) .forEach(user -> { diff --git a/testsuite/integration-arquillian/tests/other/webauthn/src/main/java/org/keycloak/testsuite/webauthn/utils/WebAuthnDataWrapper.java b/testsuite/integration-arquillian/tests/other/webauthn/src/main/java/org/keycloak/testsuite/webauthn/utils/WebAuthnDataWrapper.java index d34610af5b..9c9b3b6704 100644 --- a/testsuite/integration-arquillian/tests/other/webauthn/src/main/java/org/keycloak/testsuite/webauthn/utils/WebAuthnDataWrapper.java +++ b/testsuite/integration-arquillian/tests/other/webauthn/src/main/java/org/keycloak/testsuite/webauthn/utils/WebAuthnDataWrapper.java @@ -23,8 +23,8 @@ import com.webauthn4j.data.attestation.authenticator.COSEKey; import org.keycloak.common.util.Base64Url; import org.keycloak.credential.CredentialModel; import org.keycloak.models.KeycloakSession; -import org.keycloak.models.UserCredentialManager; import org.keycloak.models.UserModel; +import org.keycloak.models.SubjectCredentialManager; import org.keycloak.models.credential.dto.WebAuthnCredentialData; import java.io.Serializable; @@ -55,11 +55,11 @@ public class WebAuthnDataWrapper implements Serializable { final UserModel user = session.users().getUserByUsername(session.getContext().getRealm(), username); if (user == null) return; - final UserCredentialManager userCredentialManager = session.userCredentialManager(); + SubjectCredentialManager userCredentialManager = user.credentialManager(); if (userCredentialManager == null) return; final CredentialModel credential = userCredentialManager - .getStoredCredentialsByTypeStream(session.getContext().getRealm(), user, credentialType) + .getStoredCredentialsByTypeStream(credentialType) .findFirst() .orElse(null);