Hi Aleksander,
Yes, it’s a part of customization rule. The code is attached below please validate:
import org.apache.log4j.Logger;
import sailpoint.object.Application;
import sailpoint.server.Auditor;
import org.apache.http.client.ClientProtocolException;
import org.json.JSONArray;
import org.json.JSONObject;
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
import sailpoint.tools.GeneralException;
import java.util.Base64;
private Logger myLogger = Logger.getLogger(“Mexichem-SNOW”);
String mediaType = “application/json”;
/**
* Logic to close a specific SCTASK in ServiceNow.
*
* @param application, taskSysId, userEmail, roleAssigned
* @throws GeneralException
*/
public int closeTASK(Application appSnow, String taskSysId, String userEmail, String role) throws GeneralException {
public static final String BASE_URL = appSnow.getAttributeValue(“genericWebServiceBaseUrl”);
public static final String AUTHORIZATION_HEADER = “Authorization”;
public static final String AUTHORIZATION_BASIC_PREFIX = “Basic “;
public static final String USER_NAME = appSnow.getAttributeValue(“username”);
public static final String PASSWORD = context.decrypt(appSnow.getAttributeValue(“password”));
public static final String AUTHORIZATION_VALUE = USER_NAME+”:”+PASSWORD;
public static final String AUTHORIZATION_BASIC_VALUE = Base64.getEncoder().encodeToString(AUTHORIZATION_VALUE.getBytes(“utf-8”));
public static final String AUTHORIZATION_HEADER_VALUE = AUTHORIZATION_BASIC_PREFIX + AUTHORIZATION_BASIC_VALUE;
//public static final String ACCEPT_HEADER = “ACCEPT”;
//public static final String ACCEPT_HEADER_VALUE = “application/json”;
public static final MediaType JSON = MediaType.parse(“application/json; charset=utf-8”);
myLogger.debug("Starting Orbia-ServiceNow-Library-Rule closeTASK...");
/* myLogger.debug(“BASE_URL: " + BASE_URL);
myLogger.debug(“USER_NAME: " + USER_NAME);
myLogger.debug(“PASSWORD: " + PASSWORD);
myLogger.debug(“AUTHORIZATION_HEADER_VALUE: " + AUTHORIZATION_HEADER_VALUE);*/
try {
OkHttpClient client = new OkHttpClient();
String requestBody=”{“close_notes”: “Close complete. Task processed for “+userEmail+”. Role: “+role+””,“state”: “3”,“active”: “false”}”;
myLogger.debug(“requestBody: " + requestBody);
RequestBody body = RequestBody.create(JSON, requestBody);
Request request = new Request.Builder()
.url(BASE_URL+”/now/table/sc_task/”+taskSysId)
.addHeader(AUTHORIZATION_HEADER, AUTHORIZATION_HEADER_VALUE)
.put(body)
.build();
myLogger.debug(“URL: " + BASE_URL+”/now/table/sc_task/”+taskSysId);
Response response = client.newCall(request).execute();
JSONObject jobj = new JSONObject(response.body().string());
myLogger.debug(“Response: " + jobj);
Auditor.logAs(USER_NAME, “roadWebservicesRequest”, “teste”, request.urlString(), “{“statusCode”:”+response.code().toString()+”,“reponseBody”:“+jobj+”}", requestBody, “ServiceNow-AdditionalPermissions”);
return response.code();
}
catch(Exception e) {
myLogger.error("Exception occurred -closeTASK-: " + e.toString());
}
myLogger.debug(“Ending Orbia-ServiceNow-Library-Rule closeTASK…”);
}
/**
* Logic to reassign a specific SCTASK in ServiceNow.
*
* @param application, taskSysId, errorDetail, assignedGroup
* @throws GeneralException
*/
public int reassignTASK(Application appSnow, String taskSysId, String errorDetail, String assignedGroup) throws GeneralException {
public static final String BASE_URL = appSnow.getAttributeValue(“genericWebServiceBaseUrl”);
public static final String AUTHORIZATION_HEADER = “Authorization”;
public static final String AUTHORIZATION_BASIC_PREFIX = “Basic “;
public static final String USER_NAME = appSnow.getAttributeValue(“username”);
public static final String PASSWORD = context.decrypt(appSnow.getAttributeValue(“password”));
public static final String AUTHORIZATION_VALUE = USER_NAME+”:”+PASSWORD;
public static final String AUTHORIZATION_BASIC_VALUE = Base64.getEncoder().encodeToString(AUTHORIZATION_VALUE.getBytes(“utf-8”));
public static final String AUTHORIZATION_HEADER_VALUE = AUTHORIZATION_BASIC_PREFIX + AUTHORIZATION_BASIC_VALUE;
//public static final String ACCEPT_HEADER = “ACCEPT”;
//public static final String ACCEPT_HEADER_VALUE = “application/json”;
public static final MediaType JSON = MediaType.parse(“application/json; charset=utf-8”);
errorDetail=errorDetail.replace("\n", "");
myLogger.debug("Starting Orbia-ServiceNow-Library-Rule reassignTASK...");
try {
OkHttpClient client = new OkHttpClient();
String requestBody="{\"assigned_to\": \"\",\"work_notes\": \"Error: "+errorDetail+"\",\"assignment_group\":\""+assignedGroup+"\"}";
myLogger.debug("requestBody: " + requestBody);
RequestBody body = RequestBody.create(JSON, requestBody);
Request request = new Request.Builder()
.url(BASE_URL+"/now/table/sc_task/"+taskSysId)
.addHeader(AUTHORIZATION_HEADER, AUTHORIZATION_HEADER_VALUE)
.put(body)
.build();
myLogger.debug("URL: " + BASE_URL+"/now/table/sc_task/"+taskSysId);
Response response = client.newCall(request).execute();
JSONObject jobj = new JSONObject(response.body().string());
myLogger.debug("Response: " + jobj);
Auditor.logAs(USER_NAME, "roadWebservicesRequest", "teste", request.urlString(), "{\"statusCode\":"+response.code().toString()+",\"reponseBody\":"+jobj+"}", requestBody, "ServiceNow-AdditionalPermissions");
return response.code();
}
catch(Exception e) {
myLogger.error("Exception occurred -reassignTASK-: " + e.toString());
}
myLogger.debug("Ending Orbia-ServiceNow-Library-Rule reassignTASK...");
}
/**
* Logic to process a specific SCTASK in ServiceNow.
*
* @param application, identityName, taskSysId, workNote, assignedGroup
* @throws GeneralException
*/
public int processTASK(Application appSnow, String identityName, String taskSysId, String workNote, String assignedGroup) throws GeneralException {
public static final String BASE_URL = appSnow.getAttributeValue(“genericWebServiceBaseUrl”);
public static final String AUTHORIZATION_HEADER = “Authorization”;
public static final String AUTHORIZATION_BASIC_PREFIX = “Basic “;
public static final String USER_NAME = appSnow.getAttributeValue(“username”);
public static final String PASSWORD = context.decrypt(appSnow.getAttributeValue(“password”));
public static final String AUTHORIZATION_VALUE = USER_NAME+”:”+PASSWORD;
public static final String AUTHORIZATION_BASIC_VALUE = Base64.getEncoder().encodeToString(AUTHORIZATION_VALUE.getBytes(“utf-8”));
public static final String AUTHORIZATION_HEADER_VALUE = AUTHORIZATION_BASIC_PREFIX + AUTHORIZATION_BASIC_VALUE;
//public static final String ACCEPT_HEADER = “ACCEPT”;
//public static final String ACCEPT_HEADER_VALUE = “application/json”;
public static final MediaType JSON = MediaType.parse(“application/json; charset=utf-8”);
myLogger.debug("Starting Orbia-ServiceNow-Library-Rule processTASK...");
try {
OkHttpClient client = new OkHttpClient();
String requestBody="{\"assigned_to\": \"sailpoint.integration\",\"work_notes\": \""+workNote+"\",\"state\":\"2\"}";
myLogger.debug("requestBody: " + requestBody);
RequestBody body = RequestBody.create(JSON, requestBody);
Request request = new Request.Builder()
.url(BASE_URL+"/now/table/sc_task/"+taskSysId)
.addHeader(AUTHORIZATION_HEADER, AUTHORIZATION_HEADER_VALUE)
.put(body)
.build();
myLogger.debug("URL: " + BASE_URL+"/now/table/sc_task/"+taskSysId);
Response response = client.newCall(request).execute();
JSONObject jobj = new JSONObject(response.body().string());
Auditor.logAs(USER_NAME, "roadWebservicesRequest", identityName, request.urlString(), "{\"statusCode\":"+response.code().toString()+",\"reponseBody\":"+jobj+"}", request.toString(), "ServiceNow-AdditionalPermissions");
myLogger.debug("Response: " + jobj);
return response.code();
}
catch(Exception e) {
myLogger.error("Exception occurred -processTASK-: " + e.toString());
}
myLogger.debug("Ending Orbia-ServiceNow-Library-Rule processTASK...");
}
/**
* Logic to create a new Incident ServiceNow.
*
* @param application, identityName, workNote, assignedGroup
* @throws GeneralException
*/
public int newIncident(Application appSnow, String identityName, String description, String title, String assignedGroup, String businessService) throws GeneralException {
public static final String BASE_URL = appSnow.getAttributeValue(“genericWebServiceBaseUrl”);
public static final String AUTHORIZATION_HEADER = “Authorization”;
public static final String AUTHORIZATION_BASIC_PREFIX = “Basic “;
public static final String USER_NAME = appSnow.getAttributeValue(“username”);
public static final String PASSWORD = context.decrypt(appSnow.getAttributeValue(“password”));
public static final String AUTHORIZATION_VALUE = USER_NAME+”:”+PASSWORD;
public static final String AUTHORIZATION_BASIC_VALUE = Base64.getEncoder().encodeToString(AUTHORIZATION_VALUE.getBytes(“utf-8”));
public static final String AUTHORIZATION_HEADER_VALUE = AUTHORIZATION_BASIC_PREFIX + AUTHORIZATION_BASIC_VALUE;
//public static final String ACCEPT_HEADER = “ACCEPT”;
//public static final String ACCEPT_HEADER_VALUE = “application/json”;
public static final MediaType JSON = MediaType.parse(“application/json; charset=utf-8”);
myLogger.debug("Starting Orbia-ServiceNow-Library-Rule processTASK...");
try {
OkHttpClient client = new OkHttpClient();
String requestBody = "{\"assignment_group\": \""+assignedGroup+"\",\"description\": \""+description+"\",\"short_description\":\""+title+"\",\"category\":\"Access Issue\",\"business_service\":\""+businessService+"\"}";
//{"assignment_group":"Global Identity Service","description":"descricao","short_description":"titulo","category":"Access Issue","business_service":""}
myLogger.debug("requestBody: " + requestBody);
RequestBody body = RequestBody.create(JSON, requestBody);
Request request = new Request.Builder()
.url(BASE_URL+"/now/v1/table/incident")
.addHeader(AUTHORIZATION_HEADER, AUTHORIZATION_HEADER_VALUE)
.post(body)
.build();
myLogger.debug("URL: " + BASE_URL+"/now/table/sc_task/"+taskSysId);
Response response = client.newCall(request).execute();
JSONObject jobj = new JSONObject(response.body().string());
System.out.println("Request: " + request.toString());
System.out.println("Response: " + jobj);
System.out.println(requestBody);
System.out.println(response.code());
if(null != identityName){
Auditor.logAs(USER_NAME, "roadWebservicesRequest", identityName, request.urlString(), "{\"statusCode\":"+response.code().toString()+",\"reponseBody\":"+jobj+"}", requestBody, "ServiceNow-AdditionalPermissions");
}
return response.code();
}
catch(Exception e) {
myLogger.error("Exception occurred -processTASK-: " + e.toString());
}
myLogger.debug("Ending Orbia-ServiceNow-Library-Rule processTASK...");
}