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 e737a25fb4..e18813946a 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 @@ -1073,7 +1073,11 @@ public class RealmAdapter implements RealmModel, JpaModel { public void addIdentityProvider(IdentityProviderModel identityProvider) { IdentityProviderEntity entity = new IdentityProviderEntity(); - entity.setInternalId(KeycloakModelUtils.generateId()); + if (identityProvider.getInternalId() == null) { + entity.setInternalId(KeycloakModelUtils.generateId()); + } else { + entity.setInternalId(identityProvider.getInternalId()); + } entity.setAlias(identityProvider.getAlias()); entity.setDisplayName(identityProvider.getDisplayName()); entity.setProviderId(identityProvider.getProviderId()); diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/servlet/AbstractBrokerLinkAndTokenExchangeTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/servlet/AbstractBrokerLinkAndTokenExchangeTest.java index 9bc951944d..909968fcc2 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/servlet/AbstractBrokerLinkAndTokenExchangeTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/servlet/AbstractBrokerLinkAndTokenExchangeTest.java @@ -29,6 +29,8 @@ import org.keycloak.admin.client.resource.RealmResource; import org.keycloak.authorization.model.Policy; import org.keycloak.authorization.model.ResourceServer; import org.keycloak.broker.oidc.OIDCIdentityProviderConfig; +import org.keycloak.exportimport.ExportImportConfig; +import org.keycloak.exportimport.singlefile.SingleFileExportProviderFactory; import org.keycloak.jose.jws.JWSInput; import org.keycloak.models.ClientModel; import org.keycloak.models.Constants; @@ -68,6 +70,7 @@ import javax.ws.rs.core.Form; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; +import java.io.File; import java.net.URL; import java.util.LinkedList; import java.util.List; @@ -448,6 +451,37 @@ public abstract class AbstractBrokerLinkAndTokenExchangeTest extends AbstractSer Assert.assertTrue(links.isEmpty()); } + + /** + * KEYCLOAK-6026 + * + * @throws Exception + */ + @Test + public void testExportImport() throws Exception { + testExternalExchange(); + testingClient.testing().exportImport().setProvider(SingleFileExportProviderFactory.PROVIDER_ID); + String targetFilePath = testingClient.testing().exportImport().getExportImportTestDirectory() + File.separator + "singleFile-full.json"; + //System.out.println("TARGET PATH: " + targetFilePath); + testingClient.testing().exportImport().setFile(targetFilePath); + testingClient.testing().exportImport().setAction(ExportImportConfig.ACTION_EXPORT); + testingClient.testing().exportImport().setRealmName(CHILD_IDP); + testingClient.testing().exportImport().runExport(); + + adminClient.realms().realm(CHILD_IDP).remove(); + testingClient.testing().exportImport().setAction(ExportImportConfig.ACTION_IMPORT); + + testingClient.testing().exportImport().runImport(); + //System.out.println("************* AFTER IMPORT"); + testExternalExchange(); + //Thread.sleep(1000000000l); + + + + } + + + @Test public void testExternalExchange() throws Exception {