ASL Session removal instructions for portlets before gCube 4.2.0

From Gcube Wiki
Revision as of 18:37, 15 November 2016 by Massimiliano.assante (Talk | contribs) (Introduction)

Jump to: navigation, search

Introduction

GCube-Social-Cloud.png

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();

Please Note: pContext.getCurrentUser(httpServletRequest) returns an instance of GCubeUser from which you can get other user information such name, email etc.

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);

Step 5: Remove Session Checker Widget dependency

Session Checker Widget is based on the ASL Session, therefore it must be removed if you removed the ASL Session as it will not work. The session checking in gCube 4.2.0 is performed for you at portal level, see screenshot below for an example.

Session-checker-portal.png

Getting the Portal Context in your IDE (Development)

The client context relies on Liferay.ThemeDisplay javascript object, which obviously is not available if you run your application outside the gCube portal. To overcome this limitation and allow developers to test their applications in any IDE (e.g. Eclipse), you can configure a property file on your development machine containing the context information you need for development purposes.

The name of the file must be gcube-dev-context.properties, and must be placed under an environment variable defined in the run configuration on your IDE called GCUBE_DEV_HOME. The PortalManager will recognize if the application is running on an actual gateway or on an IDE and, in the latter case, retrieves and uses the information written in this file for your application.

# ONLY FOR LOCAL (IDE) DEVELOPMENT - NOT FOR PRODUCTION USE!
# Place this file under $GCUBE_DEV_HOME/ note that the environment variable GCUBE_DEV_HOME must be set on your IDE
# change the properties with your user data and desired scope / token
 
# a development user 
user.username=test.user
user.name=aTestName
user.lastname=aTestLastName
user.email=testing.user@gcube-system.org
 
# a development scope (the scope must be bound to the token below)
development.context=/gcube/devsec/devVRE
development.groupname=devVRE
development.groupid=-1
 
# a valid user token on the (above) development scope.
# you can obtain it by registering on one development VRE and using Token Generator portlet
user.token= ....


Example of GCUBE_DEV_HOME environment variable in a web application Running Configuration on the Eclipse IDE

GCUBE DEV HOME.png

Related links and references