Repository navigation
Add Provisioning dispatch executor #1159
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
Open
Mahima-Sanketh-Git
wants to merge
11
commits into
wso2-extensions:master
Choose a base branch
from
Mahima-Sanketh-Git:provisioning-dispatch-executor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b6074c7
Add Provisioning dispatch executor
Mahima-Sanketh-Git 4ff4705
Fix flow executor removal during unbind
Mahima-Sanketh-Git 6f9f59a
Fix check style
Mahima-Sanketh-Git 0484db3
Provision the user only once across retries
Mahima-Sanketh-Git 520cd07
Handle a null response from a dispatched executor
Mahima-Sanketh-Git 980bd3c
Support provisioning the user inside the new organization, with rollback
Mahima-Sanketh-Git 538baf4
Merge remote-tracking branch 'upstream/master' into provisioning-disp…
Mahima-Sanketh-Git 50abf3c
Merge tag 'v1.16.41' into provisioning-dispatch-executor
Mahima-Sanketh-Git 9f06936
Merge remote-tracking branch 'upstream/master' into provisioning-disp…
Mahima-Sanketh-Git 4b7948f
Invoke organization role assignment after successful provisioning
Mahima-Sanketh-Git 544b679
Simplify provisioning dispatcher comments
Mahima-Sanketh-Git File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
134 changes: 134 additions & 0 deletions
134
...rc/main/java/org/wso2/carbon/identity/recovery/executor/ProvisioningDispatchExecutor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| /* | ||
| * Copyright (c) 2026, WSO2 LLC. (https://www.wso2.com). | ||
| * | ||
| * WSO2 LLC. licenses this file to you 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.wso2.carbon.identity.recovery.executor; | ||
|
|
||
| import org.apache.commons.logging.Log; | ||
| import org.apache.commons.logging.LogFactory; | ||
| import org.wso2.carbon.identity.flow.execution.engine.exception.FlowEngineException; | ||
| import org.wso2.carbon.identity.flow.execution.engine.graph.Executor; | ||
| import org.wso2.carbon.identity.flow.execution.engine.model.ExecutorResponse; | ||
| import org.wso2.carbon.identity.flow.execution.engine.model.FlowExecutionContext; | ||
| import org.wso2.carbon.identity.recovery.internal.IdentityRecoveryServiceDataHolder; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| import static org.wso2.carbon.identity.flow.execution.engine.Constants.ExecutorStatus.STATUS_COMPLETE; | ||
| import static org.wso2.carbon.identity.flow.execution.engine.Constants.ExecutorStatus.STATUS_ERROR; | ||
|
|
||
| /** | ||
| * Flow executor that provisions a user and then the organization the flow collected, in that order. | ||
| * <p> | ||
| * The flow builder decides whether this executor is needed: it names this executor on the END step when | ||
| * the flow collects organization details, and {@code UserProvisioningExecutor} when it does not. So by | ||
| * the time this runs the decision is already made, and it dispatches to both unconditionally rather than | ||
| * classifying the flow itself. | ||
| * <p> | ||
| * Ordering matters. {@code OrganizationProvisioningExecutor} requires a provisioned user, because the | ||
| * creating user becomes the organization owner. Running user provisioning first leaves the user ID on | ||
| * the flow user, which the organization executor then reads from the same context. | ||
| * <p> | ||
| * The executors are resolved by name from executors contributed across all bundles, so this component | ||
| * does not depend on the one that owns the organization executor. | ||
| */ | ||
| public class ProvisioningDispatchExecutor implements Executor { | ||
|
|
||
| private static final Log LOG = LogFactory.getLog(ProvisioningDispatchExecutor.class); | ||
|
|
||
| private static final String EXECUTOR_NAME = "ProvisioningDispatchExecutor"; | ||
| private static final String USER_PROVISIONING_EXECUTOR = "UserProvisioningExecutor"; | ||
| private static final String ORGANIZATION_PROVISIONING_EXECUTOR = "OrganizationProvisioningExecutor"; | ||
|
|
||
| @Override | ||
| public String getName() { | ||
|
|
||
| return EXECUTOR_NAME; | ||
| } | ||
|
|
||
| @Override | ||
| public ExecutorResponse execute(FlowExecutionContext context) throws FlowEngineException { | ||
|
|
||
| ExecutorResponse userResponse = dispatch(USER_PROVISIONING_EXECUTOR, context); | ||
| if (userResponse == null) { | ||
| return unavailableExecutorResponse(USER_PROVISIONING_EXECUTOR); | ||
| } | ||
| // Anything other than completion is the user provisioning step's own outcome to report: it may | ||
| // need more input, or it may have failed. The organization must not be created either way. | ||
| if (!STATUS_COMPLETE.equals(userResponse.getResult())) { | ||
| return userResponse; | ||
| } | ||
|
|
||
| ExecutorResponse organizationResponse = dispatch(ORGANIZATION_PROVISIONING_EXECUTOR, context); | ||
| if (organizationResponse == null) { | ||
| return unavailableExecutorResponse(ORGANIZATION_PROVISIONING_EXECUTOR); | ||
| } | ||
| return organizationResponse; | ||
| } | ||
|
|
||
| /** | ||
| * Resolves an executor by name and runs it against the same flow context. | ||
| * | ||
| * @param executorName Name the executor is registered under. | ||
| * @param context Flow execution context, shared by both executors. | ||
| * @return The executor's response, or {@code null} if no executor is registered under that name. | ||
| * @throws FlowEngineException If the executor fails. | ||
| */ | ||
| private ExecutorResponse dispatch(String executorName, FlowExecutionContext context) | ||
| throws FlowEngineException { | ||
|
|
||
| Executor executor = IdentityRecoveryServiceDataHolder.getInstance().getFlowExecutor(executorName); | ||
| if (executor == null) { | ||
| return null; | ||
| } | ||
| if (LOG.isDebugEnabled()) { | ||
| LOG.debug("Dispatching to executor: " + executorName + " for flow: " | ||
| + context.getContextIdentifier()); | ||
| } | ||
| return executor.execute(context); | ||
| } | ||
|
|
||
| /** | ||
| * Builds the response for a flow that names this executor while one of the executors it dispatches | ||
| * to is not deployed. The end user cannot resolve this by retrying. | ||
| * | ||
| * @param executorName Name of the executor that could not be resolved. | ||
| * @return An error response. | ||
| */ | ||
| private ExecutorResponse unavailableExecutorResponse(String executorName) { | ||
|
|
||
| LOG.error("Executor not found: " + executorName + ". The provisioning dispatch executor requires " | ||
| + "both the user and organization provisioning executors to be deployed."); | ||
| ExecutorResponse response = new ExecutorResponse(); | ||
| response.setResult(STATUS_ERROR); | ||
| response.setErrorMessage("Provisioning is not available."); | ||
| return response; | ||
| } | ||
|
|
||
| @Override | ||
| public List<String> getInitiationData() { | ||
|
|
||
| return Collections.emptyList(); | ||
| } | ||
|
|
||
| @Override | ||
| public ExecutorResponse rollback(FlowExecutionContext context) throws FlowEngineException { | ||
|
|
||
| return null; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.