Rename IDPSpi to IdentityProviderStorageSpi

Closes #31639

Signed-off-by: Stefan Guilhen <sguilhen@redhat.com>
This commit is contained in:
Stefan Guilhen 2024-08-21 18:32:47 -03:00 committed by Pedro Igor
parent 98dc21e6fc
commit 88cca10472
18 changed files with 79 additions and 77 deletions

View file

@ -19,8 +19,8 @@ package org.keycloak.models.cache.infinispan.idp;
import java.util.Map;
import java.util.stream.Stream;
import org.keycloak.common.Profile;
import org.keycloak.models.IDPProvider;
import org.keycloak.models.IdentityProviderMapperModel;
import org.keycloak.models.IdentityProviderStorageProvider;
import org.keycloak.models.IdentityProviderModel;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.ModelException;
@ -31,18 +31,18 @@ import org.keycloak.models.cache.infinispan.CachedCount;
import org.keycloak.models.cache.infinispan.RealmCacheSession;
import org.keycloak.organization.OrganizationProvider;
public class InfinispanIDPProvider implements IDPProvider {
public class InfinispanIdentityProviderStorageProvider implements IdentityProviderStorageProvider {
private static final String IDP_COUNT_KEY_SUFFIX = ".idp.count";
private static final String IDP_ALIAS_KEY_SUFFIX = ".idp.alias";
private final KeycloakSession session;
private final IDPProvider idpDelegate;
private final IdentityProviderStorageProvider idpDelegate;
private final RealmCacheSession realmCache;
public InfinispanIDPProvider(KeycloakSession session) {
public InfinispanIdentityProviderStorageProvider(KeycloakSession session) {
this.session = session;
this.idpDelegate = session.getProvider(IDPProvider.class, "jpa");
this.idpDelegate = session.getProvider(IdentityProviderStorageProvider.class, "jpa");
this.realmCache = (RealmCacheSession) session.getProvider(CacheRealmProvider.class);
}

View file

@ -17,18 +17,18 @@
package org.keycloak.models.cache.infinispan.idp;
import org.keycloak.Config;
import org.keycloak.models.IDPProvider;
import org.keycloak.models.IDPProviderFactory;
import org.keycloak.models.IdentityProviderStorageProvider;
import org.keycloak.models.IdentityProviderStorageProviderFactory;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.KeycloakSessionFactory;
public class InfinispanIDPProviderFactory implements IDPProviderFactory<IDPProvider>{
public class InfinispanIdentityProviderStorageProviderFactory implements IdentityProviderStorageProviderFactory<IdentityProviderStorageProvider> {
public static final String PROVIDER_ID = "infinispan";
@Override
public IDPProvider create(KeycloakSession session) {
return new InfinispanIDPProvider(session);
public IdentityProviderStorageProvider create(KeycloakSession session) {
return new InfinispanIdentityProviderStorageProvider(session);
}
@Override

View file

@ -15,4 +15,4 @@
# limitations under the License.
#
org.keycloak.models.cache.infinispan.idp.InfinispanIDPProviderFactory
org.keycloak.models.cache.infinispan.idp.InfinispanIdentityProviderStorageProviderFactory

View file

@ -31,15 +31,14 @@ import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.MapJoin;
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Root;
import java.util.stream.Collectors;
import org.hibernate.Session;
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.connections.jpa.JpaConnectionProvider;
import org.keycloak.models.IDPProvider;
import org.keycloak.models.IdentityProviderMapperModel;
import org.keycloak.models.IdentityProviderStorageProvider;
import org.keycloak.models.IdentityProviderModel;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.ModelException;
@ -62,18 +61,18 @@ import static org.keycloak.models.jpa.PaginationUtils.paginateQuery;
import static org.keycloak.utils.StreamsUtil.closing;
/**
* A JPA based implementation of {@link IDPProvider}.
* A JPA based implementation of {@link IdentityProviderStorageProvider}.
*
* @author <a href="mailto:sguilhen@redhat.com">Stefan Guilhen</a>
*/
public class JpaIDPProvider implements IDPProvider {
public class JpaIdentityProviderStorageProvider implements IdentityProviderStorageProvider {
protected static final Logger logger = Logger.getLogger(IDPProvider.class);
protected static final Logger logger = Logger.getLogger(IdentityProviderStorageProvider.class);
private final EntityManager em;
private final KeycloakSession session;
public JpaIDPProvider(KeycloakSession session) {
public JpaIdentityProviderStorageProvider(KeycloakSession session) {
this.session = session;
this.em = session.getProvider(JpaConnectionProvider.class).getEntityManager();
}
@ -166,8 +165,7 @@ public class JpaIDPProvider implements IDPProvider {
// flush so that constraint violations are flagged and converted into model exception now rather than at the end of the tx.
em.flush();
session.identityProviders().getMappersByAliasStream(alias).collect(Collectors.toList())
.forEach(session.identityProviders()::removeMapper);
session.identityProviders().getMappersByAliasStream(alias).forEach(session.identityProviders()::removeMapper);
// send identity provider removed event.
RealmModel realm = this.getRealm();

View file

@ -17,22 +17,22 @@
package org.keycloak.models.jpa;
import org.keycloak.Config;
import org.keycloak.models.IDPProviderFactory;
import org.keycloak.models.IdentityProviderStorageProviderFactory;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.KeycloakSessionFactory;
/**
* A JPA based implementation of {@link IDPProviderFactory}.
* A JPA based implementation of {@link IdentityProviderStorageProviderFactory}.
*
* @author <a href="mailto:sguilhen@redhat.com">Stefan Guilhen</a>
*/
public class JpaIDPProviderFactory implements IDPProviderFactory<JpaIDPProvider> {
public class JpaIdentityProviderStorageProviderFactory implements IdentityProviderStorageProviderFactory<JpaIdentityProviderStorageProvider> {
public static final String ID = "jpa";
@Override
public JpaIDPProvider create(KeycloakSession session) {
return new JpaIDPProvider(session);
public JpaIdentityProviderStorageProvider create(KeycloakSession session) {
return new JpaIdentityProviderStorageProvider(session);
}
@Override

View file

@ -15,4 +15,4 @@
# limitations under the License.
#
org.keycloak.models.jpa.JpaIDPProviderFactory
org.keycloak.models.jpa.JpaIdentityProviderStorageProviderFactory

View file

@ -20,7 +20,7 @@ package org.keycloak.storage.datastore;
import org.keycloak.models.ClientProvider;
import org.keycloak.models.ClientScopeProvider;
import org.keycloak.models.GroupProvider;
import org.keycloak.models.IDPProvider;
import org.keycloak.models.IdentityProviderStorageProvider;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmProvider;
import org.keycloak.models.RoleProvider;
@ -50,7 +50,7 @@ public class DefaultDatastoreProvider implements DatastoreProvider, StoreManager
private ClientProvider clientProvider;
private ClientScopeProvider clientScopeProvider;
private GroupProvider groupProvider;
private IDPProvider idpProvider;
private IdentityProviderStorageProvider identityProviderStorageProvider;
private UserLoginFailureProvider userLoginFailureProvider;
private RealmProvider realmProvider;
private RoleProvider roleProvider;
@ -213,11 +213,11 @@ public class DefaultDatastoreProvider implements DatastoreProvider, StoreManager
}
@Override
public IDPProvider identityProviders() {
if (idpProvider == null) {
idpProvider = session.getProvider(IDPProvider.class);
public IdentityProviderStorageProvider identityProviders() {
if (identityProviderStorageProvider == null) {
identityProviderStorageProvider = session.getProvider(IdentityProviderStorageProvider.class);
}
return idpProvider;
return identityProviderStorageProvider;
}
@Override

View file

@ -18,5 +18,5 @@ package org.keycloak.models;
import org.keycloak.provider.ProviderFactory;
public interface IDPProviderFactory<T extends IDPProvider> extends ProviderFactory<T> {
public interface IdentityProviderStorageProviderFactory<T extends IdentityProviderStorageProvider> extends ProviderFactory<T> {
}

View file

@ -20,18 +20,18 @@ import org.keycloak.provider.Provider;
import org.keycloak.provider.ProviderFactory;
import org.keycloak.provider.Spi;
public class IDPSpi implements Spi {
public class IdentityProviderStorageSpi implements Spi {
public static final String NAME = "idp";
public static final String NAME = "identity-provider-storage";
@Override
public Class<? extends ProviderFactory> getProviderFactoryClass() {
return IDPProviderFactory.class;
return IdentityProviderStorageProviderFactory.class;
}
@Override
public Class<? extends Provider> getProviderClass() {
return IDPProvider.class;
return IdentityProviderStorageProvider.class;
}
@Override

View file

@ -20,7 +20,7 @@ package org.keycloak.storage;
import org.keycloak.models.ClientProvider;
import org.keycloak.models.ClientScopeProvider;
import org.keycloak.models.GroupProvider;
import org.keycloak.models.IDPProvider;
import org.keycloak.models.IdentityProviderStorageProvider;
import org.keycloak.models.RealmProvider;
import org.keycloak.models.RoleProvider;
import org.keycloak.models.SingleUseObjectProvider;
@ -40,7 +40,7 @@ public interface DatastoreProvider extends Provider {
GroupProvider groups();
IDPProvider identityProviders();
IdentityProviderStorageProvider identityProviders();
UserLoginFailureProvider loginFailures();

View file

@ -22,7 +22,7 @@ org.keycloak.provider.ExceptionConverterSpi
org.keycloak.models.ClientSpi
org.keycloak.models.ClientScopeSpi
org.keycloak.models.GroupSpi
org.keycloak.models.IDPSpi
org.keycloak.models.IdentityProviderStorageSpi
org.keycloak.models.RealmSpi
org.keycloak.models.RoleSpi
org.keycloak.models.DeploymentStateSpi

View file

@ -26,16 +26,16 @@ import java.util.stream.Stream;
import org.keycloak.provider.Provider;
/**
* The {@code IDPProvider} is concerned with the storage/retrieval of the configured identity providers in Keycloak. In
* other words, it is a provider of identity providers (IDPs) and, as such, handles the CRUD operations for IDPs.
* The {@link IdentityProviderStorageProvider} is concerned with the storage/retrieval of the configured identity providers
* in Keycloak. In other words, it is a provider of identity providers (IDPs) and, as such, handles the CRUD operations for IDPs.
* </p>
* It is not to be confused with the {@code IdentityProvider} found in server-spi-private as that provider is meant to be
* implemented by actual identity providers that handle the logic of authenticating users with third party brokers, such
* as Microsoft, Google, Github, LinkedIn, etc.
* as Microsoft, Google, GitHub, LinkedIn, etc.
*
* @author <a href="mailto:sguilhen@redhat.com">Stefan Guilhen</a>
*/
public interface IDPProvider extends Provider {
public interface IdentityProviderStorageProvider extends Provider {
/**
* Creates a new identity provider from the specified model.

View file

@ -209,7 +209,7 @@ public interface KeycloakSession extends AutoCloseable {
*
* @return the default IDP provider.
*/
IDPProvider identityProviders();
IdentityProviderStorageProvider identityProviders();
@Override
void close();

View file

@ -443,31 +443,31 @@ public interface RealmModel extends RoleContainerModel {
* Returns identity providers as a stream.
*
* @return Stream of {@link IdentityProviderModel}. Never returns {@code null}.
* @deprecated Use {@link IDPProvider#getAllStream()} instead.
* @deprecated Use {@link IdentityProviderStorageProvider#getAllStream()} instead.
*/
@Deprecated
Stream<IdentityProviderModel> getIdentityProvidersStream();
/**
* @deprecated Use {@link IDPProvider#getByAlias(String)} instead.
* @deprecated Use {@link IdentityProviderStorageProvider#getByAlias(String)} instead.
*/
@Deprecated
IdentityProviderModel getIdentityProviderByAlias(String alias);
/**
* @deprecated Use {@link IDPProvider#create(IdentityProviderModel)} instead.
* @deprecated Use {@link IdentityProviderStorageProvider#create(IdentityProviderModel)} instead.
*/
@Deprecated
void addIdentityProvider(IdentityProviderModel identityProvider);
/**
* @deprecated Use {@link IDPProvider#remove(String)} instead.
* @deprecated Use {@link IdentityProviderStorageProvider#remove(String)} instead.
*/
@Deprecated
void removeIdentityProviderByAlias(String alias);
/**
* @deprecated Use {@link IDPProvider#update(IdentityProviderModel)} instead.
* @deprecated Use {@link IdentityProviderStorageProvider#update(IdentityProviderModel)} instead.
*/
@Deprecated
void updateIdentityProvider(IdentityProviderModel identityProvider);
@ -667,7 +667,7 @@ public interface RealmModel extends RoleContainerModel {
void setDefaultRole(RoleModel role);
/**
* @deprecated use {@link IDPProvider#isIdentityFederationEnabled()} instead.
* @deprecated use {@link IdentityProviderStorageProvider#isIdentityFederationEnabled()} instead.
*/
@Deprecated
boolean isIdentityFederationEnabled();

View file

@ -22,7 +22,7 @@ import org.keycloak.authentication.authenticators.broker.AbstractIdpAuthenticato
import org.keycloak.authentication.authenticators.broker.util.SerializedBrokeredIdentityContext;
import org.keycloak.common.Profile;
import org.keycloak.models.FederatedIdentityModel;
import org.keycloak.models.IDPProvider;
import org.keycloak.models.IdentityProviderStorageProvider;
import org.keycloak.models.IdentityProviderModel;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.OrderedModel;
@ -223,19 +223,19 @@ public class IdentityProviderBean {
* @return the custom {@link Predicate} used as a last filter before conversion into {@link IdentityProvider}
*/
protected Predicate<IdentityProviderModel> federatedProviderPredicate() {
return IDPProvider.LoginFilter.getLoginPredicate();
return IdentityProviderStorageProvider.LoginFilter.getLoginPredicate();
}
/**
* Builds and returns a list of {@link IdentityProvider} instances that will be available for login. This method goes
* to the {@link IDPProvider} to fetch the IDPs that can be used for login (enabled, not link-only and not set to be
* to the {@link IdentityProviderStorageProvider} to fetch the IDPs that can be used for login (enabled, not link-only and not set to be
* hidden on login page).
*
* @param existingIDP the alias of the IDP that must be filtered out from the result (used when linking a new IDP to a user's account).
* @return a {@link List} containing the constructed {@link IdentityProvider}s.
*/
protected List<IdentityProvider> searchForIdentityProviders(String existingIDP) {
return session.identityProviders().getForLogin(IDPProvider.FetchMode.REALM_ONLY, null)
return session.identityProviders().getForLogin(IdentityProviderStorageProvider.FetchMode.REALM_ONLY, null)
.filter(idp -> !Objects.equals(existingIDP, idp.getAlias()))
.map(idp -> createIdentityProvider(this.realm, this.baseURI, idp))
.sorted(IDP_COMPARATOR_INSTANCE).toList();

View file

@ -22,11 +22,14 @@ import java.util.Objects;
import java.util.function.Predicate;
import org.keycloak.forms.login.freemarker.model.IdentityProviderBean;
import org.keycloak.models.IDPProvider;
import org.keycloak.models.IdentityProviderModel;
import org.keycloak.models.OrganizationModel;
import org.keycloak.organization.utils.Organizations;
import static org.keycloak.models.IdentityProviderStorageProvider.FetchMode.ALL;
import static org.keycloak.models.IdentityProviderStorageProvider.FetchMode.ORG_ONLY;
import static org.keycloak.models.IdentityProviderStorageProvider.FetchMode.REALM_ONLY;
public class OrganizationAwareIdentityProviderBean extends IdentityProviderBean {
private final OrganizationModel organization;
@ -52,7 +55,7 @@ public class OrganizationAwareIdentityProviderBean extends IdentityProviderBean
protected List<IdentityProvider> searchForIdentityProviders(String existingIDP) {
if (onlyRealmBrokers) {
// we only want the realm-level IDPs - i.e. those not associated with any orgs.
return session.identityProviders().getForLogin(IDPProvider.FetchMode.REALM_ONLY, null)
return session.identityProviders().getForLogin(REALM_ONLY, null)
.filter(idp -> !Objects.equals(existingIDP, idp.getAlias()))
.map(idp -> createIdentityProvider(this.realm, this.baseURI, idp))
.sorted(IDP_COMPARATOR_INSTANCE).toList();
@ -68,12 +71,12 @@ public class OrganizationAwareIdentityProviderBean extends IdentityProviderBean
.sorted(IDP_COMPARATOR_INSTANCE).toList();
}
// we don't have a specific organization - fetch public enabled IDPs linked to any org.
return session.identityProviders().getForLogin(IDPProvider.FetchMode.ORG_ONLY, null)
return session.identityProviders().getForLogin(ORG_ONLY, null)
.filter(idp -> !Objects.equals(existingIDP, idp.getAlias()))
.map(idp -> createIdentityProvider(this.realm, this.baseURI, idp))
.sorted(IDP_COMPARATOR_INSTANCE).toList();
}
return session.identityProviders().getForLogin(IDPProvider.FetchMode.ALL, this.organization != null ? this.organization.getId() : null)
return session.identityProviders().getForLogin(ALL, this.organization != null ? this.organization.getId() : null)
.filter(idp -> !Objects.equals(existingIDP, idp.getAlias()))
.map(idp -> createIdentityProvider(this.realm, this.baseURI, idp))
.sorted(IDP_COMPARATOR_INSTANCE).toList();

View file

@ -25,7 +25,7 @@ import org.keycloak.keys.DefaultKeyManager;
import org.keycloak.models.ClientProvider;
import org.keycloak.models.ClientScopeProvider;
import org.keycloak.models.GroupProvider;
import org.keycloak.models.IDPProvider;
import org.keycloak.models.IdentityProviderStorageProvider;
import org.keycloak.models.KeyManager;
import org.keycloak.models.KeycloakContext;
import org.keycloak.models.KeycloakSession;
@ -318,7 +318,7 @@ public abstract class DefaultKeycloakSession implements KeycloakSession {
}
@Override
public IDPProvider identityProviders() {
public IdentityProviderStorageProvider identityProviders() {
return getDatastoreProvider().identityProviders();
}

View file

@ -16,6 +16,9 @@
*/
package org.keycloak.testsuite.model.parameters;
import java.util.Set;
import com.google.common.collect.ImmutableSet;
import org.keycloak.authorization.jpa.store.JPAAuthorizationStoreFactory;
import org.keycloak.broker.provider.IdentityProviderFactory;
import org.keycloak.broker.provider.IdentityProviderSpi;
@ -27,31 +30,29 @@ import org.keycloak.connections.jpa.updater.liquibase.conn.LiquibaseConnectionPr
import org.keycloak.connections.jpa.updater.liquibase.conn.LiquibaseConnectionSpi;
import org.keycloak.connections.jpa.updater.liquibase.lock.LiquibaseDBLockProviderFactory;
import org.keycloak.events.jpa.JpaEventStoreProviderFactory;
import org.keycloak.models.IDPSpi;
import org.keycloak.migration.MigrationProviderFactory;
import org.keycloak.migration.MigrationSpi;
import org.keycloak.models.IdentityProviderStorageSpi;
import org.keycloak.models.dblock.DBLockSpi;
import org.keycloak.models.jpa.JpaIDPProviderFactory;
import org.keycloak.models.jpa.JpaClientProviderFactory;
import org.keycloak.models.jpa.JpaClientScopeProviderFactory;
import org.keycloak.models.jpa.JpaGroupProviderFactory;
import org.keycloak.models.jpa.JpaIdentityProviderStorageProviderFactory;
import org.keycloak.models.jpa.JpaRealmProviderFactory;
import org.keycloak.models.jpa.JpaRoleProviderFactory;
import org.keycloak.models.jpa.JpaUserProviderFactory;
import org.keycloak.models.jpa.session.JpaRevokedTokensPersisterProviderFactory;
import org.keycloak.models.jpa.session.JpaUserSessionPersisterProviderFactory;
import org.keycloak.models.session.RevokedTokenPersisterSpi;
import org.keycloak.models.session.UserSessionPersisterSpi;
import org.keycloak.migration.MigrationProviderFactory;
import org.keycloak.migration.MigrationSpi;
import org.keycloak.testsuite.model.KeycloakModelParameters;
import org.keycloak.models.jpa.JpaClientProviderFactory;
import org.keycloak.models.jpa.JpaClientScopeProviderFactory;
import org.keycloak.models.jpa.JpaGroupProviderFactory;
import org.keycloak.models.jpa.JpaRealmProviderFactory;
import org.keycloak.models.jpa.JpaRoleProviderFactory;
import org.keycloak.models.jpa.JpaUserProviderFactory;
import org.keycloak.protocol.LoginProtocolFactory;
import org.keycloak.protocol.LoginProtocolSpi;
import org.keycloak.provider.ProviderFactory;
import org.keycloak.provider.Spi;
import org.keycloak.storage.DatastoreSpi;
import org.keycloak.storage.datastore.DefaultDatastoreProviderFactory;
import org.keycloak.testsuite.model.Config;
import com.google.common.collect.ImmutableSet;
import java.util.Set;
import org.keycloak.protocol.LoginProtocolFactory;
import org.keycloak.protocol.LoginProtocolSpi;
import org.keycloak.testsuite.model.KeycloakModelParameters;
/**
*
@ -76,7 +77,7 @@ public class Jpa extends KeycloakModelParameters {
.add(DBLockSpi.class)
//required for FederatedIdentityModel
.add(IDPSpi.class)
.add(IdentityProviderStorageSpi.class)
.add(IdentityProviderSpi.class)
.build();
@ -91,7 +92,7 @@ public class Jpa extends KeycloakModelParameters {
.add(JpaClientScopeProviderFactory.class)
.add(JpaEventStoreProviderFactory.class)
.add(JpaGroupProviderFactory.class)
.add(JpaIDPProviderFactory.class)
.add(JpaIdentityProviderStorageProviderFactory.class)
.add(JpaRealmProviderFactory.class)
.add(JpaRoleProviderFactory.class)
.add(JpaUpdaterProviderFactory.class)