Monday, 20 October 2014

Hide site toolbar in webpshere portal8.5 for normal users

Did you ever need to hide certain parts of the theme user experience based on a user’s access level in IBM WebSphere Portal 8.5? Or did you ever wonder how to delegate to another dynamic content spot from within an existing content spot? This article will answer your questions and demonstrate in a few simple steps how to hide the site toolbar for everybody but administrative users.
HideToolbarForNonAdmins How to show the site toolbar for administrative users only
In order to hide the site toolbar we only need to change one line within your existing theme.html and create a new dynamic content spot that executes the access control check.
  1. Create new JSP called toolbarAdmin.jsp within your theme’s WAR file with the following content. In this example we use <WAR-PATH>/themes/html/dynamicSpots/toolbarAdmin.jsp
    <%@ page session="false" buffer="none" %>
    <%@ page trimDirectiveWhitespaces="true" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@ include file="../includePortalTaglibs.jspf" %>
    <c:set var="admin" value="<%= com.ibm.portal.ac.data.RoleType.ADMIN %>" />
    <c:if test="${wp.ac[wp.selectionModel.selected].hasPermission[admin]}">
        <r:dataSource uri='dyn-cs:id:85theme_toolbar' escape="none"/>
    </c:if>
  2. Open up your existing theme_en.html, or corresponding language file if you are not using English and replace this line. The file can be found in WebDAV under the directory /themes/<YourTheme>/nls/theme_en.html
    <a rel="dynamic-content" href="dyn-cs:id:85theme_toolbar"></a>
    with this line (Please note that you need to replace the <CONTEXT-ROOT> variable with your configured context root for your WAR file)
    <a rel="dynamic-content" 
       href="res:<CONTEXT-ROOT>/themes/html/dynamicSpots/toolbarAdmin.jsp"></a>
    Note: The default WebDAV entry point for IBM WebSphere Portal is: http://<host>:10039/wps/mycontenthandler/dav/fs-type1/
  3. And that’s it!
    The easiest way to test this is by accessing your IBM WebSphere Portal web page as anonymous user, in which case the site toolbar will be hidden. Then log in as administrator. You will see that the site toolbar appears again. You can also create a new user through the ‘Sign Up’ link and then log in as this user. Since this user will only have privileged user access, he will not be able to see the site toolbar.

Recommended Extension

In above steps we took one shortcut that gets you a quick result, but is not the recommended approach since it hard codes the URI to the JSP including its context root. Within this section, we will generate a new dynamic content spot identifier that can be referenced instead by creating a new module that exposes the dynamic content spot.
An additional advantage of this approach is that you don’t need to manually figure out your own context root and hard code it in a certain place, but the system will automatically fetch that information for you and inject the correct context root during runtime. This way your module even works when you change the context root of your application.
In order to achieve the new approach we need to change the theme.html file again, and create an new file called plugin.xml within your WAR files WEB-INF folder.


  1. Open up your existing theme_en.html, or corresponding language file if you are not using English and replace this line. The file can be found in WebDAV under the directory /themes/<YourTheme>/nls/theme_en.html
    <a rel="dynamic-content" 
       href="res:<CONTEXT-ROOT>/themes/html/dynamicSpots/toolbarAdmin.jsp"></a>
    with this line
    <a rel="dynamic-content" href="dyn-cs:id:sampleToolbarForAdminsOnly"></a>
  2. Create a new plugin.xml file or open you existing one within your theme’s WAR file WEB-INF folder. The following content shows the full plugin.xml content. Please use only the extension-element part if you already have a plugin.xml.
    <?xml version="1.0" encoding="UTF-8"?>
    <plugin id="sample_toolbarForAdminsOnly" name="Sample" provider-name="IBM" version="1.0.0">
      <extension id="sample_toolbarForAdminsOnly" 
                 point="com.ibm.portal.resourceaggregator.module">
        <module id="sample_toolbarForAdminsOnly">
          <contribution type="dyn-cs">
            <sub-contribution type="markup" ref-id="sampleToolbarForAdminsOnly">
              <uri value="res:{war:context-root}/themes/html/dynamicSpots/toolbarAdmin.jsp"/>
            </sub-contribution>
          </contribution>
        </module>
      </extension>
    </plugin>
  3. Lastly, in order for the theme to pick up your dynamic content spot, we have to add that module with the id ‘sample_toolbarForAdminsOnly’ to your profiles. In this example we are extending the deferred profile which can be found in WebDAV under the directory /themes/<YourTheme>/profiles/profile_deferred.json
    ...
    "moduleIDs": [
        "getting_started_module",
        "wp_theme_portal_85",
        "wp_dynamicContentSpots_85",
        "sample_toolbarForAdminsOnly",
        "wp_toolbar_host_view",
        "wp_portlet_css",
        "wp_one_ui",
        "wp_one_ui_dijit",
        "wp_client_ext",
        "wp_status_bar",
        "wp_theme_menus",
        "wp_theme_skin_region",
        "wp_theme_high_contrast",
        "wp_layout_windowstates",
        "wp_portal",
        "wp_analytics_aggregator",
        "wp_oob_sample_styles",
        "wp_ic4_wai_resources",
        "wp_worklight_ext",
        "wp_social_rendering_85",
        "wp_sametime_proxy"
    ],
    ...
  4. Before we can test everything you need to invalidate the theme caches by clicking the Administration menu icon in the toolbar. Then, click Portal Analysis > Theme Analyzer > Utilities Control Center > Invalidate cache.

No comments:

Post a Comment

Custom single threaded java server

 package com.diffengine.csv; import java.io.*; import java.net.*; import java.util.Date; public class Server { public static void main(Str...