Monday, September 23, 2024

Fetch Members from Workgroup

  import java.util.ArrayList;

  import java.util.Iterator;

  import java.util.List;

  import sailpoint.api.ObjectUtil;

  import sailpoint.object.Identity;

  import sailpoint.tools.GeneralException;

  List workgroupMembersList = new ArrayList();

  try {

    Identity objectByName = context.getObjectByName(Identity.class, "Operations");

    Iterator workgroupMembers = ObjectUtil.getWorkgroupMembers(context, objectByName, null);

    while (workgroupMembers.hasNext()) {

      Object[] object = (Object[]) workgroupMembers.next();

      Identity identity = (Identity) object[0];

      workgroupMembersList.add(identity.getName());

    }

  } catch (GeneralException e) {

    log.error("GeneralException : "+e.getMessage());

  }

  return workgroupMembersList;

Wednesday, August 21, 2024

Create group in OpenLdap

import sailpoint.connector.Connector;
import sailpoint.connector.LDAPConnector;
import sailpoint.object.Application;
import sailpoint.object.Attributes;
import sailpoint.object.Link;
import sailpoint.object.Identity;
import sailpoint.api.SailPointContext;
import sailpoint.tools.GeneralException;
import sailpoint.tools.Util;
import java.util.HashMap;
import java.util.Map;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.BasicAttribute;

Application ldapApp = context.getObjectByName(Application.class, "Mighty Application Name"); // Replace with your LDAP application name

// Initialize the LDAP connector
Connector connector = ldapApp.getConnector();
LDAPConnector ldapConnector = (LDAPConnector) connector;


String groupName = "mygroup";  
String groupBaseDN = "ou=groups,dc=example,dc=com";  
String gidNumber = "1234";  

// Prepare attributes for the new group
Attributes<String, Object> groupAttrs = new Attributes<>();
groupAttrs.put("cn", groupName);
groupAttrs.put("objectClass", Util.list("top", "posixGroup"));
groupAttrs.put("gidNumber", gidNumber);

try {
    ldapConnector.createObject(context, "group", groupAttrs, groupBaseDN + ",cn=" + groupName);

    
} catch (GeneralException e) {
    System.out.println("GeneralException: " + e.getMessage());
}

Wednesday, August 7, 2024

how to fetch IT roles based on entitlements in SailPoint IIQ?

import java.util.ArrayList;
import java.util.List;
import sailpoint.api.SailPointContext;
import sailpoint.object.Bundle;
import sailpoint.object.Filter;
import sailpoint.object.Profile;
import sailpoint.object.QueryOptions; 

String appName="Mighty";
String entitlementName = "DPA";
QueryOptions profileQo = new QueryOptions();
profileQo.addFilter(Filter.eq("application.name", appName));


  List bundles = new ArrayList();
  List profiles = context.getObjects(Profile.class, profileQo);

  if (profiles != null) {
    for (Object profileObj : profiles) {
      Profile p = (Profile) profileObj;
      List constraints = p.getConstraints();
      List filterList = null;
  
      if (constraints != null) {
        for (Object filter : constraints) {

          filterList = new ArrayList();
          if (filter instanceof sailpoint.object.Filter.LeafFilter) {
            sailpoint.object.Filter.LeafFilter f = (sailpoint.object.Filter.LeafFilter) filter;

            //Filter can have multiple values 
            Object value = f.getValue();

            if (value instanceof ArrayList) {

              ArrayList entitlements = new ArrayList();
              entitlements = (ArrayList) value;

              for (Object obj : entitlements) {
                if (obj.toString().equals(entitlementName)) {

                  Bundle bun = p.getBundle();
                  bundles.add(bun.getName());
                }

              }

            }

          }

        }

      }

    }

  }

  return bundles;

Wednesday, July 3, 2024

Read a CSV file, copy the CSV file data, concatenate two columns from original file and write it to another csv file

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class CSVModifier {
public static void main(String[] args) {
String line;
String inputFilePath = "F:\\DOCS\\test_03072024.csv";
String outputFilePath = "F:\\DOCS\\updated_test_03072024.csv";

try  {

BufferedReader br = new BufferedReader(new FileReader(inputFilePath));
BufferedWriter bw = new BufferedWriter(new FileWriter(outputFilePath));

// Read the header
String header = br.readLine();
if (header != null) {
String[] headers = header.split(",");
int appIndex = -1;
int roleNameIndex = -1;

// Find the indices of "app" and "Role Name"
for (int i = 0; i < headers.length; i++) {
if (headers[i].trim().equalsIgnoreCase("app")) {
appIndex = i;
} else if (headers[i].trim().equalsIgnoreCase("Role Name")) {
roleNameIndex = i;
}
}

// Check if both columns were found
if (appIndex == -1 || roleNameIndex == -1) {
throw new IllegalArgumentException(
"Input CSV does not contain required columns 'Service' and 'Role Name'");
}

// Add the new column to the header
header += ",app|RoleName";
bw.write(header);
bw.newLine();

// Read and process each line
while ((line = br.readLine()) != null) {
String[] columns = line.split(",");
String app = columns[appIndex];
String roleName = columns[roleNameIndex];
// Concatenate "app" and "Role Name"
String newColumn = app + "|" + roleName;
// Add the new column to the line
line += "," + newColumn;
bw.write(line);
bw.newLine();
}
}
bw.close();

} catch (IOException e) {
e.printStackTrace();
}
}
}

