Getting error while fetching the link accounts from an identity

Hi All,

I have written a code to fetch all the JDBC link account from an identity, but getting the below error… any help is appreciated.

here is my code,

Here is the error which I am getting,

Hi @shiva_shankar13,

you are casting an list into a string. In this case I think, permission attribute is a multivalue attribute and when yuo do a getAttribute of a multivalued attribute, SP return a list.

You can resolve checking with instanceof or put it in a generic object.

Also, if you want to check all the account of all JDBC application, you must change the first if; now you are checking the account for an application called “JDBC”

Hi @shiva_shankar13,

Check the persmission attribute properties in account schema. If it is multi valued, it will return the List.

If you know the identity and application. you can use the IdentityService to get the link attributes. Please refer the code.

import sailpoint.object.*;
import sailpoint.api.IdentityService;
                     
					 List permissionList;
                     Identity id = context.getObject(Identity.class, "Susan.Martin");
	                 if(null != id){
	                 
		                IdentityService is = new IdentityService(context);
		                Application appName = context.getObject(Application.class, "JDBC");
		                List Links = is.getLinks(id,appName);
	                    if(null != adLinks){
                    
                           for (Link linkObj : Links) {
								
								permissionList = linkObj.getAttribute("permission");
                                return permissionList; 
	                		} 
							}
							}

Regards,
Arun

@shiva_shankar13
If you are not sure of the return type please add a check and I believe you are expecting the permission in a String

Add a import statement
import sailpoint.tools.Util;

Object permissionObj=link.getAttribute("permission");

String permission="";

if(permissionObj instanceof List)
permission=Util.listToCsv((List)permissionObj);
else if(permissionObj instanceof String)
permission=(String)permissionObj;
1 Like

Hi @iamksatish , Getting the same exception even after adding this code.


@shiva_shankar13

The code I shared has to be within for loop of the code you shared

Identity id = context.getObject(Identity.class, "Susan.Martin");
	                 if(null != id){
	                 
		                IdentityService is = new IdentityService(context);
		                Application appName = context.getObject(Application.class, "<Your app Name>");
		                List Links = is.getLinks(id,appName);
  for (Link linkObj : Links) {
Object permissionObj=link.getAttribute("permission");

String permission="";

if(permissionObj instanceof List)
permission=Util.listToCsv((List)permissionObj);
else if(permissionObj instanceof String)
permission=(String)permissionObj;

}
}

As observed by others, root cause in your code is that identity.getLinks() returns list of Links not single Link.
As posted by others you can use IdentityService to get that one link (even though you can still get multiple links for single application).
So the code by @shiva_shankar13 deals with that.

@iamksatish , Thank you so much, this worked.

image

@iamksatish , can you please let me know what you are doing in this line? The one which is highlighted.

Thanks

@shiva_shankar13
We are converting to comma separated string , if the values are in list

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.