Restrict Menu items by Role in Jasper Server

We can use role-based customizations to control access to menus. The example here shows how to control access to menu items.

In this example scenario, we wish to hide Create Report, Dashboard, Domain & Data Source from roles other then ROLE_ADMINISTRATOR and ROLE_HRIS. So, these menu items would only be accessible to ROLE_ADMINISTRATOR and ROLE_HRIS.

Steps:

  • Edit the file <js-webapp>/WEB-INF/actionModel-navigation.xml. The actionModel for Create > Ad Hoc View is near the end of the file.
 <context name="main_create_mutton" test="isProVersion">
  <condition test="!banUserRole">
    <condition test="!isMainFeaturesDisabled">
        <selectAction labelKey="NAV_005_CREATE">
        
        
            <condition test="isAvailableProFeature" testArgs="AHD">
                <option labelKey="NAV_051_ADHOC_REPORT" action="primaryNavModule.navigationOption"
                        actionArgs="designer"/> 
                        
                <condition test="checkAuthenticationRoles" testArgs="ROLE_ADMINISTRATOR,ROLE_HRIS|organization_1">
                <option labelKey="NAV_057_REPORT" action="JRS.CreateReport.selectADV"
                        actionArgs="createReport"/>
                </condition>
            
            </condition>
            
            <condition test="isSupportedDevice">
                <condition test="isAvailableProFeature" testArgs="DB">
                <condition test="checkAuthenticationRoles" testArgs="ROLE_ADMINISTRATOR,ROLE_HRIS|organization_1">
                    <option labelKey="NAV_050_DASHBOARD" action="primaryNavModule.navigationOption"
                            actionArgs="dashboard"/>
                </condition>
                </condition>
                
                <condition test="isAvailableProFeature" testArgs="AHD">
                    <condition test="checkAuthenticationRoles" testArgs="ROLE_ADMINISTRATOR,ROLE_HRIS|organization_1">
                        <option labelKey="NAV_056_DOMAIN" action="primaryNavModule.navigationOption"
                                actionArgs="domain"/>
                        <option labelKey="NAV_058_DATA_SOURCE" action="primaryNavModule.navigationOption"
                                actionArgs="dataSource"/>
                    </condition>
                </condition>
                
            </condition>
        </selectAction>
    </condition>
  </condition>
</context>


  • Save the file after making changes.
  • Restart Jasper server.
  • Login as user with role other than ROLE_ADMINISTRATOR and ROLE_HRIS. You can see that the menu item to Create Report, Dashboard, Domain & Data Source is removed, and user can only see Create Ad-hoc view as menu item. Log out and log back in as admin or HRIS user. All menu items are visible to administrators and HRIS user.

Note:

In commercial editions, you must specify the role’s organization ID when restricting access to roles defined in an organization. There are three ways to specify a role in the commercial edition:

  • ORG_ROLE|orgID – Explicitly specify a role belonging to an organization
  • ORG_ROLE|* – Match the role name in any organization in the user’s scope (parent organizations and root).
  • SYSTEM_ROLE – Explicitly specify a role defined at the root or system level, such as ROLE_ADMINISTRATOR.

Leave a Reply