Skip to content

Commit

Permalink
Map Store Removal: Rename Legacy* classes (keycloak#26273)
Browse files Browse the repository at this point in the history
Closes keycloak#24105

Signed-off-by: Martin Kanis <[email protected]>
  • Loading branch information
martin-kanis authored Jan 23, 2024
1 parent 5bf2d4b commit 84603a9
Show file tree
Hide file tree
Showing 71 changed files with 209 additions and 245 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ jobs:
with:
job-id: jdk-integration-tests-${{ matrix.os }}-${{ matrix.dist }}-${{ matrix.version }}

legacy-store-integration-tests:
name: Legacy Store IT
store-integration-tests:
name: Store IT
needs: [build, conditional]
if: needs.conditional.outputs.ci-store == 'true'
runs-on: ubuntu-latest
Expand Down Expand Up @@ -283,13 +283,13 @@ jobs:
env:
GH_TOKEN: ${{ github.token }}
with:
job-name: Legacy Store IT
job-name: Store IT

- name: Surefire reports
if: always()
uses: ./.github/actions/archive-surefire-reports
with:
job-id: legacy-store-integration-tests-${{ matrix.db }}
job-id: store-integration-tests-${{ matrix.db }}

store-model-tests:
name: Store Model Tests
Expand Down Expand Up @@ -325,7 +325,7 @@ jobs:
job-id: store-model-tests

clustering-integration-tests:
name: Legacy Clustering IT
name: Clustering IT
needs: build
runs-on: ubuntu-latest
timeout-minutes: 35
Expand All @@ -351,7 +351,7 @@ jobs:
env:
GH_TOKEN: ${{ github.token }}
with:
job-name: Legacy Clustering IT
job-name: Clustering IT

- name: Surefire reports
if: always()
Expand Down Expand Up @@ -650,7 +650,7 @@ jobs:
- quarkus-unit-tests
- quarkus-integration-tests
- jdk-integration-tests
- legacy-store-integration-tests
- store-integration-tests
- store-model-tests
- clustering-integration-tests
- fips-unit-tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,11 @@ PUT /admin/realms/{realm}/users/{id}/execute-actions-email
= Removal of the deprecated mode for SAML encryption

The compatibility mode for SAML encryption introduced in version 21 is now removed. The system property `keycloak.saml.deprecated.encryption` is not managed anymore by the server. The clients which still used the old signing key for encryption should update it from the new IDP configuration metadata.

= Renaming JPA provider configuration options for migration

After removal of the Map Store the following configuration options were renamed:

* `spi-connections-jpa-legacy-initialize-empty` to `spi-connections-jpa-quarkus-initialize-empty`
* `spi-connections-jpa-legacy-migration-export` to `spi-connections-jpa-quarkus-migration-export`
* `spi-connections-jpa-legacy-migration-strategy` to `spi-connections-jpa-quarkus-migration-strategy`
4 changes: 2 additions & 2 deletions docs/documentation/upgrading/topics/migrate_db.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ default `connections-jpa` provider:

[source,bash]
----
kc.[sh|bat] start --spi-connections-jpa-legacy-migration-strategy=manual
kc.[sh|bat] start --spi-connections-jpa-quarkus-migration-strategy=manual
----

When you start the server with this configuration it checks if the database needs to be migrated.
Expand All @@ -42,7 +42,7 @@ default `connections-jpa` provider:

[source,bash]
----
kc.[sh|bat] start --spi-connections-jpa-legacy-migration-export=<path>/<file.sql>
kc.[sh|bat] start --spi-connections-jpa-quarkus-migration-export=<path>/<file.sql>
----

For further details on how to apply this file to the database, see the documentation for the relational database you're using.
Expand Down
6 changes: 3 additions & 3 deletions docs/guides/server/db.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -247,16 +247,16 @@ The maximum timeout for this lock is 900 seconds. If a node waits on this lock f
To setup the JPA migrationStrategy (manual/update/validate) you should setup JPA provider as follows:

.Setting the `migration-strategy` for the `quarkus` provider of the `connections-jpa` SPI
<@kc.start parameters="--spi-connections-jpa-legacy-migration-strategy=manual"/>
<@kc.start parameters="--spi-connections-jpa-quarkus-migration-strategy=manual"/>

If you want to get a SQL file for DB initialization, too, you have to add this additional SPI initializeEmpty (true/false):

.Setting the `initialize-empty` for the `quarkus` provider of the `connections-jpa` SPI
<@kc.start parameters="--spi-connections-jpa-legacy-initialize-empty=false"/>
<@kc.start parameters="--spi-connections-jpa-quarkus-initialize-empty=false"/>

In the same way the migrationExport to point to a specific file and location:

.Setting the `migration-export` for the `quarkus` provider of the `connections-jpa` SPI
<@kc.start parameters="--spi-connections-jpa-legacy-migration-export=<path>/<file.sql>"/>
<@kc.start parameters="--spi-connections-jpa-quarkus-migration-export=<path>/<file.sql>"/>

</@tmpl.guide>
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.keycloak.credential.CredentialInput;
import org.keycloak.credential.CredentialInputUpdater;
import org.keycloak.credential.CredentialInputValidator;
import org.keycloak.credential.LegacyUserCredentialManager;
import org.keycloak.credential.UserCredentialManager;
import org.keycloak.federation.kerberos.impl.KerberosUsernamePasswordAuthenticator;
import org.keycloak.federation.kerberos.impl.SPNEGOAuthenticator;
import org.keycloak.models.CredentialValidationOutput;
Expand Down Expand Up @@ -168,7 +168,7 @@ public boolean isConfiguredFor(RealmModel realm, UserModel user, String credenti
@Override
public boolean isValid(RealmModel realm, UserModel user, CredentialInput input) {
if (!(input instanceof UserCredentialModel)) return false;
if (input.getType().equals(PasswordCredentialModel.TYPE) && !((LegacyUserCredentialManager) user.credentialManager()).isConfiguredLocally(PasswordCredentialModel.TYPE)) {
if (input.getType().equals(PasswordCredentialModel.TYPE) && !((UserCredentialManager) user.credentialManager()).isConfiguredLocally(PasswordCredentialModel.TYPE)) {
return validPassword(user.getFirstAttribute(KERBEROS_PRINCIPAL), input.getChallengeResponse());
} else {
return false; // invalid cred type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import org.keycloak.credential.CredentialInput;
import org.keycloak.credential.CredentialInputUpdater;
import org.keycloak.credential.CredentialInputValidator;
import org.keycloak.credential.LegacyUserCredentialManager;
import org.keycloak.credential.UserCredentialManager;
import org.keycloak.federation.kerberos.KerberosPrincipal;
import org.keycloak.federation.kerberos.impl.KerberosUsernamePasswordAuthenticator;
import org.keycloak.federation.kerberos.impl.SPNEGOAuthenticator;
Expand All @@ -68,7 +68,7 @@
import org.keycloak.policy.PolicyError;
import org.keycloak.models.cache.UserCache;
import org.keycloak.storage.DatastoreProvider;
import org.keycloak.storage.LegacyStoreManagers;
import org.keycloak.storage.StoreManagers;
import org.keycloak.storage.ReadOnlyException;
import org.keycloak.storage.StorageId;
import org.keycloak.storage.UserStoragePrivateUtil;
Expand Down Expand Up @@ -205,7 +205,7 @@ protected UserModel proxy(RealmModel realm, UserModel local, LDAPObject ldapObje

// We need to avoid having CachedUserModel as cache is upper-layer then LDAP. Hence having CachedUserModel here may cause StackOverflowError
if (local instanceof CachedUserModel) {
LegacyStoreManagers datastoreProvider = (LegacyStoreManagers) session.getProvider(DatastoreProvider.class);
StoreManagers datastoreProvider = (StoreManagers) session.getProvider(DatastoreProvider.class);
local = datastoreProvider.userStorageManager().getUserById(realm, local.getId());

existing = userManager.getManagedProxiedUser(local.getId());
Expand Down Expand Up @@ -841,7 +841,7 @@ public boolean isConfiguredFor(RealmModel realm, UserModel user, String credenti
@Override
public boolean isValid(RealmModel realm, UserModel user, CredentialInput input) {
if (!(input instanceof UserCredentialModel)) return false;
if (input.getType().equals(PasswordCredentialModel.TYPE) && !((LegacyUserCredentialManager) user.credentialManager()).isConfiguredLocally(PasswordCredentialModel.TYPE)) {
if (input.getType().equals(PasswordCredentialModel.TYPE) && !((UserCredentialManager) user.credentialManager()).isConfiguredLocally(PasswordCredentialModel.TYPE)) {
return validPassword(realm, user, input.getChallengeResponse());
} else {
return false; // invalid cred type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.keycloak.models.cache.infinispan.events.*;
import org.keycloak.models.utils.KeycloakModelUtils;
import org.keycloak.storage.DatastoreProvider;
import org.keycloak.storage.LegacyStoreManagers;
import org.keycloak.storage.StoreManagers;
import org.keycloak.storage.StorageId;
import org.keycloak.storage.client.ClientStorageProviderModel;

Expand Down Expand Up @@ -121,13 +121,13 @@ public class RealmCacheSession implements CacheRealmProvider {

protected boolean clearAll;
protected final long startupRevision;
private final LegacyStoreManagers datastoreProvider;
private final StoreManagers datastoreProvider;

public RealmCacheSession(RealmCacheManager cache, KeycloakSession session) {
this.cache = cache;
this.session = session;
this.startupRevision = cache.getCurrentCounter();
this.datastoreProvider = (LegacyStoreManagers) session.getProvider(DatastoreProvider.class);
this.datastoreProvider = (StoreManagers) session.getProvider(DatastoreProvider.class);
session.getTransactionManager().enlistPrepare(getPrepareTransaction());
session.getTransactionManager().enlistAfterCompletion(getAfterTransaction());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@

import org.keycloak.credential.CredentialInput;
import org.keycloak.credential.CredentialModel;
import org.keycloak.credential.LegacyUserCredentialManager;
import org.keycloak.credential.UserCredentialManager;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
import org.keycloak.models.UserModel;

/**
* @author Alexander Schwartz
*/
public abstract class SubjectCredentialManagerCacheAdapter extends LegacyUserCredentialManager {
public abstract class SubjectCredentialManagerCacheAdapter extends UserCredentialManager {

public SubjectCredentialManagerCacheAdapter(KeycloakSession session, RealmModel realm, UserModel user) {
super(session, realm, user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.keycloak.models.cache.infinispan;

import org.keycloak.credential.CredentialModel;
import org.keycloak.credential.LegacyUserCredentialManager;
import org.keycloak.models.ClientModel;
import org.keycloak.models.GroupModel;
import org.keycloak.models.KeycloakSession;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
import org.keycloak.models.utils.ReadOnlyUserModelDelegate;
import org.keycloak.storage.CacheableStorageProviderModel;
import org.keycloak.storage.DatastoreProvider;
import org.keycloak.storage.LegacyStoreManagers;
import org.keycloak.storage.StoreManagers;
import org.keycloak.storage.OnCreateComponent;
import org.keycloak.storage.OnUpdateComponent;
import org.keycloak.storage.StorageId;
Expand Down Expand Up @@ -94,13 +94,13 @@ public class UserCacheSession implements UserCache, OnCreateComponent, OnUpdateC
protected Set<String> realmInvalidations = new HashSet<>();
protected Set<InvalidationEvent> invalidationEvents = new HashSet<>(); // Events to be sent across cluster
protected Map<String, UserModel> managedUsers = new HashMap<>();
private LegacyStoreManagers datastoreProvider;
private StoreManagers datastoreProvider;

public UserCacheSession(UserCacheManager cache, KeycloakSession session) {
this.cache = cache;
this.session = session;
this.startupRevision = cache.getCurrentCounter();
this.datastoreProvider = (LegacyStoreManagers) session.getProvider(DatastoreProvider.class);
this.datastoreProvider = (StoreManagers) session.getProvider(DatastoreProvider.class);
session.getTransactionManager().enlistAfterCompletion(getTransaction());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
* @author <a href="mailto:[email protected]">Bill Burke</a>
* @version $Revision: 1 $
*/
public class RealmAdapter implements LegacyRealmModel, JpaModel<RealmEntity> {
public class RealmAdapter implements StorageProviderRealmModel, JpaModel<RealmEntity> {
protected static final Logger logger = Logger.getLogger(RealmAdapter.class);
protected RealmEntity realm;
protected EntityManager em;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import org.keycloak.common.util.MultivaluedHashMap;
import org.keycloak.common.util.ObjectUtil;
import org.keycloak.credential.LegacyUserCredentialManager;
import org.keycloak.credential.UserCredentialManager;
import org.keycloak.models.ClientModel;
import org.keycloak.models.GroupModel;
import org.keycloak.models.KeycloakSession;
Expand Down Expand Up @@ -519,7 +519,7 @@ public void setServiceAccountClientLink(String clientInternalId) {

@Override
public SubjectCredentialManager credentialManager() {
return new LegacyUserCredentialManager(session, realm, this);
return new UserCredentialManager(session, realm, this);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.keycloak.models.RealmModel;
import org.keycloak.representations.idm.RealmRepresentation;
import org.keycloak.storage.DatastoreProvider;
import org.keycloak.storage.datastore.LegacyDatastoreProvider;
import org.keycloak.storage.datastore.DefaultDatastoreProvider;

/**
* @author <a href="mailto:[email protected]">Bill Burke</a>
Expand All @@ -30,11 +30,11 @@
public class MigrationModelManager {

public static void migrate(KeycloakSession session) {
((LegacyDatastoreProvider) session.getProvider(DatastoreProvider.class)).getMigrationManager().migrate();
((DefaultDatastoreProvider) session.getProvider(DatastoreProvider.class)).getMigrationManager().migrate();
}

public static void migrateImport(KeycloakSession session, RealmModel realm, RealmRepresentation rep, boolean skipUserDependent) {
((LegacyDatastoreProvider) session.getProvider(DatastoreProvider.class)).getMigrationManager().migrate(realm, rep, skipUserDependent);
((DefaultDatastoreProvider) session.getProvider(DatastoreProvider.class)).getMigrationManager().migrate(realm, rep, skipUserDependent);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.keycloak.migration.ModelVersion;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.LDAPConstants;
import org.keycloak.models.LegacyRealmModel;
import org.keycloak.models.StorageProviderRealmModel;
import org.keycloak.models.RealmModel;
import org.keycloak.provider.ProviderFactory;
import org.keycloak.representations.idm.RealmRepresentation;
Expand Down Expand Up @@ -53,7 +53,7 @@ public void migrateImport(KeycloakSession session, RealmModel realm, RealmRepres
}

private void migrateLDAPProviders(KeycloakSession session, RealmModel realm) {
((LegacyRealmModel) realm).getUserStorageProvidersStream().forEachOrdered(fedProvider -> {
((StorageProviderRealmModel) realm).getUserStorageProvidersStream().forEachOrdered(fedProvider -> {
if (fedProvider.getProviderId().equals(LDAPConstants.LDAP_PROVIDER)) {
fedProvider = new UserStorageProviderModel(fedProvider); // copy don't want to muck with cache
MultivaluedHashMap<String, String> config = fedProvider.getConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.keycloak.models.ImpersonationConstants;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.LDAPConstants;
import org.keycloak.models.LegacyRealmModel;
import org.keycloak.models.StorageProviderRealmModel;
import org.keycloak.models.RealmModel;
import org.keycloak.models.UserModel;
import org.keycloak.models.cache.UserCache;
Expand Down Expand Up @@ -72,7 +72,7 @@ public void migrateImport(KeycloakSession session, RealmModel realm, RealmRepres

private void migrateLDAPMappers(KeycloakSession session, RealmModel realm) {
List<String> mandatoryInLdap = Arrays.asList("username", "username-cn", "first name", "last name");
((LegacyRealmModel) realm).getUserStorageProvidersStream()
((StorageProviderRealmModel) realm).getUserStorageProvidersStream()
.filter(providerModel -> Objects.equals(providerModel.getProviderId(), LDAPConstants.LDAP_PROVIDER))
.forEachOrdered(providerModel -> realm.getComponentsStream(providerModel.getId())
.filter(mapper -> mandatoryInLdap.contains(mapper.getName()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.keycloak.migration.ModelVersion;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.LDAPConstants;
import org.keycloak.models.LegacyRealmModel;
import org.keycloak.models.StorageProviderRealmModel;
import org.keycloak.models.RealmModel;
import org.keycloak.models.utils.KeycloakModelUtils;
import org.keycloak.representations.idm.RealmRepresentation;
Expand Down Expand Up @@ -51,7 +51,7 @@ public void migrateImport(KeycloakSession session, RealmModel realm, RealmRepres
}

protected void migrateRealm(RealmModel realm) {
((LegacyRealmModel) realm).getUserStorageProvidersStream()
((StorageProviderRealmModel) realm).getUserStorageProvidersStream()
.filter(fedProvider -> Objects.equals(fedProvider.getProviderId(), LDAPConstants.LDAP_PROVIDER))
.filter(this::isActiveDirectory)
.filter(fedProvider -> Objects.isNull(getMapperByName(realm, fedProvider, "MSAD account controls")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.keycloak.models.cache;

import org.keycloak.models.KeycloakSession;
import org.keycloak.models.LegacyRealmModel;
import org.keycloak.models.StorageProviderRealmModel;
import org.keycloak.models.RealmModel;
import org.keycloak.provider.ProviderEvent;

Expand All @@ -29,7 +29,7 @@
* @author <a href="mailto:[email protected]">Bill Burke</a>
* @version $Revision: 1 $
*/
public interface CachedRealmModel extends LegacyRealmModel {
public interface CachedRealmModel extends StorageProviderRealmModel {

interface RealmCachedEvent extends ProviderEvent {
CachedRealmModel getRealm();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.keycloak.models.ClientModel;
import org.keycloak.models.ClientProvider;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.LegacyRealmModel;
import org.keycloak.models.StorageProviderRealmModel;
import org.keycloak.models.ModelException;
import org.keycloak.models.RealmModel;
import org.keycloak.storage.client.ClientLookupProvider;
Expand Down Expand Up @@ -79,7 +79,7 @@ public static ClientStorageProvider getStorageProvider(KeycloakSession session,


private static <T> Stream<ClientStorageProviderModel> getStorageProviders(RealmModel realm, KeycloakSession session, Class<T> type) {
return ((LegacyRealmModel) realm).getClientStorageProvidersStream()
return ((StorageProviderRealmModel) realm).getClientStorageProvidersStream()
.filter(model -> {
ClientStorageProviderFactory factory = getClientStorageProviderFactory(model, session);
if (factory == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.keycloak.component.ComponentModel;
import org.keycloak.models.ClientModel;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.LegacyRealmModel;
import org.keycloak.models.StorageProviderRealmModel;
import org.keycloak.models.ModelException;
import org.keycloak.models.RealmModel;
import org.keycloak.models.RoleModel;
Expand Down Expand Up @@ -73,7 +73,7 @@ public static RoleStorageProvider getStorageProvider(KeycloakSession session, Re
}

public static <T> Stream<RoleStorageProviderModel> getStorageProviders(RealmModel realm, KeycloakSession session, Class<T> type) {
return ((LegacyRealmModel) realm).getRoleStorageProvidersStream()
return ((StorageProviderRealmModel) realm).getRoleStorageProvidersStream()
.filter(model -> {
RoleStorageProviderFactory factory = getRoleStorageProviderFactory(model, session);
if (factory == null) {
Expand Down
Loading

0 comments on commit 84603a9

Please sign in to comment.