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<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 < tokens.size(); i++) {

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

        }

      } else {

        lineHash = new HashMap();

        for (int i = 0; i < 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<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 < 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 < tokens.size(); i++) {

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

        }

      } else {

        lineHash = new HashMap();

        for (int i = 0; i < 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...