KEYCLOAK-2807 Fix server info providers page

This commit is contained in:
Stian Thorgersen 2016-04-12 15:06:48 +02:00
parent 7109ad247f
commit 1c2eafeb80
5 changed files with 78 additions and 65 deletions

View file

@ -20,8 +20,10 @@ package org.keycloak.models;
import org.keycloak.provider.Provider; import org.keycloak.provider.Provider;
import org.keycloak.provider.ProviderEventManager; import org.keycloak.provider.ProviderEventManager;
import org.keycloak.provider.ProviderFactory; import org.keycloak.provider.ProviderFactory;
import org.keycloak.provider.Spi;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
@ -30,6 +32,8 @@ import java.util.List;
public interface KeycloakSessionFactory extends ProviderEventManager { public interface KeycloakSessionFactory extends ProviderEventManager {
KeycloakSession create(); KeycloakSession create();
Set<Spi> getSpis();
<T extends Provider> ProviderFactory<T> getProviderFactory(Class<T> clazz); <T extends Provider> ProviderFactory<T> getProviderFactory(Class<T> clazz);
<T extends Provider> ProviderFactory<T> getProviderFactory(Class<T> clazz, String id); <T extends Provider> ProviderFactory<T> getProviderFactory(Class<T> clazz, String id);

View file

@ -40,6 +40,7 @@ public class DefaultKeycloakSessionFactory implements KeycloakSessionFactory {
private static final ServicesLogger logger = ServicesLogger.ROOT_LOGGER; private static final ServicesLogger logger = ServicesLogger.ROOT_LOGGER;
private Set<Spi> spis = new HashSet<>();
private Map<Class<? extends Provider>, String> provider = new HashMap<Class<? extends Provider>, String>(); private Map<Class<? extends Provider>, String> provider = new HashMap<Class<? extends Provider>, String>();
private Map<Class<? extends Provider>, Map<String, ProviderFactory>> factoriesMap = new HashMap<Class<? extends Provider>, Map<String, ProviderFactory>>(); private Map<Class<? extends Provider>, Map<String, ProviderFactory>> factoriesMap = new HashMap<Class<? extends Provider>, Map<String, ProviderFactory>>();
protected CopyOnWriteArrayList<ProviderEventListener> listeners = new CopyOnWriteArrayList<ProviderEventListener>(); protected CopyOnWriteArrayList<ProviderEventListener> listeners = new CopyOnWriteArrayList<ProviderEventListener>();
@ -80,6 +81,8 @@ public class DefaultKeycloakSessionFactory implements KeycloakSessionFactory {
protected void loadSPIs(ProviderManager pm, ServiceLoader<Spi> load) { protected void loadSPIs(ProviderManager pm, ServiceLoader<Spi> load) {
for (Spi spi : load) { for (Spi spi : load) {
spis.add(spi);
Map<String, ProviderFactory> factories = new HashMap<String, ProviderFactory>(); Map<String, ProviderFactory> factories = new HashMap<String, ProviderFactory>();
factoriesMap.put(spi.getProviderClass(), factories); factoriesMap.put(spi.getProviderClass(), factories);
@ -138,6 +141,11 @@ public class DefaultKeycloakSessionFactory implements KeycloakSessionFactory {
return provider.get(clazz); return provider.get(clazz);
} }
@Override
public Set<Spi> getSpis() {
return spis;
}
@Override @Override
public <T extends Provider> ProviderFactory<T> getProviderFactory(Class<T> clazz) { public <T extends Provider> ProviderFactory<T> getProviderFactory(Class<T> clazz) {
return getProviderFactory(clazz, provider.get(clazz)); return getProviderFactory(clazz, provider.get(clazz));

View file

@ -95,10 +95,7 @@ public class ServerInfoAdminResource {
private void setProviders(ServerInfoRepresentation info) { private void setProviders(ServerInfoRepresentation info) {
LinkedHashMap<String, SpiInfoRepresentation> spiReps = new LinkedHashMap<>(); LinkedHashMap<String, SpiInfoRepresentation> spiReps = new LinkedHashMap<>();
List<Spi> spis = new LinkedList<>(); List<Spi> spis = new LinkedList<>(session.getKeycloakSessionFactory().getSpis());
for (Spi spi : ServiceLoader.load(Spi.class)) {
spis.add(spi);
}
Collections.sort(spis, new Comparator<Spi>() { Collections.sort(spis, new Comparator<Spi>() {
@Override @Override
public int compare(Spi s1, Spi s2) { public int compare(Spi s1, Spi s2) {

View file

@ -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 <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
*/
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<RealmRepresentation> testRealms) {
}
}

View file

@ -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 <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
*/
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());
}
}