diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java b/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java index ecf207a9fc..12e4148c87 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java @@ -19,6 +19,9 @@ package org.keycloak.models.jpa; import org.keycloak.Config; import org.jboss.logging.Logger; +import org.keycloak.broker.provider.IdentityProvider; +import org.keycloak.broker.provider.IdentityProviderFactory; +import org.keycloak.broker.social.SocialIdentityProvider; import org.keycloak.common.enums.SslRequired; import org.keycloak.common.util.MultivaluedHashMap; import org.keycloak.common.util.Time; @@ -1197,7 +1200,7 @@ public class RealmAdapter implements LegacyRealmModel, JpaModel { } private IdentityProviderModel entityToModel(IdentityProviderEntity entity) { - IdentityProviderModel identityProviderModel = new IdentityProviderModel(); + IdentityProviderModel identityProviderModel = getModelFromProviderFactory(entity.getProviderId()); identityProviderModel.setProviderId(entity.getProviderId()); identityProviderModel.setAlias(entity.getAlias()); identityProviderModel.setDisplayName(entity.getDisplayName()); @@ -1218,6 +1221,21 @@ public class RealmAdapter implements LegacyRealmModel, JpaModel { return identityProviderModel; } + private IdentityProviderModel getModelFromProviderFactory(String providerId) { + Optional factory = Stream.concat(session.getKeycloakSessionFactory().getProviderFactoriesStream(IdentityProvider.class), + session.getKeycloakSessionFactory().getProviderFactoriesStream(SocialIdentityProvider.class)) + .filter(providerFactory -> Objects.equals(providerFactory.getId(), providerId)) + .map(IdentityProviderFactory.class::cast) + .findFirst(); + + if (factory.isPresent()) { + return factory.get().createConfig(); + } else { + logger.warn("Couldn't find a suitable identity provider factory for " + providerId); + return new IdentityProviderModel(); + } + } + @Override public IdentityProviderModel getIdentityProviderByAlias(String alias) { return getIdentityProvidersStream() diff --git a/server-spi/src/main/java/org/keycloak/models/IdentityProviderModel.java b/server-spi/src/main/java/org/keycloak/models/IdentityProviderModel.java index 7f01927279..56e6b72fe4 100755 --- a/server-spi/src/main/java/org/keycloak/models/IdentityProviderModel.java +++ b/server-spi/src/main/java/org/keycloak/models/IdentityProviderModel.java @@ -70,6 +70,8 @@ public class IdentityProviderModel implements Serializable { private String displayName; + private String displayIconClasses; + private IdentityProviderSyncMode syncMode; /** @@ -96,6 +98,7 @@ public class IdentityProviderModel implements Serializable { this.addReadTokenRoleOnCreate = model.addReadTokenRoleOnCreate; this.firstBrokerLoginFlowId = model.getFirstBrokerLoginFlowId(); this.postBrokerLoginFlowId = model.getPostBrokerLoginFlowId(); + this.displayIconClasses = model.getDisplayIconClasses(); } } @@ -206,7 +209,7 @@ public class IdentityProviderModel implements Serializable { } public String getDisplayIconClasses() { - return null; + return displayIconClasses; } /**