How can I perform a contain() check on values return by getAssignedRoles() method?

Hello Experts,

I am trying to do the following on IIQ Rule Beanshell script:

  1. Get all the assigned roles of the identity.
  2. From the returned results of assigned roles, check if any of the roles matches “SAP”.

The following is a snippet of the codes:

import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import sailpoint.api.ExternalAttributeHandler;
import sailpoint.tools.Util;
import sailpoint.object.Attributes;
import sailpoint.object.Identity;
import sailpoint.tools.GeneralException;
import sailpoint.object.ProvisioningPlan;
import sailpoint.api.Provisioner;

logger.debug("getAssignedRoles: " + identity.getAssignedRoles());
logger.debug("Contain getAssignedRoles: " + identity.getAssignedRoles().contains("SAP"));

The following is a sample of the logger debug output from above codes:

2022-12-28T20:47:02,418 DEBUG QuartzScheduler_Worker-3 mzlogger:166 - getAssignedRoles: [sailpoint.object.Bundle@585debd0[id=0a0000b285051603818505d59e42009b,name=SAP-OM-S50000068]]
2022-12-28T20:47:02,419 DEBUG QuartzScheduler_Worker-3 mzlogger:166 - Contain getAssignedRoles: false

From the logger debug, the contain() results shows “false”, which is not what I’m expecting. It should show “true” because it does contain the value I’m looking for.
From the IIQ javadoc documentation, I noticed that the getAssignedRoles() method is a type of java.util.List.

Does anyone have any idea how can I perform a contain on said method?
Thank you in advanced!

Regards,
Ming Zheng

The return type of this method is List< RoleAssignment >
You should go through this list and check the role name…

Hi Ming,

Since getAssignedRoles() returns a list, you can certainly use the contains() method to check for an exact match of the String you’re trying to look for, which is “SAP”. Are you looking for a fuzzy match (i.e. the role contains “SAP” somewhere in it)? If so, then you need to write your own method to do that check as the list.contains() only will work for full string matches.

Also it is possible that the getAssignedRoles() method might return null, so I’d suggest not doing contains() chained to getAssignedRoles() like you did in the logger.debug line, without checking for null values to avoid a NPE.