Friday, May 3, 2024

Database Connection

 public static Connection getConnection(){

    String url = "DBURL";

    String user = "spadmin";

String pwd = "p1213#%$#^$%#&^";    

Connection connection;

 log.error("Intializing connection");

 Properties connectionProperties = new Properties();

         connectionProperties.put("user", user);

        connectionProperties.put("password", context.decrypt(pwd));

        connection = DriverManager.getConnection(url, connectionProperties);        

        return connection;

}


WorkflowLaunch

HashMap<String,Object> map = new HashMap<String,Object>();

        map.put("allowRequestsWithViolations","true");

        map.put("approvalMode","serial");

        map.put("approvalScheme","none"); // For auto approval 

        map.put("AppName",applicationName); //Target applcation name

        map.put("doRefresh","true");

        map.put("enableRetryRequest","false");

        map.put("fallbackApprover","spadmin");

        map.put("flow",requestType);

        map.put("foregroundProvisioning","true");

        map.put("identityDisplayName",identityName);

        map.put("identityName",identityName);

        map.put("identity",identity);

        map.put("notificationScheme","user,requester");

        map.put("optimisticProvisioning","true");

        map.put("plan",plan);

        map.put("policiesToCheck","");

        map.put("policyScheme","continue");

        map.put("policyViolations","");

        map.put("project","");

        map.put("requireViolationReviewComments","true");

        map.put("securityOfficerName","");

        map.put("sessionOwner","spadmin");

        map.put("source","LCM");

        map.put("trace","true");

        map.put("violationReviewDecision","");

        map.put("workItemComments","");


//Create WorkflowLaunch and set values

Workflow wf = (Workflow) context.getObjectByName(Workflow.class,"Mighty - LCM Provisioning");

WorkflowLaunch wflaunch = new WorkflowLaunch(); 

wflaunch.setWorkflowName(wf.getName());

 wflaunch.setWorkflowRef(wf.getName());

 wflaunch.setCaseName("customProvToDB");

 //Launch workflow for application provisioning

 wflaunch.setVariables(map);

 wflaunch.setWorkflow(wf);  

       

 //Create Workflower and launch workflow from WorkflowLaunch

 Workflower workflower = new Workflower(context);

 WorkflowLaunch launch = workflower.launch(wflaunch);

 String workFlowId = launch.getWorkflowCase().getId();

log.error("workFlowId: "+workFlowId); 

API's Syntax

SailPointContext context = SailPointFactory.getCurrentContext();

Identity identity = new  Identity();

Identity identity = context.getObjectByName(Identity.class, "Magnus"));

Bundle bundle = new Bundle();

WorkflowLaunch wflaunch = new WorkflowLaunch();

Workflower workflower = new Workflower(context);

Trim the String

public static String getNotNullString(String value){

String returnValue = "";

if (value != null) {

 str = value.trim();

 }

 return returnValue ;

}

Sunday, April 28, 2024

Workgroup Creation

import sailpoint.object.Identity;

import sailpoint.object.Identity.WorkgroupNotificationOption;


Identity identity = new Identity();

identity.setName("Mighty-Workgroup");

identity.setDisplayName("Mighty-Workgroup");

Identity workGroupOwner = context.getObjectByName(Identity.class, "spadmin");

identity.setOwner(workGroupOwner);

identity.setWorkgroup(true);

identity.setNotificationOption(WorkgroupNotificationOption.MembersOnly);

context.saveObject(identity);

context.commitTransaction();

context.decache(identity);

