0% found this document useful (0 votes)
40 views5 pages

BSDG 3 - Listing Objects in Namespace at Runtime - Compass

The document provides guidance on using Bean Shell in IdentityIQ to list all variables available in the script's context at runtime. It explains how to access the 'this.variables' array and includes sample code to handle Java reserved words that may conflict with variable names. The output examples demonstrate how the script can be utilized to debug and understand the variables in use during execution.

Uploaded by

ag55807
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views5 pages

BSDG 3 - Listing Objects in Namespace at Runtime - Compass

The document provides guidance on using Bean Shell in IdentityIQ to list all variables available in the script's context at runtime. It explains how to access the 'this.variables' array and includes sample code to handle Java reserved words that may conflict with variable names. The output examples demonstrate how the script can be utilized to debug and understand the variables in use during execution.

Uploaded by

ag55807
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

7/31/22, 11:11 AM BSDG 3 - Listing Objects in Namespace at Runtime - Compass

Compass  Products  IdentityIQ  Technical White Papers  BSDG 3 - Listing Objects in Namespace at Runtime

BSDG 3 - Listing Objects in Namespace at Runtime  


Previous | Contents | Next

IdentityIQ has several hundred places where Bean Shell code can be executed in the product. It can be confusing to try to
remember what objects IdentityIQ passes into a block of Bean Shell code at runtime. The details for what object(s) are
passed are covered in documentation, but this documentation can quickly end up out of date. Bean Shell provides a
reference to a "this" variable that is in context in all running instances of Bean Shell code. There is a "this.variables" field that
is an array of all variables that are declared and defined in the script's context. Using this feature of Bean Shell we can
create a code block that will list all of the variables defined for a script to use at run time.

The following code illustrates an example of how to reverse engineer what variables are in context during Bean Shell
execution:

https://community.sailpoint.com/t5/tkb/articleprintpage/tkb-id/White_papers/article-id/43 1/5
7/31/22, 11:11 AM BSDG 3 - Listing Objects in Namespace at Runtime - Compass

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

Logger log = Logger.getLogger("sailpoint.services.bshdemo");


// TODO: Remove this forced log level set before checking in this Rule.
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();

https://community.sailpoint.com/t5/tkb/articleprintpage/tkb-id/White_papers/article-id/43 2/5
7/31/22, 11:11 AM BSDG 3 - Listing Objects in Namespace at Runtime - Compass

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

On lines 11 and 13 we can see the references to this.variables for retrieving what variables exist in context.

The logic on lines 17-19 address an issue with calling Bean Shell's eval() method on variable names that shadow a Java
reserved word. The "transient" keyword is a reserved word in Java but is a valid workflow variable in IdentityIQ's workflow
language. If a workflow variable collides with any Java reserved word in the namespace, then calling Bean Shell's eval()
results in an error. The fix is to add keyword-specific traps like the example in the for loop. This is usually only a problem
when examining IdentityIQ workflow variables and the "transient" keyword is one such instance that causes difficulty.

On line 20 we use Bean Shell's eval() function to retrieve the value of the variable. In Bean Shell values can be void, null, or a
valid reference to a Java object in memory. On lines 26-29 we retrieve the class name for the variable, assuming it has
one. And finally on lines 31-37 we log the variable, its class name, and its value if one can be retrieved as a string.

When run from the IIQ console this script produces the following sample output:

https://community.sailpoint.com/t5/tkb/articleprintpage/tkb-id/White_papers/article-id/43 3/5
7/31/22, 11:11 AM BSDG 3 - Listing Objects in Namespace at Runtime - Compass

> rule "Bean Shell Dev Guide - 015 Show Objects In Context"
2015-01-20 10:18:27,837 DEBUG main sailpoint.services.bshdemo:? - Listing Variables passed to Beanshell namespace:
2015-01-20 10:18:27,840 DEBUG main sailpoint.services.bshdemo:? - bsf: BSFManager = org.apache.bsf.BSFManager@45a98c98
2015-01-20 10:18:27,840 DEBUG main sailpoint.services.bshdemo:? - log: Logger = org.apache.log4j.Logger@65bbf773
2015-01-20 10:18:27,840 DEBUG main sailpoint.services.bshdemo:? - bsh: This = 'this' reference to Bsh object: NameSpac
2015-01-20 10:18:27,840 DEBUG main sailpoint.services.bshdemo:? - context: InternalContext = sailpoint.server.Internal
>

When run from inside a Customization Rule on a JDBC Application during account aggregation, this script produces the
following sample output:

2015-01-20 10:19:34,688 DEBUG QuartzScheduler_Worker-3 sailpoint.services.bshdemo:? - Listing Variables passed to Bean


2015-01-20 10:19:34,689 DEBUG QuartzScheduler_Worker-3 sailpoint.services.bshdemo:? - bsf: BSFManager = org.apache.bsf
2015-01-20 10:19:34,689 DEBUG QuartzScheduler_Worker-3 sailpoint.services.bshdemo:? - connector: JDBCConnector = sailp
2015-01-20 10:19:34,689 DEBUG QuartzScheduler_Worker-3 sailpoint.services.bshdemo:? - application: Application = sailp
2015-01-20 10:19:34,689 DEBUG QuartzScheduler_Worker-3 sailpoint.services.bshdemo:? - log: Logger = org.apache.log4j.L
2015-01-20 10:19:34,689 DEBUG QuartzScheduler_Worker-3 sailpoint.services.bshdemo:? - bsh: This = 'this' reference to
2015-01-20 10:19:34,689 DEBUG QuartzScheduler_Worker-3 sailpoint.services.bshdemo:? - context: InternalContext = sailp
2015-01-20 10:19:34,690 DEBUG QuartzScheduler_Worker-3 sailpoint.services.bshdemo:? - state: HashMap = {}
2015-01-20 10:19:34,690 DEBUG QuartzScheduler_Worker-3 sailpoint.services.bshdemo:? - locked: String = Y

2015-01-20 10:19:34,690 DEBUG QuartzScheduler_Worker-3 sailpoint.services.bshdemo:? - status: String = A


2015-01-20 10:19:34,690 DEBUG QuartzScheduler_Worker-3 sailpoint.services.bshdemo:? - object: ResourceObject = sailpoi

https://community.sailpoint.com/t5/tkb/articleprintpage/tkb-id/White_papers/article-id/43 4/5
7/31/22, 11:11 AM BSDG 3 - Listing Objects in Namespace at Runtime - Compass

If you are curious or need to identify what variables are in context in your Bean Shell code, then this block can be very
helpful when developing new code in the field.

Previous | Contents | Next

Attachments

 Rule-BSDevGuide-003-HelloWorld-With-Logging.xml.zip 

 24 Kudos

https://community.sailpoint.com/t5/tkb/articleprintpage/tkb-id/White_papers/article-id/43 5/5

You might also like