Repository navigation
Remove ability to set up multivalued issuer for OIDC providers #54682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+300
−21
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...eycloak/connections/jpa/updater/liquibase/custom/JpaUpdate27_0_0_OidcIssuerMigration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /* | ||
| * Copyright 2026 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.connections.jpa.updater.liquibase.custom; | ||
|
|
||
| import java.sql.PreparedStatement; | ||
| import java.sql.ResultSet; | ||
|
|
||
| import org.keycloak.migration.migrators.OidcIssuerMigration; | ||
|
|
||
| import liquibase.exception.CustomChangeException; | ||
| import liquibase.statement.core.UpdateStatemen 8000 t; | ||
| import liquibase.structure.core.Table; | ||
| import org.jboss.logging.Logger; | ||
|
|
||
| public class JpaUpdate27_0_0_OidcIssuerMigration extends CustomKeycloakTask { | ||
|
|
||
| private static final Logger LOG = Logger.getLogger(JpaUpdate27_0_0_OidcIssuerMigration.class); | ||
|
|
||
| @Override | ||
| protected void generateStatementsImpl() throws CustomChangeException { | ||
| String sql = "SELECT p.INTERNAL_ID, p.PROVIDER_ID, p.PROVIDER_ALIAS, p.REALM_ID, c.VALUE FROM " | ||
| + getTableName("IDENTITY_PROVIDER") + " p JOIN " + getTableName("IDENTITY_PROVIDER_CONFIG") | ||
| + " c ON c.IDENTITY_PROVIDER_ID = p.INTERNAL_ID WHERE c.NAME = 'issuer' AND c.VALUE LIKE '%,%'"; | ||
| try (PreparedStatement ps = connection.prepareStatement(sql); ResultSet rs = ps.executeQuery()) { | ||
| while (rs.next()) { | ||
| String id = rs.getString(1); | ||
| String providerId = rs.getString(2); | ||
| String alias = rs.getString(3); | ||
| String realmId = rs.getString(4); | ||
| String issuers = rs.getString(5); | ||
| if (!OidcIssuerMigration.isMultiIssuerProvider(kcSession, providerId, issuers)) { | ||
| if (OidcIssuerMigration.getFactory(kcSession, providerId) == null) { | ||
| LOG.warnf("Identity provider '%s' in realm '%s' configures multiple issuers (%s), but its provider " | ||
| + "'%s' is not installed, so it cannot be migrated. If you install that provider later, " | ||
| + "replace the issuer list with a single issuer and configure a separate identity provider " | ||
| + "for each additional issuer.", alias, realmId, issuers, providerId); | ||
| } | ||
| continue; | ||
| } | ||
| String first = OidcIssuerMigration.firstIssuer(issuers); | ||
| if (first != null) { | ||
| statements.add(new UpdateStatement(null, null, database.correctObjectName("IDENTITY_PROVIDER_CONFIG", Table.class)) | ||
| .addNewColumnValue("VALUE", first) | ||
| .setWhereClause("IDENTITY_PROVIDER_ID=? AND NAME=?").addWhereParameter(id).addWhereParameter("issuer")); | ||
| LOG.warnf("Disabling identity provider '%s' in realm '%s' because it configured multiple issuers (%s). " | ||
| + "The same subject from different issuers could authenticate as the wrong user. Only the first issuer will be retained. " | ||
| + "Review existing federated links before enabling the provider. Configure a separate identity provider for each additional issuer; " | ||
| + "existing user links cannot be split automatically.", | ||
| alias, realmId, issuers); | ||
| } else { | ||
| LOG.warnf("Disabling identity provider '%s' in realm '%s' because its issuer value (%s) " | ||
| + "contains commas but no valid issuer. Correct the issuer before enabling the provider.", | ||
| alias, realmId, issuers); | ||
|
pedroigor marked this conversation as resolved.
Resolved
|
||
| } | ||
| statements.add(new UpdateStatement(null, null, database.correctObjectName("IDENTITY_PROVIDER", Table.class)) | ||
| .addNewColumnValue("ENABLED", false).setWhereClause("INTERNAL_ID=?").addWhereParameter(id)); | ||
| } | ||
| } catch (Exception e) { | ||
| throw new CustomChangeException(getTaskId() + ": Failed to migrate OIDC issuer lists", e); | ||
| } | ||
| confirmationMessage.append("Migrated OIDC issuer lists and disabled affected identity providers"); | ||
| } | ||
|
|
||
| @Override | ||
| protected String getTaskId() { | ||
| return "27.0.0-54458-oidc-single-issuer"; | ||
| } | ||
| } | ||
20 changes: 20 additions & 0 deletions
20
model/jpa/src/main/resources/META-INF/jpa-changelog-27.0.0.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,28 @@ | ||
| <?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
| <!-- | ||
| ~ Copyright 2026 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. | ||
| --> | ||
| <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd"> | ||
|
|
||
| <changeSet author="keycloak" id="27.0.0-43241-login-themes"> | ||
| <customChange class="org.keycloak.connections.jpa.updater.liquibase.custom.JpaUpdate27_0_0_LoginThemes"/> | ||
| </changeSet> | ||
|
|
||
| <changeSet author="keycloak" id="27.0.0-54458-oidc-single-issuer"> | ||
| <customChange class="org.keycloak.connections.jpa.updater.liquibase.custom.JpaUpdate27_0_0_OidcIssuerMigration"/> | ||
| </changeSet> | ||
|
|
||
| </databaseChangeLog> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...rivate/src/main/java/org/keycloak/broker/provider/SingleIssuerIdentityProviderConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /* | ||
| * Copyright 2026 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.broker.provider; | ||
|
|
||
| /** | ||
| * Identifies identity provider configurations that accept a single issuer. Config subclasses inherit | ||
| * this capability so migrations can discover affected providers through their factories. | ||
| */ | ||
| public interface SingleIssuerIdentityProviderConfig { | ||
| } |
107 changes: 107 additions & 0 deletions
107
server-spi-private/src/main/java/org/keycloak/migration/migrators/OidcIssuerMigration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| /* | ||
| * Copyright 2026 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.migration.migrators; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| import org.keycloak.broker.provider.IdentityProvider; | ||
| import org.keycloak.broker.provider.IdentityProviderFactory; | ||
| import org.keycloak.broker.provider.SingleIssuerIdentityProviderConfig; | ||
| import org.keycloak.broker.social.SocialIdentityProvider; | ||
| import org.keycloak.migration.ModelVersion; | ||
| import org.keycloak.models.IdentityProviderModel; | ||
| import org.keycloak.models.KeycloakSession; | ||
| import org.keycloak.representations.idm.RealmRepresentation; | ||
|
|
||
| import org.jboss.logging.Logger; | ||
|
|
||
| /** | ||
| * Migration of legacy issuer lists for providers with single-issuer configurations. Federated links do not record an issuer, | ||
| * so a migrated provider must be reviewed before it can safely be enabled again. | ||
| * <p> | ||
| * This intentionally does not implement {@link Migration} and is not registered in {@code DefaultMigrationManager}. | ||
| * Identity providers are validated eagerly while a realm representation is imported (see | ||
| * {@code OIDCIdentityProviderConfig#validate}), before the standard post-import {@code migrateImport} hooks ever run, | ||
| * so a multi-issuer configuration would fail validation before any registered migrator got a chance to fix it. | ||
| * Instead, {@link #migrateImport(KeycloakSession, RealmRepresentation)} is called directly against the representation | ||
| * before identity providers are created. | ||
| */ | ||
| public final class OidcIssuerMigration { | ||
|
|
||
| public static final ModelVersion VERSION = new ModelVersion("27.0.0"); | ||
| private static final Logger LOG = Logger.getLogger(OidcIssuerMigration.class); | ||
|
|
||
| private OidcIssuerMigration() { | ||
| } | ||
|
|
||
| /** | ||
| * Resolves the factory for the given provider id, or {@code null} when that provider is not installed. | ||
| */ | ||
| public static IdentityProviderFactory<?> getFactory(KeycloakSession session, String providerId) { | ||
| IdentityProviderFactory<?> factory = (IdentityProviderFactory<?>) session.getKeycloakSessionFactory() | ||
| .getProviderFactory(IdentityProvider.class, providerId); | ||
| if (factory == null) { | ||
| factory = (IdentityProviderFactory<?>) session.getKeycloakSessionFactory() | ||
| .getProviderFactory(SocialIdentityProvider.class, providerId); | ||
| } | ||
| return factory; | ||
| } | ||
|
|
||
| public static boolean isMultiIssuerProvider(KeycloakSession session, String providerId, String issuer) { | ||
| if (issuer == null || !issuer.contains(",")) { | ||
| return false; | ||
| } | ||
| IdentityProviderFactory<?> factory = getFactory(session, providerId); | ||
| return factory != null && factory.createConfig() instanceof SingleIssuerIdentityProviderConfig; | ||
| } | ||
|
|
||
| public static String firstIssuer(String issuers) { | ||
| return Arrays.stream(issuers.split(",")) | ||
| .map(String::trim) | ||
| .filter(s -> !s.isEmpty()) | ||
| .findFirst() | ||
| .orElse(null); | ||
| } | ||
|
|
||
| public static void migrateImport(KeycloakSession session, RealmRepresentation realm) { | ||
| if (realm.getIdentityProviders() == null) { | ||
| return; | ||
| } | ||
| realm.getIdentityProviders().forEach(idp -> { | ||
| if (idp.getConfig() == null) { | ||
| return; | ||
| } | ||
| String issuers = idp.getConfig().get(IdentityProviderModel.ISSUER); | ||
| if (isMultiIssuerProvider(session, idp.getProviderId(), issuers)) { | ||
| String first = firstIssuer(issuers); | ||
| if (first != null) { | ||
| idp.getConfig().put(IdentityProviderModel.ISSUER, first); | ||
| LOG.warnf("Disabled identity provider '%s' in imported realm '%s' because it configured multiple issuers (%s). " | ||
| + "The same subject from different issuers could authenticate as the wrong user. Only the first issuer was retained. " | ||
| + "Review existing federated links before enabling the provider. Configure a separate identity provider for each additional issuer; " | ||
| + "existing user links cannot be split automatically.", | ||
| idp.getAlias(), realm.getRealm(), issuers); | ||
| } else { | ||
|
pedroigor marked this conversation as resolved.
Resolved
|
||
| LOG.warnf("Disabled identity provider '%s' in imported realm '%s' because its issuer value (%s) " | ||
| + "contains commas but no valid issuer. Correct the issuer before enabling the provider.", | ||
| idp.getAlias(), realm.getRealm(), issuers); | ||
| } | ||
| idp.setEnabled(false); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.