ITRoles Creation Utlity

  import java.io.BufferedReader;

  import java.io.File;

  import java.io.FileNotFoundException;

  import java.io.FileReader;

  import java.io.IOException;

  import java.util.ArrayList;

  import java.util.HashMap;

  import java.util.List;

  import java.util.Map;

  import org.apache.commons.logging.Log;

  import sailpoint.api.SailPointContext;

  import sailpoint.object.Application;

  import sailpoint.object.Bundle;

  import sailpoint.object.Filter;

  import sailpoint.object.Identity;

  import sailpoint.object.Profile;

  import sailpoint.tools.GeneralException;

  import sailpoint.tools.RFC4180LineParser;


  private void buildRole(HashMap roleHash) {


    String roleDec = roleHash.get("Role Description").toString();

    String roleOwner = roleHash.get("Role Owner").toString();

    String entsList = roleHash.get("Entilements").toString();

    String roleNameBeforeReplace = roleHash.get("Role Name").toString();

    String roleName = roleNameBeforeReplace.replace("+", "");


    String appName = "AD";

    Bundle role = null;

    Identity ownerId = null;

    Identity workgroupOwner = null;


    Map desc = new HashMap();

    desc.put("en_US", roleDec);


    try {


      role = context.getObjectByName(Bundle.class, roleName);

      if (role == null) {

        role = new Bundle();

      }


      ownerId = context.getObjectByName(Identity.class, roleOwner);

      if (ownerId == null) {



        ownerId = new Identity();

        ownerId.setName(roleOwner);

        ownerId.setDisplayName(roleOwner);

        workgroupOwner = context.getObjectByName(Identity.class, "spadmin");

        ownerId.setOwner(workgroupOwner);

        ownerId.setWorkgroup(true);

        ownerId.setNotificationOption(sailpoint.object.Identity.WorkgroupNotificationOption.MembersOnly);

        context.saveObject(ownerId);

        context.commitTransaction();

        context.decache(ownerId);

      }



      Application appObj = null;

      if (appName != null) {

        appObj = context.getObjectByName(Application.class, appName);

        if (appObj == null) {

          return;

        }

      }


      role.setType("it");

      role.setName(roleName);

      role.setDisplayName(roleName);

      role.setOwner(ownerId);

      role.setDescriptions(desc);


      List inheritList = new ArrayList();

      Bundle bundleObj = context.getObjectByName(Bundle.class, "Mighty IT Roles");

      inheritList.add(inheritList);


      RFC4180LineParser entParser = new RFC4180LineParser("|");

      ArrayList&lt;String> entitlements = entParser.parseLine(entsList);


      if (role.getType().contains("it")) {


        List proList = new ArrayList();

        List filList = new ArrayList();

        Profile profile = new Profile();


        Filter filter = Filter.containsAll("Entilements", entitlements);

        filList.add(filter);

        profile.setConstraints(filList);

        profile.setApplication(appObj);

        proList.add(profile);

        role.setProfiles(filList);

        role.setInheritance(inheritList);


      }

      context.saveObject(role);

      context.commitTransaction();

      context.decache(role);

      return;


    } catch (Exception e) {

      log.error("Exception : " + e.getMessage());

    }

  }

  // Code Execution Starts here

  int lineCounter = 0;

  String dlm = ",";

  String thisLine = "";

  String headerString = "";

  String valueString = "";

  HashMap lineHash = null;

  List headerStrings = new ArrayList();

  String csvFileName = "Path";

  log.debug("Role Creation Started...");

  BufferedReader fileIn = null;

  File bundleFile = null;

  log.debug("Readin Bundle date from : " + csvFileName);


  try {

    bundleFile = new File(csvFileName);


    if ((!bundleFile.exists()) || bundleFile.isDirectory()) {

      log.error("Unable to find the bundle csv file : " + csvFileName);

      return;

    }


    fileIn = new BufferedReader(new FileReader(csvFileName));

    RFC4180LineParser parser = new RFC4180LineParser(dlm);


    while (null != (thisLine = fileIn.readLine())) {

      ArrayList tokens = parser.parseLine(thisLine);


      if (lineCounter == 0) {

        for (int i = 0; i &lt; tokens.size(); i++) {

          headerStrings.add(tokens.get(i).toString().trim());

        }

      } else {

        lineHash = new HashMap();

        for (int i = 0; i &lt; args.length; i++) {

          headerString = headerStrings.get(i).toString();

          valueString = tokens.get(i).toString();


          if (valueString != null) {

            valueString = valueString.trim();

          } else {

            valueString = "";

          }

          lineHash.put(headerString, valueString);

        }

        buildRole(lineHash);

      }

      lineCounter++;


      if ((lineCounter % 20) == 0) {

        context.decache();

      }

    }

  } catch (FileNotFoundException e) {

    log.error("Exception : " + e.getMessage());

  } catch (IOException e) {

    log.error("Exception : " + e.getMessage());

  } catch (GeneralException e) {

    log.error("Exception : " + e.getMessage());

  }

  return "Sucess";

