From 1c2eafeb80e60754de0d1f86c6fed3ecd6750e7d Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Tue, 12 Apr 2016 15:06:48 +0200 Subject: [PATCH] KEYCLOAK-2807 Fix server info providers page --- .../models/KeycloakSessionFactory.java | 4 ++ .../DefaultKeycloakSessionFactory.java | 8 +++ .../admin/info/ServerInfoAdminResource.java | 5 +- .../testsuite/admin/ServerInfoTest.java | 65 +++++++++++++++++++ .../testsuite/admin/ServerInfoTest.java | 61 ----------------- 5 files changed, 78 insertions(+), 65 deletions(-) create mode 100644 testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/ServerInfoTest.java delete mode 100644 testsuite/integration/src/test/java/org/keycloak/testsuite/admin/ServerInfoTest.java diff --git a/server-spi/src/main/java/org/keycloak/models/KeycloakSessionFactory.java b/server-spi/src/main/java/org/keycloak/models/KeycloakSessionFactory.java index 3aa15d810e..0028ae7b8f 100755 --- a/server-spi/src/main/java/org/keycloak/models/KeycloakSessionFactory.java +++ b/server-spi/src/main/java/org/keycloak/models/KeycloakSessionFactory.java @@ -20,8 +20,10 @@ package org.keycloak.models; import org.keycloak.provider.Provider; import org.keycloak.provider.ProviderEventManager; import org.keycloak.provider.ProviderFactory; +import org.keycloak.provider.Spi; import java.util.List; +import java.util.Set; /** * @author Bill Burke @@ -30,6 +32,8 @@ import java.util.List; public interface KeycloakSessionFactory extends ProviderEventManager { KeycloakSession create(); + Set getSpis(); + ProviderFactory getProviderFactory(Class clazz); ProviderFactory getProviderFactory(Class clazz, String id); diff --git a/services/src/main/java/org/keycloak/services/DefaultKeycloakSessionFactory.java b/services/src/main/java/org/keycloak/services/DefaultKeycloakSessionFactory.java index 3ca473b33d..90b495cc71 100755 --- a/services/src/main/java/org/keycloak/services/DefaultKeycloakSessionFactory.java +++ b/services/src/main/java/org/keycloak/services/DefaultKeycloakSessionFactory.java @@ -40,6 +40,7 @@ public class DefaultKeycloakSessionFactory implements KeycloakSessionFactory { private static final ServicesLogger logger = ServicesLogger.ROOT_LOGGER; + private Set spis = new HashSet<>(); private Map, String> provider = new HashMap, String>(); private Map, Map> factoriesMap = new HashMap, Map>(); protected CopyOnWriteArrayList listeners = new CopyOnWriteArrayList(); @@ -80,6 +81,8 @@ public class DefaultKeycloakSessionFactory implements KeycloakSessionFactory { protected void loadSPIs(ProviderManager pm, ServiceLoader load) { for (Spi spi : load) { + spis.add(spi); + Map factories = new HashMap(); factoriesMap.put(spi.getProviderClass(), factories); @@ -138,6 +141,11 @@ public class DefaultKeycloakSessionFactory implements KeycloakSessionFactory { return provider.get(clazz); } + @Override + public Set getSpis() { + return spis; + } + @Override public ProviderFactory getProviderFactory(Class clazz) { return getProviderFactory(clazz, provider.get(clazz)); diff --git a/services/src/main/java/org/keycloak/services/resources/admin/info/ServerInfoAdminResource.java b/services/src/main/java/org/keycloak/services/resources/admin/info/ServerInfoAdminResource.java index 4454ccbfe6..3ea8fd13cf 100755 --- a/services/src/main/java/org/keycloak/services/resources/admin/info/ServerInfoAdminResource.java +++ b/services/src/main/java/org/keycloak/services/resources/admin/info/ServerInfoAdminResource.java @@ -95,10 +95,7 @@ public class ServerInfoAdminResource { private void setProviders(ServerInfoRepresentation info) { LinkedHashMap spiReps = new LinkedHashMap<>(); - List spis = new LinkedList<>(); - for (Spi spi : ServiceLoader.load(Spi.class)) { - spis.add(spi); - } + List spis = new LinkedList<>(session.getKeycloakSessionFactory().getSpis()); Collections.sort(spis, new Comparator() { @Override public int compare(Spi s1, Spi s2) { diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/ServerInfoTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/ServerInfoTest.java new file mode 100644 index 0000000000..5e1a041b44 --- /dev/null +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/ServerInfoTest.java @@ -0,0 +1,65 @@ +/* + * Copyright 2016 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. + */ + +package org.keycloak.testsuite.admin; + +import org.junit.Test; +import org.keycloak.common.Version; +import org.keycloak.representations.idm.RealmRepresentation; +import org.keycloak.representations.info.ServerInfoRepresentation; +import org.keycloak.testsuite.AbstractKeycloakTest; + +import java.util.List; + +import static org.junit.Assert.*; + +/** + * @author Stian Thorgersen + */ +public class ServerInfoTest extends AbstractKeycloakTest { + + @Test + public void testServerInfo() { + ServerInfoRepresentation info = adminClient.serverInfo().getInfo(); + assertNotNull(info); + + assertNotNull(info.getProviders()); + assertNotNull(info.getProviders().get("realm")); + assertNotNull(info.getProviders().get("user")); + assertNotNull(info.getProviders().get("authenticator")); + + assertNotNull(info.getThemes()); + assertNotNull(info.getThemes().get("account")); + assertNotNull(info.getThemes().get("admin")); + assertNotNull(info.getThemes().get("email")); + assertNotNull(info.getThemes().get("login")); + assertNotNull(info.getThemes().get("welcome")); + + assertNotNull(info.getEnums()); + + assertNotNull(info.getMemoryInfo()); + assertNotNull(info.getSystemInfo()); + + assertEquals(Version.VERSION, info.getSystemInfo().getVersion()); + assertNotNull(info.getSystemInfo().getServerTime()); + assertNotNull(info.getSystemInfo().getUptime()); + } + + @Override + public void addTestRealms(List testRealms) { + } +} diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/admin/ServerInfoTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/admin/ServerInfoTest.java deleted file mode 100644 index a217a0480d..0000000000 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/admin/ServerInfoTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2016 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. - */ - -package org.keycloak.testsuite.admin; - -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.keycloak.common.Version; -import org.keycloak.representations.info.ServerInfoRepresentation; -import org.keycloak.testsuite.OAuthClient; -import org.keycloak.testsuite.rule.WebResource; -import org.keycloak.testsuite.rule.WebRule; -import org.openqa.selenium.WebDriver; - -/** - * @author Stian Thorgersen - */ -public class ServerInfoTest extends AbstractClientTest { - - @Rule - public WebRule webRule = new WebRule(this); - - @WebResource - protected WebDriver driver; - - @WebResource - protected OAuthClient oauth; - - @Test - public void testServerInfo() { - ServerInfoRepresentation info = keycloak.serverInfo().getInfo(); - - Assert.assertNotNull(info); - Assert.assertNotNull(info.getProviders()); - Assert.assertNotNull(info.getThemes()); - Assert.assertNotNull(info.getEnums()); - - Assert.assertNotNull(info.getMemoryInfo()); - Assert.assertNotNull(info.getSystemInfo()); - - Assert.assertEquals(Version.VERSION, info.getSystemInfo().getVersion()); - Assert.assertNotNull(info.getSystemInfo().getServerTime()); - Assert.assertNotNull(info.getSystemInfo().getUptime()); - } - -}