Repository navigation
Preserve workflow definitions in realm export and import #53486
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| * Copyright 2026 the original author or authors. | ||
| * | ||
| * 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.models.workflow; | ||
|
|
||
| import org.keycloak.common.util.Time; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| public class ScheduledWorkflowRunnerTest { | ||
|
|
||
| @Test | ||
| public void testWithoutPreviousRun() { | ||
| assertEquals(Integer.MAX_VALUE, ScheduledWorkflowRunner.computeInitialDelay(0, Integer.MAX_VALUE)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMaximumInterval() { | ||
| assertDelay(Time.currentTime(), Integer.MAX_VALUE); | ||
| } | ||
|
|
||
| @Test | ||
| public void testPreviousRunAheadOfLocalClock() { | ||
| assertDelay(Time.currentTime() + 60, Integer.MAX_VALUE); | ||
| } | ||
|
|
||
| @Test | ||
| public void testOverdueRun() { | ||
| assertDelay(Time.currentTime() - 120, 60); | ||
| } | ||
|
|
||
| @Test | ||
| public void testOrdinaryInterval() { | ||
| assertDelay(Time.currentTime() - 10, 60); | ||
| } | ||
|
|
||
| private static void assertDelay(int lastRun, int interval) { | ||
| int before = Time.currentTime(); | ||
| long delay = ScheduledWorkflowRunner.computeInitialDelay(lastRun, interval); | ||
| int after = Time.currentTime(); | ||
| long nextRun = (long) lastRun + interval; | ||
| assertTrue("Delay must not be shortened by overflow", delay >= Math.max(0L, nextRun - after)); | ||
| assertTrue("Delay must not exceed the remaining interval", delay <= Math.max(0L, nextRun - before)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,7 @@ | |
| import org.keycloak.models.RoleModel; | ||
| import org.keycloak.models.UserModel; | ||
| import org.keycloak.models.utils.ModelToRepresentation; | ||
| import org.keycloak.models.workflow.WorkflowProvider; | ||
| import org.keycloak.organization.OrganizationProvider; | ||
| import org.keycloak.representations.idm.ClientRepresentation; | ||
| import org.keycloak.representations.idm.ComponentExportRepresentation; | ||
|
|
@@ -254,8 +255,20 @@ public static RealmRepresentation exportRealm(KeycloakSession session, RealmMode | |
|
|
||
| // components | ||
| MultivaluedHashMap<String, ComponentExportRepresentation> components = exportComponents(realm, realm.getId()); | ||
| boolean keepLegacyComponents = !Profile.isFeatureEnabled(Feature.WORKFLOWS) | ||
| && !options.isPartial() && options.isWorkflowsIncluded(); | ||
| if (!keepLegacyComponents) { | ||
| components.remove(WorkflowProvider.class.getName()); | ||
| } | ||
| rep.setComponents(components); | ||
|
|
||
| if (options.isWorkflowsIncluded() && Profile.isFeatureEnabled(Feature.WORKFLOWS)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor. This sets the field unconditionally, and the mapper uses Neighbouring collections guard on emptiness ( |
||
| var workflows = WorkflowExportImportUtils.exportWorkflows(session, realm); | ||
| if (!workflows.isEmpty()) { | ||
| rep.setWorkflows(workflows); | ||
| } | ||
| } | ||
|
|
||
| // Message Bundle | ||
| rep.setLocalizationTexts(realm.getRealmLocalizationTexts()); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section is good, but I think the change also needs an entry in
docs/documentation/upgrading, because it is visible to anyone with existing tooling:workflowsarray;org.keycloak.models.workflow.WorkflowProviderno longer appears undercomponents;WorkflowExportImportUtils.fromComponent).