BusinessRoles Creation Utlity

   import java.io.BufferedReader;

  import java.io.File;

  import java.io.FileNotFoundException;

  import java.io.FileReader;

  import java.io.IOException;

  import java.util.ArrayList;

  import java.util.HashMap;

  import java.util.List;

  import java.util.Map;

  import org.apache.commons.logging.Log;

  import sailpoint.api.SailPointContext;

  import sailpoint.object.Application;

  import sailpoint.object.Bundle;

  import sailpoint.object.Filter;

  import sailpoint.object.Identity;

  import sailpoint.object.Profile;

  import sailpoint.tools.GeneralException;

  import sailpoint.tools.RFC4180LineParser;


  private void buildBusinessRole(HashMap roleHash) {


    String roleName = roleHash.get("Business Role Name").toString().trim();

    String roleDesc = roleHash.get("Business Role Description").toString().trim();

    String roleOwner = roleHash.get("Business Role Owner").toString().trim();

    String itRole = roleHash.get("IT Role Name").toString().trim();


    Map desc = new HashMap();

    desc.put("en_US", roleDesc);


    Bundle role = null;

    Identity identity = null;

    Identity workGroupOwner = null;


    try {

      role = context.getObjectByName(Bundle.class, roleName);

      if (role == null) {

        role = new Bundle();

      }

      identity = context.getObjectByName(Identity.class, roleOwner);


      if (identity == null) {

        // Create the Workgroup for this Business Role

        identity = new Identity();

        identity.setName(roleOwner);

        identity.setDisplayName(roleOwner);

        workGroupOwner = context.getObjectByName(Identity.class, "spadmin");

        identity.setOwner(workGroupOwner);

        identity.setWorkgroup(true);

        context.saveObject(identity);

        context.commitTransaction();

        context.decache(identity);

      }

      

      role.setType("business");

      role.setName(roleName);

      role.setDisplayName(roleName);

      role.setOwner(identity);

      role.setDescriptions(desc);


      RFC4180LineParser entParser = new RFC4180LineParser("|");

      ArrayList&lt;String> itRoles = entParser.parseLine(itRole);


      Bundle bundleObj = context.getObjectByName(Bundle.class, "Mighty IT Roles");

      role.addInheritance(bundleObj);


      // Add the required IT Roles to this Business Role

      for (int e = 0; e &lt; itRoles.size(); e++) {

        Bundle requiredRole = context.getObjectByName(Bundle.class, itRoles.get(e));


        if (requiredRole == null) {

          log.error("Reuired role not found...");

        } else {

          role.addRequirement(requiredRole);

        }

      }

      context.saveObject(role);

      context.commitTransaction();

      context.decache(role);

      return;


    } catch (GeneralException e) {

      log.error("GeneralException : " + e.getMessage());

    }

  }


  // Code Execution Starts here


  int lineCounter = 0;

  String dlm = ",";

  String thisLine = "";

  String headerString = "";

  String valueString = "";

  HashMap lineHash = null;

  List headerStrings = new ArrayList();

  String csvFileName = "Path";


  log.debug("Role Creation Started...");


  BufferedReader fileIn = null;

  File bundleFile = null;

  log.debug("Readin Bundle date from : " + csvFileName);


  try {

    bundleFile = new File(csvFileName);


    if ((!bundleFile.exists()) || bundleFile.isDirectory()) {

      log.error("Unable to find the bundle csv file : " + csvFileName);

      return;

    }


    fileIn = new BufferedReader(new FileReader(csvFileName));

    RFC4180LineParser parser = new RFC4180LineParser(dlm);


    while (null != (thisLine = fileIn.readLine())) {

      ArrayList tokens = parser.parseLine(thisLine);


      if (lineCounter == 0) {

        for (int i = 0; i &lt; tokens.size(); i++) {

          headerStrings.add(tokens.get(i).toString().trim());

        }

      } else {

        lineHash = new HashMap();

        for (int i = 0; i &lt; args.length; i++) {

          headerString = headerStrings.get(i).toString();

          valueString = tokens.get(i).toString();


          if (valueString != null) {

            valueString = valueString.trim();

          } else {

            valueString = "";

          }

          lineHash.put(headerString, valueString);

        }

        buildRole(lineHash);

      }

      lineCounter++;


      if ((lineCounter % 20) == 0) {

        context.decache();

      }

    }

  } catch (FileNotFoundException e) {

    log.error("Exception : " + e.getMessage());

  } catch (IOException e) {

    log.error("Exception : " + e.getMessage());

  } catch (GeneralException e) {

    log.error("Exception : " + e.getMessage());

  }

  return "Sucess";

Fetch Members from Workgroup

  import java.util.ArrayList;   import java.util.Iterator;   import java.util.List;   import sailpoint.api.ObjectUtil;   import sailpoint.ob...