Customizing a user signup workflow in WSO2 API Manager

You can follow the steps provided in the Adding a User Signup Workflow [1] for the simple steps in adding a User Signup Workflow.

Here I am going to talk about customizing the workflow to send more user claim values to the Business Process and Human Task.

You can get the sample custom signup workflow from custom-workflow-executor [2].

In the sample project I have created, the sample payload looks like below

public static final String REGISTER_USER_PAYLOAD_CUSTOM =
" <wor:UserSignupProcessRequest xmlns:wor=\"http://workflow.registeruser.apimgt.carbon.wso2.org\">\n" +
" <wor:userName>$1</wor:userName>\n" +
" <wor:tenantDomain>$2</wor:tenantDomain>\n" +
" <wor:workflowExternalRef>$3</wor:workflowExternalRef>\n" +
" <wor:callBackURL>$4</wor:callBackURL>\n" +
" <wor:organization>$5</wor:organization>\n" +
" <wor:country>$6</wor:country>\n" +
" </wor:UserSignupProcessRequest>";

The code below shows how I am getting the user claim values via realm service and setting it to the payload.

String payload = REGISTER_USER_PAYLOAD_CUSTOM;
//getting the user store manager
RealmService realmService = ServiceReferenceHolder.getInstance().getRealmService();
UserRealm realm = realmService.getBootstrapRealm();
UserStoreManager manager = realm.getUserStoreManager();

//getting the user claim value
String organization = manager.getUserClaimValue(tenantAwareUserName, "http://wso2.org/claims/organization", null);
String country = manager.getUserClaimValue(tenantAwareUserName, "http://wso2.org/claims/country", null);
payload = payload.replace("$5", organization);
payload = payload.replace("$6", country);

You can modify the payload in CustomUserSignUpWSWorkflowExecutor class as per your requirement. Currently in the sample, I have added organization and country to the payload.

After you modify the project, build it and copy the “custom-usersignup-workflow-executor-1.0.0.jar” jar found at “workflow-executor/target” and place it at “<APIM_HOME>/repository/components/dropins”. Note: This requires a server restart.

Log in to APIM management console (https://<Server Host>:9443/carbon) and select Browse under Resources.

Go to /_system/governance/apimgt/applicationdata/workflow-extensions.xml resource, disable the Simple Workflow Executor and disable WS Workflow Executor. Then add the following UserSignUp executor for your custom signup workflow executor.

<WorkFlowExtensions>
...
<UserSignUp executor="org.wso2.sample.workflow.executor.CustomUserSignUpWSWorkflowExecutor">
<Property name="serviceEndpoint">http://localhost:9765/services/UserSignupProcess/</Property>
<Property name="username">admin</Property>
<Property name="password">admin</Property>
<Property name="callbackURL">https://localhost:8243/services/WorkflowCallbackService</Property>
</UserSignUp>
...
</WorkFlowExtensions>

Changes to the Business Process

You can find the modified Business Process to cater the sample from the following locations

Added the following in the UserApprovalTask.ht

<htd:presentationParameters>

<htd:presentationParameter name="organization" type="xsd:string">
htd:getInput("UserApprovalRequest")/test10:organization
</htd:presentationParameter>
<htd:presentationParameter name="country" type="xsd:string">
htd:getInput("UserApprovalRequest")/test10:country
</htd:presentationParameter>
...
</htd:presentationParameters>
<htd:subject xml:lang="en-US">
Subject: Approve APIStore signup request done by $userName$ from the tenant domain $tenantDomain$
</htd:subject>
<htd:description xml:lang="en-US" contentType="text/plain">
Description: Hi Admin, please approve APIStore signup request done by $userName$ from the tenant domain $tenantDomain$, organization: $organization$, country: $country$
</htd:description>

Added the following in the UserApprovalTash.wsdl

<xsd:complexType name="UserApprovalDataType">
<xsd:sequence>
<xsd:complexType>

<xsd:element name="organization" type="xsd:string" />
<xsd:element name="country" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>

Added the following in the UserSignupProcess.bpel

<bpel:copy>
<bpel:from>
<bpel:literal>
<tns1:UserApprovalData xmlns:tns1="http://workflow.registeruser.apimgt.carbon.wso2.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
...
<tns1:organization>tns1:organization</tns1:organization>
<tns1:country>tns1:country</tns1:country>
</tns1:UserApprovalData>
</bpel:literal>
</bpel:from>
<bpel:to variable="ht_input" part="UserApprovalRequest"></bpel:to>
</bpel:copy>
...
<bpel:assign validate="no" name="AssignInputs">

<bpel:copy>
<bpel:from part="payload" variable="input">
<bpel:query queryLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath1.0"><![CDATA[tns:organization]]></bpel:query>
</bpel:from>
<bpel:to part="UserApprovalRequest" variable="ht_input">
<bpel:query queryLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath1.0"><![CDATA[tns:organization]]></bpel:query>
</bpel:to>
</bpel:copy>

<bpel:copy>
<bpel:from part="payload" variable="input">
<bpel:query queryLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath1.0"><![CDATA[tns:country]]></bpel:query>
</bpel:from>
<bpel:to part="UserApprovalRequest" variable="ht_input">
<bpel:query queryLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath1.0"><![CDATA[tns:country]]></bpel:query>
</bpel:to>
</bpel:copy>
</bpel:assign>

Added the following in the UserSignupProcessArtifacts.wsdl

<element name="UserSignupProcessRequest">
<complexType>
<sequence>
...
<element name="organization" type="string"/>
<element name="country" type="string"/>
</sequence>
</complexType>
</element>

With that idea, you can modify the BPEL and HumanTask according to your user claim values.

You can check out my blog [3] which says how to add new fields to the user signup page in wso2 api manager store.

Once you have the steps in [3] configured.

When you sign-up in the API Manager Store

You will be notified with the Approval Process with the following message

When you login to the admin portal (https://<server_ip>:9443/admin), you will see the customized message set at the human task as shown below.

[1] — https://docs.wso2.com/display/AM200/Adding+a+User+Signup+Workflow

[2] — https://github.com/Vishanth/custom-workflow-executor

[3] — https://medium.com/@vishanth/how-to-add-new-fields-to-user-signup-page-in-wso2-api-manager-store-666d4c6c7aeb