func()

in pkg/client/keycloak/adapter/gocloak_adapter_auth_flow.go [582:618]


func (a GoCloakAdapter) adjustFlowExecutionPriority(
	realmName,
	flowAlias string,
	flowExec *FlowExecution,
	flowExecsCount int,
	childFlows map[string]AuthenticationExecution,
) error {
	if !flowExec.AuthenticationFlow || flowExec.Level != 0 {
		return nil
	}

	childFlow, ok := childFlows[flowExec.DisplayName]
	if !ok {
		return errors.Errorf("unable to find child flow with name: %s", flowExec.DisplayName)
	}

	if childFlow.Requirement != flowExec.Requirement {
		flowExec.Requirement = childFlow.Requirement
		if err := a.updateFlowExecution(realmName, flowAlias, flowExec); err != nil {
			return errors.Wrap(err, "unable to update flow execution")
		}
	}

	if childFlow.Priority == flowExec.Index {
		return nil
	}

	if childFlow.Priority < 0 || childFlow.Priority > flowExecsCount {
		return errors.Errorf("wrong flow priority, flow name: %s, priority: %d", childFlow.Alias, childFlow.Priority)
	}

	if err := a.adjustExecutionPriority(realmName, flowExec.ID, flowExec.Index-childFlow.Priority); err != nil {
		return errors.Wrap(err, "unable to adjust flow priority")
	}

	return nil
}