InetSoft Product Documentation: Building a Custom Report Tree

A custom representation of the report repository (list of deployed reports) for a given user can be created using a JSP page or servlet. It is assumed that the user has been signed-on into the reporting server with a valid session. To make certain API calls, it is necessary to obtain the repository list for the given user.

demo
Read how InetSoft saves money and resources with deployment flexibility.

JSP Servlet

<HTML>
 <HEAD>
 <TITLE>Replet List</TITLE>
 <% inetsoft.sree.security.SRPrincipal principal = (inetsoft.sree.security.SRPrincipal) 
  session.getAttribute(inetsoft.sree.RepletRepository.PRINCIPAL_COOKIE);
  inetsoft.sree.AnalyticRepository repository =        (inetsoft.sree.AnalyticRepository) 
  inetsoft.sree.SreeEnv.getRepletRepository();
  inetsoft.sree.RepositoryEntry[] entries = repository.getReplets(principal, "r");
 %>
 </HEAD>
 <BODY>
 <% for(int i=0; i<entries.length; i++){
 %> <a href="http://hostname/sree/Reports?
 op=Replet&name=<%=entries[i].getName()%>"
 > 
<%=entries[i].getName()%> 
</a><br> 
<% } %> 
</BODY> 
</HTML>

The resulting code will display a list of reports for which the user and/or his roles have read permissions.

Get/Set Custom User Session Properties

It is often desirable to set certain custom properties for a user session. These properties are external to Style Intelligence, but may be accessed within the Style Intelligence environment. You can also change certain Style Intelligence-specific session properties on the fly.

Although properties can be set through the HttpSession object, it is highly recommended that you access properties using the SRPrincipal object associated with the user session. You can access the SRPrincipal object from within the script of a report as well as from a VPM.

Accessing SRPrincipal in Custom JSP/Servlets

The SRPrincipal object can be accessed from the HttpSession object within a custom JSP or Servlet. You can add or set the properties of the SRPrincipal object using the setProperty() method.

<%@ page import="inetsoft.sree.security.*, inetsoft.sree.RepletRepository" %>
 <%
 SRPrincipal p;
 p = (SRPrincipal) session.getAttribute(RepletRepository.PRINCIPAL_COOKIE);
 if(p == null) {
    p = new SRPrincipal();
 }
   // setting a custom property
 p.setProperty("property_name", "property_value");
   // setting the locale using the locale string
 p.setProperty(SRPrincipal.LOCALE, "en_US");
   session.setAttribute(RepletRepository.PRINCIPAL_COOKIE, p);
 %>

Accessing SRPrincipal in Report & VPM Script

You can access the SRPrincipal object within VPM trigger scripts and report scripts (in the onLoad and onInit handlers, or in element-level script).

var p = parameter['__principal__']; 
// Getting the SRPrincipal properties
p.getProperty(inetsoft.sree.security.SRPrincipal.LOCALE); 

Use Case: Simulating User Sessions

The example presented here will provide administrative users the ability to simulate different user sessions without explicitly logging in as that user.

The administrator would login to the InetSoft server, and access a custom JSP page which sets custom properties on the SRPrincipal object. See Accessing SRPrincipal in Custom JSP/Servlets for more details.

 inetsoft.sree.security.SRPrincipal p =
 (inetsoft.sree.security.SRPrincipal)session.getAttribute
 (inetsoft.sree.RepletRepository.PRINCIPAL_COOKIE);

 // setting a custom property 
 p.setProperty("sim_user", "david");

These custom properties can be accessed within the script of a VPM and used to set a user/role based filtering parameter defined in the 'Conditions' tab of the VPM.

VPM Lookup Trigger:

   var p = parameter['__principal__'];
   if(!isNull(p)) {
    parameter['usr'] = p.getProperty("sim_user"); 
   }