When API is configured for workflow, only a set of users(users with admin role) can manage the tasks. But there can be use cases to manage some tasks by different user types or roles. As an example, if multiple departments manage APIs in a single tenant and workflow need to be managed within that department. In such cases, each workflow task only needs to be visible to admin users of that logical department.
By default, this cannot be achieved without customization. Hence this document explains how to achieve subscription management in such a deployment. So the following tasks are discussed in this document.
Workflow executor needs to be customized to send additional information to the Business process engine. This customization is done to include role information to the web service call to the BPS. By default, the required role of the users, which use to limit access and manage pending tasks, is set to “admin” at the BPS engine. If we can include the admin role of the current department that can be used to limit workflow management at BPS.
The following code includes this information to the web service call. We include “deptAdminRole” property to hold the admin role name. In this sample, we have a hardcoded role name as “hr_admin_role” assuming it is the admin role for the HR department. But these value can be derived as follows
<dependency> <groupId>org.wso2.carbon.apimgt</groupId> <artifactId>org.wso2.carbon.apimgt.impl</artifactId> <version>6.5.349</version> </dependency>
public WorkflowResponse execute(WorkflowDTO workflowDTO) throws WorkflowException { try { String action = WorkflowConstants.CREATE_SUBSCRIPTION_WS_ACTION; ServiceClient client = getClient(action); String payload = "<wor:SubscriptionApprovalWorkFlowProcessRequest " + " xmlns:wor=\"http://workflow.subscription.apimgt.carbon.wso2.org\">\n" + " <wor:apiName>$1</wor:apiName>\n" + " <wor:apiVersion>$2</wor:apiVersion>\n" + " <wor:apiContext>$3</wor:apiContext>\n" + " <wor:apiProvider>$4</wor:apiProvider>\n" + " <wor:subscriber>$5</wor:subscriber>\n" + " <wor:applicationName>$6</wor:applicationName>\n" + " <wor:tierName>$7</wor:tierName>\n" + " <wor:workflowExternalRef>$8</wor:workflowExternalRef>\n" + " <wor:callBackURL>$9</wor:callBackURL>\n" + " <wor:deptAdminRole>$deptAdminRole</wor:deptAdminRole>\n" + " </wor:SubscriptionApprovalWorkFlowProcessRequest>"; SubscriptionWorkflowDTO subsWorkflowDTO = (SubscriptionWorkflowDTO) workflowDTO; String callBackURL = subsWorkflowDTO.getCallbackUrl(); payload = payload.replace("$1", subsWorkflowDTO.getApiName()); payload = payload.replace("$2", subsWorkflowDTO.getApiVersion()); payload = payload.replace("$3", subsWorkflowDTO.getApiContext()); payload = payload.replace("$4", subsWorkflowDTO.getApiProvider()); payload = payload.replace("$5", subsWorkflowDTO.getSubscriber()); payload = payload.replace("$6", subsWorkflowDTO.getApplicationName()); payload = payload.replace("$7", subsWorkflowDTO.getTierName()); payload = payload.replace("$8", subsWorkflowDTO.getExternalWorkflowReference()); payload = payload.replace("$9", callBackURL != null ? callBackURL : "?"); payload = payload.replace("$deptAdminRole", "hr_admin_role"); client.fireAndForget(AXIOMUtil.stringToOM(payload)); ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance(); apiMgtDAO.addWorkflowEntry(workflowDTO); publishEvents(workflowDTO); } catch (AxisFault axisFault) { log.error("Error sending out message", axisFault); throw new WorkflowException("Error sending out message", axisFault); } catch (XMLStreamException e) { log.error("Error converting String to OMElement", e); throw new WorkflowException("Error converting String to OMElement", e); } catch (APIManagementException e) { throw new WorkflowException("Error while persisting workflow", e); } return new GeneralWorkflowResponse(); }
<bpel:literal> <tschema:SubscriptionApprovalData xmlns:tschema="http://workflow.subscription.apimgt.carbon.wso2.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><tschema:apiName>tschema:apiName</tschema:apiName> <tschema:apiVersion>tschema:apiVersion</tschema:apiVersion> <tschema:apiContext>tschema:apiContext</tschema:apiContext> <tschema:apiProvider>tschema:apiProvider</tschema:apiProvider> <tschema:subscriber>tschema:subscriber</tschema:subscriber> <tschema:applicationName>tschema:applicationName</tschema:applicationName> <tschema:tierName>tschema:tierName</tschema:tierName> <tschema:callBackURL>tschema:callBackURL</tschema:callBackURL> <tschema:workflowExternalRef>tschema:workflowExternalRef</tschema:workflowExternalRef> <tschema:deptAdminRole>tschema:deptAdminRole</tschema:deptAdminRole> </tschema:SubscriptionApprovalData> </bpel:literal>
<htd:peopleAssignments> <htd:potentialOwners> <htd:from logicalPeopleGroup="admin"> <htd:argument name="role"> htd:getInput("SubscriptionApprovalRequest")/test10:deptAdminRole </htd:argument> </htd:from> </htd:potentialOwners> </htd:peopleAssignments>
<SubscriptionCreation executor="com.rukspot.sample.apimgt.workflow.rolebase.RoleBasedSubscriptionCreationWSWorkflowExecutor"> <Property name="serviceEndpoint">http://localhost:9765/services/SubscriptionApprovalWorkFlowProcess/</Property> <Property name="username">admin</Property> <Property name="password">admin</Property> <Property name="callbackURL">https://localhost:8243/services/WorkflowCallbackService</Property> </SubscriptionCreation>
Please find the sample code from GitHub
Add Comment
Comments (0)