diff --git a/services/src/main/java/org/keycloak/services/resources/admin/AuthenticationManagementResource.java b/services/src/main/java/org/keycloak/services/resources/admin/AuthenticationManagementResource.java index ede2e278a7..4b523a16c9 100755 --- a/services/src/main/java/org/keycloak/services/resources/admin/AuthenticationManagementResource.java +++ b/services/src/main/java/org/keycloak/services/resources/admin/AuthenticationManagementResource.java @@ -323,6 +323,14 @@ public class AuthenticationManagementResource { if (flow.isBuiltIn()) { throw new BadRequestException("Can't delete built in flow"); } + List executions = realm.getAuthenticationExecutions(id); + for (AuthenticationExecutionModel execution : executions) { + if(execution.getFlowId() != null) { + AuthenticationFlowModel nonTopLevelFlow = realm.getAuthenticationFlowById(execution.getFlowId()); + realm.removeAuthenticationFlow(nonTopLevelFlow); + } + realm.removeAuthenticatorExecution(execution); + } realm.removeAuthenticationFlow(flow); }