Hi @amanKsingh ,
There are multiple approaches available, but you need to select the one which is most suitable as per your need additionally that should be performance optimized.
In Sailpoint, we don’t have a direct way to fetch the membership of a particular role. It all depends on How you have assigned the membership of users to the role. for e.g. whether you have assigned a population or filter or custom rule in auto-assignment option while creating the business role.
The Bundle (Role) object looks like below -
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Bundle PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Bundle created="1665370220901" disabled="true" displayName="Accounting Business Role" id="c0a83865838c16e38183bfcce9650059" modified="1706013674377" name="Accounting Business Role" type="business">
<Attributes>
<Map>
<entry key="accountSelectorRules"/>
<entry key="allowDuplicateAccounts" value="false"/>
<entry key="allowMultipleAssignments" value="false"/>
<entry key="mergeTemplates" value="false"/>
<entry key="sysDescriptions">
<value>
<Map>
<entry key="en_US" value="Accounting Business Role"/>
</Map>
</value>
</entry>
</Map>
</Attributes>
<Inheritance>
<Reference class="sailpoint.object.Bundle" id="c0a83865838c16e38183bfc389310037" name="WintelApplication"/>
</Inheritance>
<Owner>
<Reference class="sailpoint.object.Identity" id="c0a84a0382f6191b8182f6f9eb5100eb" name="spadmin"/>
</Owner>
<Requirements>
<Reference class="sailpoint.object.Bundle" id="c0a83865838c16e38183bfc891fa0049" name="Accounting IT Role"/>
</Requirements>
<Selector>
<IdentitySelector>
<PopulationRef>
<Reference class="sailpoint.object.GroupDefinition" id="c0a83865838c16e38183bfd174b10063" name="Accounting population"/>
</PopulationRef>
</IdentitySelector>
</Selector>
</Bundle>
In the above example we have used a population to assign the user membership to this role
If I open the Population, I can see below details -
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE GroupDefinition PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<GroupDefinition created="1665370518705" id="c0a83865838c16e38183bfd174b10063" indexed="true" modified="1665453140105" name="Accounting population" private="true">
<Description></Description>
<GroupFilter>
<CompositeFilter operation="OR">
<Filter operation="EQ" property="jobTitle" value="Accounts Payable Analyst"/>
<Filter operation="EQ" property="jobTitle" value="Accounts Receivable Analyst"/>
</CompositeFilter>
</GroupFilter>
<Index>
<Reference class="sailpoint.object.GroupIndex" id="c0a8386583c41fbb8183c4be28890030" name="Accounting population"/>
</Index>
<Owner>
<Reference class="sailpoint.object.Identity" id="c0a84a0382f6191b8182f6f9eb5100eb" name="spadmin"/>
</Owner>
</GroupDefinition>
The population contains a complex filter i.e. JobTitle equals Accounts Payable Analyst or JobTitle equals Accounts Receivable Analyst -
<CompositeFilter operation="OR">
<Filter operation="EQ" property="jobTitle" value="Accounts Payable Analyst"/>
<Filter operation="EQ" property="jobTitle" value="Accounts Receivable Analyst"/>
</CompositeFilter>
Now taking the above example, If we have assigned the membership via population you can use the same filter to fetch all the users.
example rule -
import sailpoint.object.Filter;
import sailpoint.object.Identity;
import sailpoint.object.QueryOptions;
QueryOptions qo=new QueryOptions();
Filter filter1=Filter.eq("jobTitle","Accounts Payable Analyst");
Filter filter2=Filter.eq("jobTitle","Accounts Receivable Analyst");
Filter filter=Filter.or(filter1,filter2);
qo.addFilter(filter);
List<Identity> identities=context.getObjects(Identity.class,qo);
for(int i=0;i<identities.size();i++)
{
Identity id=identities.get(i);
System.out.println("Name"+id.getName());
}
context.decache();
In similar fashion you can check the assignment criteria in the business role to take your call.
However, @abartkowski also suggested you a nice way to fetch the details.
Now let say if you have a hard constraint not to use db queries even for read purpose, then you need to construct the user filter based on status i.e for active users and fetch the user bundle details from your rule based on your condition.
Something similar,
import sailpoint.object.Filter;
import sailpoint.object.Identity;
import sailpoint.object.QueryOptions;
import sailpoint.object.Bundle;
QueryOptions qo=new QueryOptions();
String roleName="Accounting Business Role";
Bundle bundle = context.getObjectByName(Bundle.class,roleName);
String roleId=bundle.getId();
System.out.println("Role id Fetched as"+roleId);
Filter filter=Filter.eq("assignedRoles.id", roleId);
qo.addFilter(filter);
List<Identity> identities=context.getObjects(Identity.class,qo);
System.out.println("Total users::"+identities.size());
for(int i=0;i<identities.size();i++)
{
Identity id=identities.get(i);
System.out.println("Identity Name::"+id.getName());
}
context.decache();
Mark it as solved, if it helps.