cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Java code for user-wise report access list

Former Member
0 Likes
523

Dear All,

I have a very big requirement and I have no idea where to begin. I only have a limited experience with SAP BI's Java SDK and has mostly used it for just generating list of all reports with their folder path or list of all users in a group.

This time though I have a big ambition (or at least I think it would be a difficult one to pull off)

What I need

Is a list of all reports with all users who has access to it and the access level they have.

It needs to have following columns

Report Name, Full Report Path, User ID (and Name if possible), Access level

I am also trying to write a code for list of reports and the user groups that has to it.


What I have

I know how to retrieve the list of all reports and I know how to retrieve list of users. But what I don't know is how to connect them or to get the access level they have.

So if anyone can help me out, it would be great. It would be even more great if I could have a ready to use code! I know it is too much to ask, but as I said I am a novice to Java part and if you give me pieces, it would take me days to stitch em up and make a full code.

So if there are any kind ones out there, please help!

Thanks.


Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Likes

Hi All,

Thank you for your quick and helpful answers. I did a little research on my own and made a lot of progress. Let me share the code I am using


<%@ page import = "com.crystaldecisions.sdk.exception.SDKException,

com.crystaldecisions.sdk.occa.report.lib.ReportSDKServerException,

com.crystaldecisions.sdk.framework.*,

com.crystaldecisions.sdk.occa.infostore.*,

com.crystaldecisions.sdk.occa.report.*,

com.crystaldecisions.sdk.properties.*,

com.crystaldecisions.sdk.occa.report.application.*,

com.crystaldecisions.sdk.occa.managedreports.*,

com.crystaldecisions.sdk.occa.report.data.*,

com.crystaldecisions.sdk.plugin.desktop.user.*,

java.util.*,

java.io.*"

%>

<%

  // User Credentials

  String username = "";

  String password = "";

  String cmsname  = "";

  String authType = "";

  IEnterpriseSession enterpriseSession = null;

  writeToLog("ReportObjectID"+"%"+"ReportName"+"%"+"ReportPath"+"%"+"User/UserGroup Name"+"%"+"User/UserGroup ID"+"%"+"AccessLevel Title"+"%"+"AccessLevel ID"+"%"+"Inherited/Explicit");

  // Log onto Enterprise

  enterpriseSession = CrystalEnterprise.getSessionMgr().logon(username, password, cmsname, authType);

  IInfoStore boInfoStore = (IInfoStore)enterpriseSession.getService("", "InfoStore");

  IInfoObjects infoObjects = boInfoStore.query("Select SI_ID from CI_INFOOBJECTS where SI_KIND = 'CrystalReport' OR SI_KIND = 'Webi'");

  for(int j=0; j<infoObjects.size();j++)

  {

  IInfoObject report = (IInfoObject)infoObjects.get(j);

  String path = getInfoObjectPath(report);

  String title = report.getTitle();

  String ReportObjectID = String.valueOf(report.getID());

  ISecurityInfo2 securityInfo = report.getSecurityInfo2();

  IEffectivePrincipals effectivePrincipals = securityInfo.getEffectivePrincipals();

  Iterator CurrentObject = effectivePrincipals.iterator();

  while (CurrentObject.hasNext())

  {

  IEffectivePrincipal effectivePrincipal = (IEffectivePrincipal)CurrentObject.next();

  IEffectiveRoles effectiveRoles = effectivePrincipal.getRoles();

  Iterator roleIT = effectiveRoles.iterator();

  while (roleIT.hasNext())

  {

  IEffectiveRole effectiveRole = (IEffectiveRole)roleIT.next();

  writeToLog(String.valueOf(ReportObjectID)+"%"+title+"%"+path+"%"+effectivePrincipal.getName()+"%"+String.valueOf(effectivePrincipal.getID())+"%"+effectiveRole.getTitle()+"%"+String.valueOf(effectiveRole.getID())+"%"+Boolean.valueOf(effectiveRole.isInherited()));

  }

  }

  }

  out.println("All Done");

%>

<%!

  public static String getInfoObjectPath(IInfoObject infoobject) throws SDKException

  {

  String path = "";

  while (infoobject.getParentID() != 0)

  {

  infoobject=infoobject.getParent();

  path = "/" + infoobject.getTitle() + path;

  }

  return path;

  }

<%!

  public void writeToLog(String msg)

  {

  try

  {

  // Set up Logging File

  FileOutputStream FSout;

  PrintStream pStream; // declare a print stream object

  FSout = new FileOutputStream("C:\\TestOutput2.csv", true);  // Append

  pStream = new PrintStream(FSout);

  pStream.println(msg);

  pStream.close();

  }

  catch (IOException e)

  {

  //error writing to log

  }

  }

%>

This pretty much does all that I wanted to accomplish. Thank you again for the help.

Regards

Answers (2)

Answers (2)

DellSC
Active Contributor
0 Likes

This gets a little complicated because security can be assigned to specific users, but also to user gropus.  Also you have both Explicit Principals - user and groups that have been explicitly granted access to something - and Effective Principals - users and groups that have inherited access to something.  You also have to look at the access level and advanced rights assigned to determine whether they have access or whether the access has been taken away.

So, here's some potential logic for you:

- Get the list of users.  I would create a UserInfo class that has, at a minimum, the Title (User ID) and Full Name and put these in a HashMap<Integer, UserInfo> that has a key of the SI_ID for the user.

- Get the list of groups - I would create a GroupInfo class that has the group name and then a HashMap<Integer, UserInfo> of the users who are members of that group.  Then I would put these in a HashMap<Integer, GroupInfo> that has the SI_ID of the group as its key.

- Get a list of the Access Levels - I put these in a HashMap<Integer, String> that thas the SI_ID of the role/access level and its name.

- Get the list of reports.

     - For each report, walk through the ExplicitPrincipals (getSecurityInfo2().getExplicitPrincipals()).

     - For each ExplicitPrincipal, walk through the ExplicitRoles (getRoles())  to build a string of the access levels that are assigned (there can be multiple...)

     - If the ExplicitPrincipal is a group (found in your group hashmap), walk through the group's list of users and output the information.

     - If the ExplicitPrincipal is a user (found in your user hashmap), output the user info.

     - If there is no role assigned, walk through the list of ExplicitRights (getRights()) for the principal to make sure that the "View Object" right has been assigned.  If it has, output as above.

     - Repeat all of these steps for the EffectivePrincipals found in getSecurityInfo2().getEffectivePrincipals() to show folks who have inherited rights.

-Dell


Former Member
0 Likes

Hi,

Refer to the blog at

The blog is to get the usergroup access levels on folder. You can change the two queries in the code to

String query = "SELECT  SI_ID,SI_NAME FROM  ci_systemobjects WHERE  SI_kind='user' ";

         IInfoObjects infoobjects = iStore.query(query);

        String universeQuery = "SELECT  SI_ID,SI_NAME FROM ci_infoobjects WHERE SI_Kind='crystalreport'";

         IInfoObjects universes = iStore.query(universeQuery);

Doing so you we get users access levels for all crystal reports.

You would need to check the login in the code and construct one according to your needs.

Hope this helps.

Thanks,

Prithvi