From 29a501552e0a2b1010b48de8fc066aec83af8db5 Mon Sep 17 00:00:00 2001 From: Alexander Schwartz Date: Tue, 5 Jul 2022 12:30:32 +0200 Subject: [PATCH] Disable the JpaUserFederatedStorageProvider when map storage is enabled Closes #12895 --- .../jpa/JpaUserFederatedStorageProviderFactory.java | 10 +++++++++- .../util/MultipleStepsExportProvider.java | 6 +++++- .../org/keycloak/exportimport/util/ExportUtils.java | 11 +++++++---- testsuite/integration-arquillian/tests/base/pom.xml | 1 + 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/model/jpa/src/main/java/org/keycloak/storage/jpa/JpaUserFederatedStorageProviderFactory.java b/model/jpa/src/main/java/org/keycloak/storage/jpa/JpaUserFederatedStorageProviderFactory.java index 0a3218c57d..2780393c91 100644 --- a/model/jpa/src/main/java/org/keycloak/storage/jpa/JpaUserFederatedStorageProviderFactory.java +++ b/model/jpa/src/main/java/org/keycloak/storage/jpa/JpaUserFederatedStorageProviderFactory.java @@ -17,9 +17,11 @@ package org.keycloak.storage.jpa; import org.keycloak.Config; +import org.keycloak.common.Profile; import org.keycloak.connections.jpa.JpaConnectionProvider; import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSessionFactory; +import org.keycloak.provider.EnvironmentDependentProviderFactory; import org.keycloak.storage.federated.UserFederatedStorageProvider; import org.keycloak.storage.federated.UserFederatedStorageProviderFactory; @@ -29,7 +31,7 @@ import javax.persistence.EntityManager; * @author Bill Burke * @version $Revision: 1 $ */ -public class JpaUserFederatedStorageProviderFactory implements UserFederatedStorageProviderFactory { +public class JpaUserFederatedStorageProviderFactory implements UserFederatedStorageProviderFactory, EnvironmentDependentProviderFactory { @Override public UserFederatedStorageProvider create(KeycloakSession session) { EntityManager em = session.getProvider(JpaConnectionProvider.class).getEntityManager(); @@ -55,4 +57,10 @@ public class JpaUserFederatedStorageProviderFactory implements UserFederatedStor public String getId() { return "jpa"; } + + @Override + public boolean isSupported() { + return !Profile.isFeatureEnabled(Profile.Feature.MAP_STORAGE); + } + } diff --git a/model/legacy-services/src/main/java/org/keycloak/exportimport/util/MultipleStepsExportProvider.java b/model/legacy-services/src/main/java/org/keycloak/exportimport/util/MultipleStepsExportProvider.java index 88e7529153..4d25ba1cde 100755 --- a/model/legacy-services/src/main/java/org/keycloak/exportimport/util/MultipleStepsExportProvider.java +++ b/model/legacy-services/src/main/java/org/keycloak/exportimport/util/MultipleStepsExportProvider.java @@ -84,7 +84,11 @@ public abstract class MultipleStepsExportProvider implements ExportProvider { // Count total number of users if (!exportUsersIntoRealmFile) { usersHolder.totalCount = session.users().getUsersCount(realm, true); - federatedUsersHolder.totalCount = UserStorageUtil.userFederatedStorage(session).getStoredUsersCount(realm); + if (UserStorageUtil.userFederatedStorage(session) != null) { + federatedUsersHolder.totalCount = UserStorageUtil.userFederatedStorage(session).getStoredUsersCount(realm); + } else { + federatedUsersHolder.totalCount = 0; + } } } diff --git a/services/src/main/java/org/keycloak/exportimport/util/ExportUtils.java b/services/src/main/java/org/keycloak/exportimport/util/ExportUtils.java index 98a213a099..01aa479b4c 100755 --- a/services/src/main/java/org/keycloak/exportimport/util/ExportUtils.java +++ b/services/src/main/java/org/keycloak/exportimport/util/ExportUtils.java @@ -235,10 +235,13 @@ public class ExportUtils { rep.setUsers(users); } - List federatedUsers = userFederatedStorage(session).getStoredUsersStream(realm, 0, -1) - .map(user -> exportFederatedUser(session, realm, user, options)).collect(Collectors.toList()); - if (federatedUsers.size() > 0) { - rep.setFederatedUsers(federatedUsers); + UserFederatedStorageProvider userFederatedStorageProvider = userFederatedStorage(session); + if (userFederatedStorageProvider != null) { + List federatedUsers = userFederatedStorage(session).getStoredUsersStream(realm, 0, -1) + .map(user -> exportFederatedUser(session, realm, user, options)).collect(Collectors.toList()); + if (federatedUsers.size() > 0) { + rep.setFederatedUsers(federatedUsers); + } } } else if (options.isClientsIncluded() && options.isOnlyServiceAccountsIncluded()) { diff --git a/testsuite/integration-arquillian/tests/base/pom.xml b/testsuite/integration-arquillian/tests/base/pom.xml index ea64492371..1486247955 100644 --- a/testsuite/integration-arquillian/tests/base/pom.xml +++ b/testsuite/integration-arquillian/tests/base/pom.xml @@ -855,6 +855,7 @@ false false +