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 ede2e27..4b523a1 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<AuthenticationExecutionModel> 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);
}