Difference between revisions of "ASL Session removal instructions for portlets before gCube 4.2.0"

From Gcube Wiki
Jump to: navigation, search
(Getting the infrastructure Context (Scope))
Line 97: Line 97:
 
=== Getting the infrastructure Context (Scope)  ===
 
=== Getting the infrastructure Context (Scope)  ===
  
''' Please note:''' the following methods needed to get the infrastructure context work with AJAX calls (i.e. XMLHttpRequest to exchange data with a server behind the scenes) only. If you use standard http GET or POST to  exchange data with a server, you must handle the infrastructure context information differently. Please see the following page for further information read ClientContextLibrary [3] bottom of this page.
+
''' Please note:''' the following methods needed to get the infrastructure context work with AJAX calls (i.e. XMLHttpRequest to exchange data with a server behind the scenes) only. If you use standard http GET or POST to  exchange data with a server, you must handle the infrastructure context information differently. Please see the following page for further information see the [https://wiki.gcube-system.org/gcube/ClientContextLibrary gCube ClientContext Library].
  
 
* Get the '''current scope''' (a.k.a. the infrastructure context):
 
* Get the '''current scope''' (a.k.a. the infrastructure context):
Line 128: Line 128:
  
 
</source>
 
</source>
 
  
 
== Related links and references ==
 
== Related links and references ==

Revision as of 17:06, 15 November 2016

Introduction

This guide contains instructions on how to replace ASL Core component an explain how to btain the same contextual information (current user and scope) you used to retrieve from ASL Core component in an better and reliable way by exploiting the gCube Portal_Context component.

This guide assumes your portlet was developed prior to gCube 4.2.0 and already uses ASL Core component. If this is not the case, go straight to Portal_Context to understand how to get contextual information in your web application. It also assumes that you use the maven-portal-bom artifact for dependency management.

Step 1: dependencies removal

Remove the following dependencies from your pom.xml:

  • ASL Core
<dependency>
        <groupId>org.gcube.applicationsupportlayer</groupId>
	<artifactId>aslcore</artifactId>
       <scope>provided</scope>
</dependency>
  • Custom Portal Handler
<dependency>
	<groupId>org.gcube.portal</groupId>
	<artifactId>custom-portal-handler</artifactId>
	<scope>provided</scope>
</dependency>

Step 2: Portal Manager & User Management Core dependencies check

Add the following dependencies to your pom.xml (if not present already):

  • Portal Manager
<dependency>
	<groupId>org.gcube.common.portal</groupId>
	<artifactId>portal-manager</artifactId>
	<scope>provided</scope>
</dependency>
  • User Management Core
<dependency>
	<groupId>org.gcube.dvos</groupId>
	<artifactId>usermanagement-core</artifactId>
	<scope>provided</scope>
</dependency>

Step 3: Remove ScopeHelper setContext call in your portlet class doView

ScopeHelper.setContext is no longer needed, if you removed the custom-portal-handler dependency correctly your portlet class should not compile anymore. Remove the following line:

public void doView(RenderRequest request, RenderResponse response)    throws PortletException, IOException {
    ScopeHelper.setContext(request); // <-- '''REMOVE THIS LINE'''
    PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher(....);
    dispatcher.include(request, response);
}

The new doView method should look like the following (note that ScopeHelper.setContext(request) is removed) :

public void doView(RenderRequest request, RenderResponse response)    throws PortletException, IOException {
    PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher(....);
    dispatcher.include(request, response);
}

Step 4: replace any call to ASL Session with PortalContext

First, get an instance of the PortalContext by invoking the static method PortalContext.getConfiguration();

PortalContext instance = PortalContext.getConfiguration();

Getting the current User

  • Get the current username of the current user:
import org.gcube.common.portal;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
...
PortalContext pContext = PortalContext.getConfiguration();
String username = pContext.getCurrentUser(httpServletRequest).getUsername();

Getting the infrastructure Context (Scope)

Please note: the following methods needed to get the infrastructure context work with AJAX calls (i.e. XMLHttpRequest to exchange data with a server behind the scenes) only. If you use standard http GET or POST to exchange data with a server, you must handle the infrastructure context information differently. Please see the following page for further information see the gCube ClientContext Library.

  • Get the current scope (a.k.a. the infrastructure context):
import org.gcube.common.portal;
...
PortalContext pContext = PortalContext.getConfiguration();
String currentScope = pContext.getCurrentScope(httpServletRequest);
  • Get the current user token:
import org.gcube.common.portal;
...
PortalContext pContext = PortalContext.getConfiguration();
String userToken = pContext.getCurrentUserToken(httpServletRequest);
  • Get the current group id (we map VREs with Liferay groups, the groupid identifies the VRE univocally in Liferay).
import org.gcube.common.portal;
...
PortalContext pContext = PortalContext.getConfiguration();
long currGroupId = pContext.getCurrentGroupId(httpServletRequest);

Related links and references