How to dynamically fetch workgroup name from entitlement cataologue which is mentioned in Owner field and update the memebrs for that entitlement to that workgroup

Hi,

We have a requirement as below.

  1. Find members from AD Application in entitlement catalogue
  2. Check the owner field for each entitlement .
  3. If there is a workgroup in owner field - we have to add all the members in that entitlement to that workgroup dynamically.

Initially, I created a custom rule to fetch all memebers from AD application

Filter filterEntitlement = Filter.and(Filter.and(Filter.eq(“application.name”,“MRC Active Directory Direct”),
Filter.eq(“name”, “memberOf”),

			Filter filter = Filter.collectionCondition("identityEntitlements", filterEntitlement);
		QueryOptions qo = new QueryOptions();
		qo.addFilter(filter);

  List ids = context.getObjects(Identity.class, qo);

List memberName = new ArrayList();

for (Identity identity : ids) {
memberName.add(identity.getName());

System.out.println("Found identity: " + identity.getName());
}

Secondly, I gave the sample workgroup name directly in querry options and I am able to add all these memebers in that static workgroup.

List userNames=new ArrayList();

// Make Sure you add the list of users to the above list of userNames

QueryOptions qo = new QueryOptions();

qo.addFilter(Filter.in(“name”, memberName));

int recordCounter=0;

IncrementalObjectIterator it = new IncrementalObjectIterator(context, Identity.class, qo);

Identity workGroupObject=context.getObjectByName(Identity.class,“XYZ Owners Workgroup”);

while ( (it != null) && (it.hasNext()) ) {
recordCounter++;

Identity identity = (Identity) it.next();


identity.add(workGroupObject);
context.saveObject(identity);

if (0 == (recordCounter % 10)) {
  context.commitTransaction();
  context.decache();
} 

}

context.commitTransaction();
context.decache();

Util.flushIterator(it);

return “Success”;

But , I should not pass the workgroup directly. Instead I have to iterate each entitlement and find the owner field and memebers . If it is a workgroup I have to add all the memebers to that workgroup.

I tried in other ways > But I am stuck how to retrieve workgroup name for each entitlement. Can someone help on this step.

give it a try below code


  import sailpoint.object.*;
  import sailpoint.tools.*;
  import sailpoint.api.*;

  import java.util.*;

  String appName = "Okta";

  try {
    QueryOptions queryOptions = new QueryOptions();
    queryOptions.addFilter(Filter.and(
      Filter.eq("application.name", appName),
      Filter.notnull("owner")
    ));
    queryOptions.setCloneResults(true);

    Iterator maIterator = context.search(ManagedAttribute.class, queryOptions);
    while (maIterator.hasNext()) {
      ManagedAttribute managedAttribute = (ManagedAttribute) maIterator.next();
      if (Objects.nonNull(managedAttribute.getOwner()) && !managedAttribute.getOwner().isWorkgroup()) {
        continue;
      }
      Identity workGroupObject = managedAttribute.getOwner();

      Filter filterEntitlement = Filter.and(
        Filter.eq("application.name", appName),
        Filter.eq("name", managedAttribute.getAttribute()),
        Filter.eq("value", managedAttribute.getValue())
      );

      Filter filter = Filter.collectionCondition("identityEntitlements", filterEntitlement);

      QueryOptions qo = new QueryOptions();
      qo.addFilter(filter);
      qo.setCloneResults(true);
      qo.setDistinct(true);
      int recordCounter = 0;
      IncrementalObjectIterator it = new IncrementalObjectIterator(context, Identity.class, qo);
      while (it != null && it.hasNext()) {

        recordCounter++;
        Identity identity = (Identity) it.next();
        identity.add(workGroupObject);
        context.saveObject(identity);

        if (recordCounter % 10 == 0) {
          context.commitTransaction();
          context.decache(managedAttribute);
        }
      }
      Util.flushIterator(it);
      context.commitTransaction();
      // context.decache();
    }
    Util.flushIterator(maIterator);
  } catch (Exception e) {
    throw new RuntimeException(e);
  } finally {
    context.decache();
  }

  return "Success";

thanks