diff --git a/model/legacy-private/src/main/java/org/keycloak/storage/RoleStorageManager.java b/model/legacy-private/src/main/java/org/keycloak/storage/RoleStorageManager.java index f3dddf329b..c53299ceb9 100644 --- a/model/legacy-private/src/main/java/org/keycloak/storage/RoleStorageManager.java +++ b/model/legacy-private/src/main/java/org/keycloak/storage/RoleStorageManager.java @@ -23,6 +23,7 @@ import org.keycloak.common.util.reflections.Types; import org.keycloak.component.ComponentModel; import org.keycloak.models.ClientModel; import org.keycloak.models.KeycloakSession; +import org.keycloak.models.LegacyRealmModel; import org.keycloak.models.ModelException; import org.keycloak.models.RealmModel; import org.keycloak.models.RoleModel; @@ -71,9 +72,8 @@ public class RoleStorageManager implements RoleProvider { return getStorageProviderInstance(session, storageModel, factory); } - public static Stream getStorageProviders(RealmModel realm, KeycloakSession session, Class type) { - return realm.getRoleStorageProvidersStream() + return ((LegacyRealmModel) realm).getRoleStorageProvidersStream() .filter(model -> { RoleStorageProviderFactory factory = getRoleStorageProviderFactory(model, session); if (factory == null) { @@ -162,9 +162,9 @@ public class RoleStorageManager implements RoleProvider { /** * Obtaining roles from an external role storage is time-bounded. In case the external role storage * isn't available at least roles from a local storage are returned. For this purpose - * the {@link org.keycloak.services.DefaultKeycloakSessionFactory#getRoleStorageProviderTimeout()} property is used. + * the org.keycloak.services.DefaultKeycloakSessionFactory#getRoleStorageProviderTimeout() property is used. * Default value is 3000 milliseconds and it's configurable. - * See {@link org.keycloak.services.DefaultKeycloakSessionFactory} for details. + * See org.keycloak.services.DefaultKeycloakSessionFactory for details. */ @Override public Stream searchForRolesStream(RealmModel realm, String search, Integer first, Integer max) { @@ -229,9 +229,9 @@ public class RoleStorageManager implements RoleProvider { /** * Obtaining roles from an external role storage is time-bounded. In case the external role storage * isn't available at least roles from a local storage are returned. For this purpose - * the {@link org.keycloak.services.DefaultKeycloakSessionFactory#getRoleStorageProviderTimeout()} property is used. + * the org.keycloak.services.DefaultKeycloakSessionFactory#getRoleStorageProviderTimeout()} property is used. * Default value is 3000 milliseconds and it's configurable. - * See {@link org.keycloak.services.DefaultKeycloakSessionFactory} for details. + * See org.keycloak.services.DefaultKeycloakSessionFactory for details. */ @Override public Stream searchForClientRolesStream(ClientModel client, String search, Integer first, Integer max) { diff --git a/model/legacy/src/main/java/org/keycloak/models/LegacyRealmModel.java b/model/legacy/src/main/java/org/keycloak/models/LegacyRealmModel.java index abc92f50c6..1e7ed9e390 100644 --- a/model/legacy/src/main/java/org/keycloak/models/LegacyRealmModel.java +++ b/model/legacy/src/main/java/org/keycloak/models/LegacyRealmModel.java @@ -20,6 +20,8 @@ package org.keycloak.models; import org.keycloak.models.RealmModel; import org.keycloak.storage.client.ClientStorageProvider; import org.keycloak.storage.client.ClientStorageProviderModel; +import org.keycloak.storage.role.RoleStorageProvider; +import org.keycloak.storage.role.RoleStorageProviderModel; import java.util.List; import java.util.stream.Collectors; @@ -47,4 +49,24 @@ public interface LegacyRealmModel extends RealmModel { .map(ClientStorageProviderModel::new) .sorted(ClientStorageProviderModel.comparator); } + + /** + * @deprecated Use {@link #getRoleStorageProvidersStream() getRoleStorageProvidersStream} instead. + */ + @Deprecated + default List getRoleStorageProviders() { + return getRoleStorageProvidersStream().collect(Collectors.toList()); + } + + /** + * Returns sorted {@link RoleStorageProviderModel RoleStorageProviderModel} as a stream. + * It should be used with forEachOrdered if the ordering is required. + * @return Sorted stream of {@link RoleStorageProviderModel}. Never returns {@code null}. + */ + default Stream getRoleStorageProvidersStream() { + return getComponentsStream(getId(), RoleStorageProvider.class.getName()) + .map(RoleStorageProviderModel::new) + .sorted(RoleStorageProviderModel.comparator); + } + } diff --git a/server-spi/src/main/java/org/keycloak/storage/role/RoleStorageProviderModel.java b/model/legacy/src/main/java/org/keycloak/storage/role/RoleStorageProviderModel.java similarity index 100% rename from server-spi/src/main/java/org/keycloak/storage/role/RoleStorageProviderModel.java rename to model/legacy/src/main/java/org/keycloak/storage/role/RoleStorageProviderModel.java 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 528ca05beb..41fb744e24 100755 --- a/server-spi/src/main/java/org/keycloak/models/RealmModel.java +++ b/server-spi/src/main/java/org/keycloak/models/RealmModel.java @@ -23,8 +23,6 @@ import org.keycloak.component.ComponentModel; import org.keycloak.provider.Provider; import org.keycloak.provider.ProviderEvent; import org.keycloak.storage.SearchableModelField; -import org.keycloak.storage.role.RoleStorageProvider; -import org.keycloak.storage.role.RoleStorageProviderModel; import java.util.List; import java.util.Map; @@ -658,25 +656,6 @@ public interface RealmModel extends RoleContainerModel { ComponentModel getComponent(String id); - /** - * @deprecated Use {@link #getRoleStorageProvidersStream() getRoleStorageProvidersStream} instead. - */ - @Deprecated - default List getRoleStorageProviders() { - return getRoleStorageProvidersStream().collect(Collectors.toList()); - } - - /** - * Returns sorted {@link RoleStorageProviderModel RoleStorageProviderModel} as a stream. - * It should be used with forEachOrdered if the ordering is required. - * @return Sorted stream of {@link RoleStorageProviderModel}. Never returns {@code null}. - */ - default Stream getRoleStorageProvidersStream() { - return getComponentsStream(getId(), RoleStorageProvider.class.getName()) - .map(RoleStorageProviderModel::new) - .sorted(RoleStorageProviderModel.comparator); - } - /** * Returns stream of ComponentModels that represent StorageProviders for class storageProviderClass in this realm. * @param storageProviderClass {@code Class} diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/ClientStorageTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/ClientStorageTest.java index 38c8d01784..fe1d59f3d7 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/ClientStorageTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/storage/ClientStorageTest.java @@ -31,6 +31,7 @@ import org.keycloak.events.Details; import org.keycloak.models.ClientModel; import org.keycloak.models.Constants; import org.keycloak.models.KeycloakSession; +import org.keycloak.models.LegacyRealmModel; import org.keycloak.models.RealmModel; import org.keycloak.models.cache.infinispan.ClientAdapter; import org.keycloak.representations.AccessToken; @@ -341,7 +342,7 @@ public class ClientStorageTest extends AbstractTestRealmKeycloakTest { testingClient.server().run(session -> { RealmModel realm = session.realms().getRealmByName("test"); - ClientStorageProviderModel model = realm.getClientStorageProvidersStream().findFirst().get(); + ClientStorageProviderModel model = ((LegacyRealmModel) realm).getClientStorageProvidersStream().findFirst().get(); Calendar eviction = Calendar.getInstance(); eviction.add(Calendar.HOUR, 1); model.setCachePolicy(CacheableStorageProviderModel.CachePolicy.EVICT_DAILY); @@ -366,7 +367,7 @@ public class ClientStorageTest extends AbstractTestRealmKeycloakTest { testingClient.server().run(session -> { RealmModel realm = session.realms().getRealmByName("test"); - ClientStorageProviderModel model = realm.getClientStorageProvidersStream().findAny().get(); + ClientStorageProviderModel model = ((LegacyRealmModel) realm).getClientStorageProvidersStream().findAny().get(); Calendar eviction = Calendar.getInstance(); eviction.add(Calendar.HOUR, 4 * 24); model.setCachePolicy(CacheableStorageProviderModel.CachePolicy.EVICT_WEEKLY); @@ -394,7 +395,7 @@ public class ClientStorageTest extends AbstractTestRealmKeycloakTest { testingClient.server().run(session -> { RealmModel realm = session.realms().getRealmByName("test"); - ClientStorageProviderModel model = realm.getClientStorageProvidersStream().findFirst().get(); + ClientStorageProviderModel model = ((LegacyRealmModel) realm).getClientStorageProvidersStream().findFirst().get(); model.setCachePolicy(CacheableStorageProviderModel.CachePolicy.MAX_LIFESPAN); model.setMaxLifespan(1 * 60 * 60 * 1000); realm.updateComponent(model); @@ -446,7 +447,7 @@ public class ClientStorageTest extends AbstractTestRealmKeycloakTest { testingClient.server().run(session -> { RealmModel realm = session.realms().getRealmByName("test"); - ClientStorageProviderModel model = realm.getClientStorageProvidersStream().findFirst().get(); + ClientStorageProviderModel model = ((LegacyRealmModel) realm).getClientStorageProvidersStream().findFirst().get(); model.setCachePolicy(CacheableStorageProviderModel.CachePolicy.NO_CACHE); realm.updateComponent(model); }); @@ -466,7 +467,7 @@ public class ClientStorageTest extends AbstractTestRealmKeycloakTest { private void setDefaultCachePolicy() { testingClient.server().run(session -> { RealmModel realm = session.realms().getRealmByName("test"); - ClientStorageProviderModel model = realm.getClientStorageProvidersStream().findFirst().get(); + ClientStorageProviderModel model = ((LegacyRealmModel) realm).getClientStorageProvidersStream().findFirst().get(); model.setCachePolicy(CacheableStorageProviderModel.CachePolicy.DEFAULT); realm.updateComponent(model); });