The World's Most Widely Used Business Intelligence Software
0

How to Set Role-Based JasperReports Server Home Pages

Introduction

This tutorial shows how to specify a dashboard as a user's home page. The dashboard is visible immediately after logging in to JasperReports Server, and provides a role-based "information cockpit" that helps users make better and faster business decisions.

Product Versions

This tutorial is written for JasperReports Server version 4.0 and later, and requires only slight edits to work in v3.x.

User:  Developer

Objectives

This guide will show you how to:

Pre-Requisites

  • The SuperMart sample data must be installed to follow this tutorial
  • You need a basic understanding of JasperReports Server, how to create dashboards, and role-based authorization
    • For additional details, please refer to the JasperReports Server Pro User Guide located in the jasperreports-server-4.x\docs folder
  • To specify a dashboard as a role's home page, you need write permission to the JasperReports Server web application folder
  • A basic understanding of JSP and HTML iFrames is helpful, but not required

 

Creating a Test Role and User

For this tutorial, you will create a test role and user, and grant the test user read privileges to the SuperMart demo folder.

Step Action
1

Create a new role.

  1. Log in to JasperReports Server as jasperadmin (or the administrator of the organization for which you are creating the new role-based home page).
  2. From the main menu select Manage > Roles.
  3. In the Organizations column, left-click the organization name to select it.
  4. In the center Roles column, click the Add Role button.
  5. Enter ROLE_TEST and click the Add Role to... button.

             Result: The new role is added in the Roles section

2

Grant ROLE_TEST read access to the SuperMart samples.

  1. From the main menu select View > Repository.
  2. Expand the Organization folder.
  3. Right-click on the SuperMart Demo folder name and select Permissions from the context menu.
  4. Assign Read Only access to ROLE_TEST and click OK.
3

Create a new Test User.

  1. Select Manage > Users.
  2. In the Organizations column, select the organization name.
  3. In the center Users column, click the Add User button and enter
    • User name: Test User
    • User ID: the system fills in Test_User (change to any value you like; you'll log in with this User ID)
    • Email: enter any valid email address
    • Password: test (you'll log in with this password)
  4.   Make sure the User is enabled box is checked.
  5. Click the Add User to... button.

Result: Your new Test User appears in the Users section.

4

Associate Test User with ROLE_TEST:

  1. In the Users column, make sure your new user name is selected.
  2. At the lower right, click the Edit button.
  3. Near the bottom of the Properties column, move ROLE_TEST from Roles Available to Roles Assigned and click the Save button.
  4. Click Save in the Details section.

Return to top

 

Identifying the Dashboard URI

The following steps assure that target users (in this case, Test User) can access the dashboard. 

Note: The dashboard URI will be different for superuser than for organization users, including jasperadmin, because superuser has root access to the repository. Superuser's URI path to any resource includes the top-level root/organizations directories.

To make sure the URI you select is accessible by the target users, you need to first emulate the target user.

Step Action
1
  1. From the Manage Users page, ensure that  Test User is selected.
  2. At the lower right, click the Login as User button.

Notice your login id in the upper-right corner:  jasperadmin user as Test User.
 

2

Open the dashboard you want to include on the new home page:

  1. From the main menu select View > Repository.
  2. Expand the Organization folder and select the SuperMart Demo folder.
  3. At the right, click on SuperMart Dashboard to open the dashboard.

Result: The dashboard opens

3

Copy the URL from the web browser address bar to a text editor.

Example: _http://localhost:8081/jasperserver-pro/flow.html?_flowId=dashboardRuntimeFlow&dashboardResource=/supermart/SupermartDashboard30

4
  1. Identify the dashboard’s URI, located after &dashboardResource=
    • Example: /supermart/SupermartDashboard30
  2. Copy this URI to the clipboard.
5 In JasperReports Server, click the Log Out link at the upper right to return to jasperadmin view.

Return to top

 

Editing a Role-Based Home Page

A role-based home page requires you to reference the dashboard in a JSP file. You then assign this new homeFor<Role>.jsp file to the role you created earlier. You need a text editor and write access to the application server to complete this step.  

Step Action
1
  1. Find the JSP home directory on the application server.
    • Windows example:
      c:\jasperreports-server-4.1\apache-tomcat\webapps\jasperserver-pro\WEB-INF\jsp\modules\home
    • Linux example:
      /opt/jasperreports-server-4.1/apache-tomcat/webapps/jasperserver-pro/WEB-INF/jsp/modules/home

Copy the file homeForDemo.jsp and rename it homeForTest.jsp.

2
  1. Open homeForTest.jsp in a text editor.
  2. Scroll down to the iFrame section (near line 22).
    • Notice the line starting with src=
    • The dashboardResource value is the URI of the dashboard you identified in Step 4 above. 
    • For this tutorial, leave it as-is. If you wish to point to a different dashboard, substitute that dashboard’s correct URI as shown here (the URI ends with the Resource ID):

           src="${pageContext.request.contextPath}/flow.html?_flowId=
dashboardRuntimeFlow&amp;dashboardResource=/supermart/Supermart_Dashboard_Redux&
decorate=no&hidden_isJasperAnalysis=<%=LicenseManager.getInstance()
.checkLicense()&&LicenseManager.getInstance().isProductFeatureSupported
(LicenseManager.ANALYSIS_FEATURES)?"true":"false"%>">

Save the file to the jsp/ modules/ home directory. You now have a new home page available!

3

Assign the new home page to a role:

  1. Open home.jsp in a text editor.
  2. Add a new ifAllGranted block for ROLE_TEST, and edit the ifNotGranted block to reflect the following. (Note: in this tutorial we added ROLE_TEST to the default organization, whose Resource ID is organization_1):
     

<authz:authorize ifAllGranted="ROLE_DEMO">
    <%@ include file="homeForDemo.jsp" %>
</authz:authorize>

<authz:authorize ifAllGranted="ROLE_TEST|organization_1"> 
   <jsp:include page="homeForTest.jsp"/> 
</authz:authorize>

<authz:authorize ifNotGranted="ROLE_DEMO">
   <authz:authorize ifNotGranted="ROLE_TEST|organization_1">
      <jsp:include page="homeForNonDemo.jsp"/>
   </authz:authorize>
</authz:authorize>

4

Save the file, and you are done! Log in as your target user and  the dashboard should appear the user’s home page.

Return to top

What's Next?

For further details on individual and customized dashboards please refer to:

  • Spring Security here.  
  • Java Server Pages here.

Written by

This tutorial was written by Kerstin Klein, Professional Services Consultant; and Mary Flynn, Sales Engineer Manager; in June 2009. It was updated for v4.1 by Curtis Stallins with direction from Matt Geise in June 2011.