diff --git a/components/flow-orchestration-framework/org.wso2.carbon.identity.flow.execution.engine/src/main/java/org/wso2/carbon/identity/flow/execution/engine/FlowExecutionService.java b/components/flow-orchestration-framework/org.wso2.carbon.identity.flow.execution.engine/src/main/java/org/wso2/carbon/identity/flow/execution/engine/FlowExecutionService.java index 3cf7c62bd792..bedf8061a9be 100644 --- a/components/flow-orchestration-framework/org.wso2.carbon.identity.flow.execution.engine/src/main/java/org/wso2/carbon/identity/flow/execution/engine/FlowExecutionService.java +++ b/components/flow-orchestration-framework/org.wso2.carbon.identity.flow.execution.engine/src/main/java/org/wso2/carbon/identity/flow/execution/engine/FlowExecutionService.java @@ -116,8 +116,6 @@ public FlowExecutionStep executeFlow(String tenantDomain, String applicationId, } } - isFlowEnteredInIdentityContext = enterFlowInIdentityContext(context.getFlowType()); - if (inputs != null) { context.getUserInputData().putAll(inputs); } @@ -131,6 +129,8 @@ public FlowExecutionStep executeFlow(String tenantDomain, String applicationId, context.getUserInputData().remove(ANONYMOUS_PROFILE_TRACKER)); } + isFlowEnteredInIdentityContext = enterFlowInIdentityContext(context); + context.setCurrentActionId(actionId); for (FlowExecutionListener listener : FlowExecutionEngineDataHolder.getInstance().getFlowListeners()) { @@ -182,8 +182,9 @@ public FlowExecutionStep executeFlow(String tenantDomain, String applicationId, } } - private boolean enterFlowInIdentityContext(String flowType) { + private boolean enterFlowInIdentityContext(FlowExecutionContext context) { + String flowType = context.getFlowType(); if (!EnumUtils.isValidEnum(FlowTypes.class, flowType)) { LOG.warn("Invalid flow type: " + flowType + " provided. Hence not entering the flow in IdentityContext."); return false; @@ -194,6 +195,7 @@ private boolean enterFlowInIdentityContext(String flowType) { IdentityContext.getThreadLocalIdentityContext().enterFlow(new Flow.Builder() .name(Flow.Name.REGISTER) .initiatingPersona(Flow.InitiatingPersona.USER) + .anonymousProfileTracker((String) context.getProperty(ANONYMOUS_PROFILE_TRACKER)) .build()); return true; case PASSWORD_RECOVERY: diff --git a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/context/model/Flow.java b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/context/model/Flow.java index 6f8547be2989..e7b3d0f1f3f9 100644 --- a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/context/model/Flow.java +++ b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/context/model/Flow.java @@ -211,11 +211,13 @@ public enum CredentialType { private final Name name; private final InitiatingPersona initiatingPersona; private CredentialType credentialType; + private String anonymousProfileTracker; private Flow(Builder builder) { this.name = builder.name; this.initiatingPersona = builder.initiatingPersona; + this.anonymousProfileTracker = builder.anonymousProfileTracker; } private Flow(CredentialFlowBuilder builder) { @@ -240,6 +242,18 @@ public CredentialType getCredentialType() { return credentialType; } + /** + * Returns the anonymous profile tracker identifier associated with the flow, if any. + * This is used to correlate an anonymous, pre-authentication profile (e.g. for external profile linking) + * with the user created/updated as a result of this flow. + * + * @return The anonymous profile tracker identifier, or null if not applicable. + */ + public String getAnonymousProfileTracker() { + + return anonymousProfileTracker; + } + /** * Checks if the given flow name corresponds to a credential flow. * @@ -258,6 +272,7 @@ public static class Builder { private Name name; private InitiatingPersona initiatingPersona; + private String anonymousProfileTracker; public Builder name(Name name) { @@ -271,6 +286,12 @@ public Builder initiatingPersona(InitiatingPersona initiatingPersona) { return this; } + public Builder anonymousProfileTracker(String anonymousProfileTracker) { + + this.anonymousProfileTracker = anonymousProfileTracker; + return this; + } + public Flow build() { validate();