Sunday, August 1, 2021

Listing Objects in Namespace at Runtime in Sailpoint IdentityIQ

 Listing Objects in Namespace at Runtime in Sailpoint IdentityIQ

import org.apache.log4j.Logger;
import org.apache.log4j.Level;

Logger log = Logger.getLogger("sailpoint.services.bshdemo");
log.setLevel(Level.DEBUG);
log.debug("Listing Variables passed to Beanshell namespace:");

// BeanShell has a "this.variables" array that we can access.

for (int i = 0 ; i < this.variables.length ; i++) {
   String varName = this.variables[i];

   Object varValue = null;
   try {
      if ("transient".equals(varName)) {
         varValue = "[reserved word]";
      } else {
         varValue = eval(varName);
      } 
   } catch (Exception ex) {
      varValue = "[eval exception]";
   }

   String varClass = "void";
   if ((void != varValue) && (null != varValue)) {
      varClass = varValue.getClass().getSimpleName();
   }

   if (void == varValue) {
       log.debug(varName + " = void");
   } else if (null == varValue) {
       log.debug(varName + " = null");
   } else {
       log.debug(varName + ": " + varClass + " = " + varValue);
   }
}
return;