ClassCastException into WorkflowScriptMethods sample.

book

Article ID: 8052

calendar_today

Updated On:

Products

CA Identity Manager CA Identity Governance CA Identity Portal CA Risk Analytics CA Secure Cloud SaaS - Arcot A-OK (WebFort) CLOUDMINDER ADVANCED AUTHENTICATION CA Secure Cloud SaaS - Advanced Authentication CA Secure Cloud SaaS - Identity Management CA Secure Cloud SaaS - Single Sign On

Issue/Introduction

This issue came for IM r14.1 with a custom workpoint code involved in a custom workpoint process triggered by an admin modify user task.

This could be reproduced using the OOTB

"IAM Suite\Identity Manager\tools\samples\WorkflowContext\ApprovalDecision\WorkflowScriptMethods.java"
triggered by the provided two OOTB scripts: "Is manager" and "Is not manager".

<Please see attached file for image>

IsManager.png

<Please see attached file for image>

IsNotManager.png

 

You can customize a simple WP process based on the OOTB SingleStepApproval one, by just adding an unconditional node after the Start point with the 2 transitions "Is manager" (com.ca.identitymanager.samples.WorkflowScriptMethods.approvalNotRequired) and
"Is not manager" (com.ca.identitymanager.samples.WorkflowScriptMethods.approvalRequired).

<Please see attached file for image>

MyWPprocess.jpg

If you set the workflow process to be involved by instance at the modify user event level then no issue.


If you set the workflow process to be involved at the Admin task level as following then you get the issue:

<Please see attached file for image>

TaskLevelConfig.jpg

<Please see attached file for image>

TaskLevelDefinition.jpg
The following statement:
User user = ((UserEvent)evt).getUser();
fails with:
java.lang.ClassCastException: com.netegrity.ims.events.IMTaskEvent cannot be cast to com.netegrity.imapi.UserEvent

When the workflow process is involved at the Admin task level, the original part of problematic code is as following:

IMEvent evt= workflowContext.getEvent();
User user = ((UserEvent)evt).getUser();
String title = user.getAttribute("title");

 

Cause

The following code line:

IMEvent evt= workflowContext.getEvent();
does not retrieve an instance of UserEvent in our case but an instance of IMTaskEvent.

This explains why the following code line:

User user = ((UserEvent)evt).getUser();

fails with java.lang.ClassCastException: com.netegrity.ims.events.IMTaskEvent cannot be cast to com.netegrity.imapi.UserEvent.

Environment

Observed with IM r12.6.X and r14.1.0.

Resolution

The goal is to retrieve the managed user object when the instance is of an IM task or in other terms when the workflow process is involved at the task level instead of at the event level.

The original following 2 lines in the sample code:

User user = ((UserEvent)evt).getUser();
String title = user.getAttribute("title");

need to be replaced by the following code:
 User user = null;
 String title = null;
 ManagedObject mo = null;
  if(evt instanceof UserEvent)
  {
   user = ((UserEvent)evt).getUser();
   title = user.getAttribute("title");
  }
  else if(evt instanceof IMTaskEvent)
  {
   mo = ((IMTaskEvent)evt).getPrimaryManagedObject();
   if(mo.get("title") != null && !mo.get("title").equals(""))
   {
    title = (String) mo.get("title");
   }
  }

 

Based on our WorkflowScriptMethods.java sample this change needs to be done twice in both approvalRequired and approvalNotRequired methods.

Attachments

1558700172417000008052_sktwi1f5rjvs16oy6.jpeg get_app
1558700170519000008052_sktwi1f5rjvs16oy5.jpeg get_app
1558700168699000008052_sktwi1f5rjvs16oy4.jpeg get_app
1558700166830000008052_sktwi1f5rjvs16oy3.png get_app
1558700165000000008052_sktwi1f5rjvs16oy2.png get_app