Search in sources :

Example 1 with ProviderRepresentation

use of org.keycloak.representations.info.ProviderRepresentation in project keycloak by keycloak.

the class ServerInfoAdminResource method setProviders.

private void setProviders(ServerInfoRepresentation info) {
    info.setComponentTypes(new HashMap<>());
    LinkedHashMap<String, SpiInfoRepresentation> spiReps = new LinkedHashMap<>();
    List<Spi> spis = new LinkedList<>(session.getKeycloakSessionFactory().getSpis());
    Collections.sort(spis, new Comparator<Spi>() {

        @Override
        public int compare(Spi s1, Spi s2) {
            return s1.getName().compareTo(s2.getName());
        }
    });
    for (Spi spi : spis) {
        SpiInfoRepresentation spiRep = new SpiInfoRepresentation();
        spiRep.setInternal(spi.isInternal());
        List<String> providerIds = new LinkedList<>(session.listProviderIds(spi.getProviderClass()));
        Collections.sort(providerIds);
        Map<String, ProviderRepresentation> providers = new HashMap<>();
        if (providerIds != null) {
            for (String name : providerIds) {
                ProviderRepresentation provider = new ProviderRepresentation();
                ProviderFactory<?> pi = session.getKeycloakSessionFactory().getProviderFactory(spi.getProviderClass(), name);
                provider.setOrder(pi.order());
                if (ServerInfoAwareProviderFactory.class.isAssignableFrom(pi.getClass())) {
                    provider.setOperationalInfo(((ServerInfoAwareProviderFactory) pi).getOperationalInfo());
                }
                if (pi instanceof ConfiguredProvider) {
                    ComponentTypeRepresentation rep = new ComponentTypeRepresentation();
                    rep.setId(pi.getId());
                    ConfiguredProvider configured = (ConfiguredProvider) pi;
                    rep.setHelpText(configured.getHelpText());
                    List<ProviderConfigProperty> configProperties = configured.getConfigProperties();
                    if (configProperties == null)
                        configProperties = Collections.EMPTY_LIST;
                    rep.setProperties(ModelToRepresentation.toRepresentation(configProperties));
                    if (pi instanceof ComponentFactory) {
                        rep.setMetadata(((ComponentFactory) pi).getTypeMetadata());
                    }
                    List<ComponentTypeRepresentation> reps = info.getComponentTypes().get(spi.getProviderClass().getName());
                    if (reps == null) {
                        reps = new LinkedList<>();
                        info.getComponentTypes().put(spi.getProviderClass().getName(), reps);
                    }
                    reps.add(rep);
                }
                providers.put(name, provider);
            }
        }
        spiRep.setProviders(providers);
        spiReps.put(spi.getName(), spiRep);
    }
    info.setProviders(spiReps);
}
Also used : SpiInfoRepresentation(org.keycloak.representations.info.SpiInfoRepresentation) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ProviderConfigProperty(org.keycloak.provider.ProviderConfigProperty) ComponentFactory(org.keycloak.component.ComponentFactory) ProviderRepresentation(org.keycloak.representations.info.ProviderRepresentation) Spi(org.keycloak.provider.Spi) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) ConfiguredProvider(org.keycloak.provider.ConfiguredProvider) ComponentTypeRepresentation(org.keycloak.representations.idm.ComponentTypeRepresentation)

Example 2 with ProviderRepresentation

use of org.keycloak.representations.info.ProviderRepresentation in project keycloak by keycloak.

the class ServerInfoTest method testServerInfo.

@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());
    Map<String, ProviderRepresentation> jpaProviders = info.getProviders().get("connectionsJpa").getProviders();
    ProviderRepresentation jpaProvider = jpaProviders.values().iterator().next();
    log.infof("JPA Connections provider info: %s", jpaProvider.getOperationalInfo());
}
Also used : ServerInfoRepresentation(org.keycloak.representations.info.ServerInfoRepresentation) ProviderRepresentation(org.keycloak.representations.info.ProviderRepresentation) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest) Test(org.junit.Test)

Aggregations

ProviderRepresentation (org.keycloak.representations.info.ProviderRepresentation)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 Test (org.junit.Test)1 ComponentFactory (org.keycloak.component.ComponentFactory)1 ConfiguredProvider (org.keycloak.provider.ConfiguredProvider)1 ProviderConfigProperty (org.keycloak.provider.ProviderConfigProperty)1 Spi (org.keycloak.provider.Spi)1 ComponentTypeRepresentation (org.keycloak.representations.idm.ComponentTypeRepresentation)1 ServerInfoRepresentation (org.keycloak.representations.info.ServerInfoRepresentation)1 SpiInfoRepresentation (org.keycloak.representations.info.SpiInfoRepresentation)1 AbstractKeycloakTest (org.keycloak.testsuite.AbstractKeycloakTest)1