Web Services Before Operation Rule

The Before Operation Rule is used to calculate attributes before a web service operation call. This rule is used by the Web Services Connector before performing any operation such as Test Connection, Aggregation, and so on.

Input Objects

The following table lists the input Objects for WebServiceBeforeOperationRule:

Objects

Type

Description

application

sailpoint.object.Application

The application whose data file is being processed.

requestEndPoint

sailpoint.connector.webservices.EndPoint

Current request information. It contains the header, body, context URL, method type, response attribute map, successful response code.

oldResponseMap

java.util.Map

The response object returned from earlier endpoint configuration of same operation type like Account Aggregation, Get Object, etc.

restClient

sailpoint.connector.webservices.WebServicesClient

This is a Web Services Client (HTTP Client) object that enables you to call the Web Services API target system.

provisioningPlan

sailpoint.object.ProvisioningPlan

Used to update the payload of the HTTP request. Provisioning plan has an account request which defines the operation to be performed on the account. An account request can contain multiple attributes requests and each attribute request represents an operation on a single account attribute. This argument enables the user to update the body/payload or URL attributes of endpoint object using the provisioningPlan information.

Return Objects

The Web Service Before Operation Rule uses the following return objects:

sailpoint.connector.webservices.EndPoint

sailpoint.connector.webservices.Map

The rule allows user to return the endpoint object (requestEndPoint) or a map. The map can hold updatedEndPoint and connectorStateMap keys where the value expected is Endpoint (requestEndPoint) and connectorStateMap objects respectively. The connectorStateMap object is a map that contains key and value of the attribute that must be updated in the application through the Before Operation Rule.

Examples of the Before Operation Rule

The following is an example which displays the rule used by the Web Services Connector before performing any operation such as Test Connection, Aggregation, and so on.

Copy
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Rule name="Example Rule" type="WebServiceBeforeOperationRule">
    <Description>
        This rule is used by the  Web Services connector before performing any operation like testconnection, aggregation etc.
    </Description>
    <Source><![CDATA[
        import com.google.gson.Gson;
        import sailpoint.tools.Util;
        Map obj = (Map) application.getAttributeValue("transientValues");
        if(null != obj) {
            String cursor = obj.get("cursor");
            if(Util.isNotNullOrEmpty(cursor)) {
                Map postBodyMap = (Map) requestEndPoint.getBody();
                postBodyMap.put("jsonBody", "{\"cursor\":\"" + cursor + "\"}");
                requestEndPoint.setFullUrl(requestEndPoint.getFullUrl() + "/continue");
            }
        }
        return requestEndPoint;
        
    ]]></Source>
</Rule>

The following example is for the provisioningPlan rule:

Copy
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import connector.common.JsonUtil;
import connector.common.Util;
import sailpoint.connector.webservices.EndPoint;
import sailpoint.connector.webservices.WebServicesClient;
import sailpoint.object.Application;
import sailpoint.object.ProvisioningPlan;
import sailpoint.object.ProvisioningPlan.AccountRequest;              
                
    Map body = requestEndPoint.getBody();
    String jsonBody = (String) body.get("jsonBody");
    log.info("Rule - Modify Body: running");

    try {

        Map jsonMap = JsonUtil.toMap(jsonBody);
        if (jsonMap != null) {
            Object roleEntry = jsonMap.get("webSiteAndRole");
            String role = "";
            if (roleEntry != null && roleEntry instanceof ArrayList) {
                ArrayList rolesArray = (ArrayList) roleEntry;
                if (rolesArray.size() > 0) {
                    role = (String) rolesArray.get(0);
                }
            } else if (roleEntry != null) {
                role = (String) roleEntry;
            }

            jsonMap.remove("webSiteAndRole");
            jsonMap.put("webSiteAndRole", role);

            log.info("Rule - Modify Body: setting webSiteAndRole = " + role);
            String webID = "";
            if (provisioningPlan != null) {
                log.info("Rule - Modify Body: plan is not null");
                for (AccountRequest accReq : Util.iterate(provisioningPlan.getAccountRequests())) {
                    log.info("Rule - Modify Body: iterating over account requests");
                    for (ProvisioningPlan.AttributeRequest attReq : Util.iterate(accReq.getAttributeRequests())) {
                        log.info("Rule - Modify Body: iterating over attribute requests");
                        String attrName = attReq.getName();
                        String value = null;
                        if (attrName != null && "webId".equalsIgnoreCase(attrName)) {
                            webID = (String) attReq.getValue();
                            log.info("Rule - Modify Body: setting webID = " + webID);
                    }
                }
            }
        } else {
            log.info("Rule - Modify Body: plan is null");
        }

        if (!"".equals(webID)) {
            jsonMap.put("webID", webID);
        }

// Add in any other missing fields
        if (!jsonMap.containsKey("webLogonEmail")) {
            jsonMap.put("webLogonEmail", "");
        }
        
        if (!jsonMap.containsKey("taxID")) {
            jsonMap.put("taxID", "");
        }

        if (!jsonMap.containsKey("taxIdType")) {
            jsonMap.put("taxIdType", "");
        }
        
        if (!jsonMap.containsKey("actorLogonId")) {
            jsonMap.put("actorLogonId", "");
        }

        String finalBody = JsonUtil.render(jsonMap);
        body.put("jsonBody", finalBody);
        requestEndPoint.setBody(body);
    }
} catch (Exception ex) {
    log.error("Rule - Modify Body: " + ex);
}

return requestEndPoint;​

The following is an example of Web Services Connector executing the Before Operation Rule on a target system API:

Copy
import connector.common.JsonUtil;
import sailpoint.connector.webservices.WebServicesClient;
    try {
        WebServicesClient client = new WebServicesClient();
        String url = "http://hostname:portnumber/RestFormDataWS/beforeRuleMock";
        Map args = new HashMap();
        args.put(WebServicesClient.ARG_URL, url);
        client.configure(args);
        Map header = new HashMap();
        // Information can be fetched from requestEndpoint and updated in the header and body
        header.put("Authorization","XXXX XXXX");
        header.put("Content-Type","application/json");
      
        List<String> allowedStatuses = new ArrayList();
        allowedStatuses.add("2**");
        
        Map payload = new HashMap();
        payload.put("jsonBody","{"user":{"userId":"RinkuSharma","firstName":"Rinku","lastName":"Sharma","title":"manager"}}");
        
        String response = client.executePost(url, payload, header, allowedStatuses);
        // if response contains token it can be updated in the requestEndpoint header or body
        // the requestEndpoint will be used for execution of the particular operation configured
        log.info("response: " + response);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }

The following example displays the Before Operation Rule being used to update the values for endpoint and application attributes before execution of the endpoint:

Copy
Map updatedInfoMap = new HashMap();
    requestEndPoint.setFullUrl(requestEndPoint.getFullUrl().replaceAll("&&", "&"));
    Map connectorStateMap = new HashMap();
    connectorStateMap.put("accesstoken","Bearer accessTokenGeneratedInBeforeRuleScript");
    updatedInfoMap.put("updatedEndPoint",requestEndPoint);
    updatedInfoMap.put("connectorStateMap",connectorStateMap);
    return updatedInfoMap;