Added Weblet support

master
Massimiliano Assante 2 years ago
parent ca364579c1
commit 1222051250

@ -1,53 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="VREApp-Integration-portlet">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<property name="context-root" value="VREApp-Integration-portlet"/>
<property name="java-output-path" value="/VREApp-Integration-portlet/target/classes"/>
</wb-module>

@ -1,9 +1,13 @@
# Changelog for VRE Definition Portlet
# Changelog for VRE App Integration Portlet
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1.2.0-SNAPSHOT] - 2022-02-18
- Added Weblet support
## [v1.1.0] - 2021-07-13
- Ported to git

@ -14,7 +14,7 @@
<artifactId>VREApp-Integration-portlet</artifactId>
<packaging>war</packaging>
<name>VREApp-Integration-portlet Portlet</name>
<version>1.1.0</version>
<version>1.2.0-SNAPSHOT</version>
<properties>
<distroDirectory>${project.basedir}/distro</distroDirectory>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -35,7 +35,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>3.6.3</version>
<version>3.6.3-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -89,6 +89,10 @@
<artifactId>portal-manager</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>oidc-library-portal</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-scope-maps</artifactId>
@ -146,7 +150,6 @@
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-service</artifactId>
<version>${liferay.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
@ -164,7 +167,6 @@
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>util-java</artifactId>
<version>${liferay.version}</version>
<scope>provided</scope>
</dependency>
<dependency>

@ -1,93 +0,0 @@
package org.gcube.portlets.user;
import java.io.IOException;
import java.util.Base64;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.servlet.http.HttpServletRequest;
import org.gcube.common.portal.PortalContext;
import org.gcube.oidc.rest.JWTToken;
import org.gcube.portal.oidc.lr62.OIDCUmaUtil;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.util.PortalUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;
import okhttp3.*;
/**
* Portlet implementation class ExtAppManager
*/
public class ExtAppManager extends MVCPortlet {
private static com.liferay.portal.kernel.log.Log _log = LogFactoryUtil.getLog(ExtAppManager.class);
final String D4S_BOOT_URL = "https://d4science-cdn.nubisware.cloud/d4s-cdn/visuals/d4s-boot";
final String EXT_APP_MANAGER_URL = "https://d4science-cdn.nubisware.cloud/d4s-cdn/visuals/ext-app-manager";
public static final String D4S_BOOT_ATTR = "d4s-boot-div";
public static final String EXT_APP_MANAGERATTR = "ext-app-div";
@Override
public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, IOException {
JWTToken umaToken = null;
try {
String username = PortalUtil.getUser(renderRequest).getScreenName();
HttpServletRequest httpReq = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(renderRequest));
String context = getCurrentContext(renderRequest);
umaToken = OIDCUmaUtil.getUMAToken(httpReq, username, context);
} catch (Exception e) {
e.printStackTrace();
}
String token = umaToken.getAccessTokenString();
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(D4S_BOOT_URL)
.addHeader("cache-control", "no-cache")
.addHeader("Authorization", "Bearer " + token)
.build();
Call call = client.newCall(request);
Response response = call.execute();
String d4sBootDIV = response.body().string();
String encodedSd4sBootDIV = Base64.getEncoder().encodeToString(d4sBootDIV.getBytes());
renderRequest.setAttribute(D4S_BOOT_ATTR, encodedSd4sBootDIV);
request = new Request.Builder()
.url(EXT_APP_MANAGER_URL)
.addHeader("cache-control", "no-cache")
.addHeader("Authorization", "Bearer " + token)
.build();
call = client.newCall(request);
response = call.execute();
String extAppDIV = response.body().string();
String encodedextAppDIV = Base64.getEncoder().encodeToString(extAppDIV.getBytes());
renderRequest.setAttribute(EXT_APP_MANAGERATTR, encodedextAppDIV);
super.render(renderRequest, renderResponse);
}
public static String getCurrentContext(RenderRequest request) {
long groupId = -1;
try {
groupId = PortalUtil.getScopeGroupId(request);
return getCurrentContext(groupId);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static String getCurrentContext(long groupId) {
try {
PortalContext pContext = PortalContext.getConfiguration();
return pContext.getCurrentScope(""+groupId);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

@ -0,0 +1,41 @@
package org.gcube.portlets.user.weblet;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.PortletPreferences;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.portlet.DefaultConfigurationAction;
public class WebletConfigurationAction extends DefaultConfigurationAction {
private static Log _log = LogFactoryUtil.getLog(WebletConfigurationAction.class);
@Override
public void processAction(
PortletConfig portletConfig, ActionRequest actionRequest,
ActionResponse actionResponse) throws Exception {
super.processAction(portletConfig, actionRequest, actionResponse);
PortletPreferences prefs = actionRequest.getPreferences();
String bootURL = prefs.getValue("bootURL", "true");
String managerURL = prefs.getValue("managerURL", "true");
String iamClientId = prefs.getValue("iamClientId", "true");
_log.debug("bootURL = " + bootURL + " in PublicWebappConfigurationAction.processAction().");
_log.debug("managerURL = " + managerURL + " in PublicWebappConfigurationAction.processAction().");
_log.debug("iamClientId = " + iamClientId + " in PublicWebappConfigurationAction.processAction().");
}
@Override
public String render(PortletConfig portletConfig,
RenderRequest renderRequest, RenderResponse renderResponse)
throws Exception {
return "/html/extappmanager/config.jsp";
}
}

@ -0,0 +1,108 @@
package org.gcube.portlets.user.weblet;
import java.io.IOException;
import java.util.Base64;
import javax.portlet.PortletException;
import javax.portlet.PortletPreferences;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.servlet.http.HttpServletRequest;
import org.gcube.common.portal.PortalContext;
import org.gcube.oidc.rest.JWTToken;
import org.gcube.portal.oidc.lr62.OIDCUmaUtil;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.util.PortalUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;
import okhttp3.*;
/**
* Portlet implementation class WebletManager
*/
public class WebletManager extends MVCPortlet {
private static com.liferay.portal.kernel.log.Log _log = LogFactoryUtil.getLog(WebletManager.class);
//final String D4S_BOOT_URL = "https://cdn.dev.d4science.org/visuals/d4s-cdn/d4s-boot";
//final String EXT_APP_MANAGER_URL = "https://cdn.dev.d4science.org/visuals/d4s-vre-manager/ext-app-manager?app=_myextapp";
public static final String D4S_BOOT_ATTR = "d4s-boot-div";
public static final String EXT_APP_MANAGERATTR = "ext-app-div";
@Override
public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, IOException {
PortletPreferences portletPreferences = renderRequest.getPreferences();
String D4S_BOOT_URL = GetterUtil.getString(portletPreferences.getValue("bootURL", StringPool.BLANK));
String WEBLET_MANAGER_URL = GetterUtil.getString(portletPreferences.getValue("managerURL", StringPool.BLANK));
String IAM_CLIENTID = GetterUtil.getString(portletPreferences.getValue("iamClientId", StringPool.BLANK));
String webletForIamClientURL = new StringBuilder(WEBLET_MANAGER_URL).append("?app=").append(IAM_CLIENTID).toString();
if (D4S_BOOT_URL.equals(StringPool.BLANK) || WEBLET_MANAGER_URL.equals(StringPool.BLANK) || IAM_CLIENTID.equals(StringPool.BLANK)) {
_log.warn("Missing parameters in config");
}
else {
JWTToken umaToken = null;
try {
String username = PortalUtil.getUser(renderRequest).getScreenName();
HttpServletRequest httpReq = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(renderRequest));
String context = getCurrentContext(renderRequest);
umaToken = OIDCUmaUtil.getUMAToken(httpReq, username, context);
} catch (Exception e) {
e.printStackTrace();
}
String token = umaToken.getAccessTokenString();
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(D4S_BOOT_URL)
.addHeader("cache-control", "no-cache")
.addHeader("Authorization", "Bearer " + token)
.build();
Call call = client.newCall(request);
Response response = call.execute();
String d4sBootDIV = response.body().string();
String encodedSd4sBootDIV = Base64.getEncoder().encodeToString(d4sBootDIV.getBytes());
renderRequest.setAttribute(D4S_BOOT_ATTR, encodedSd4sBootDIV);
request = new Request.Builder()
.url(webletForIamClientURL)
.addHeader("cache-control", "no-cache")
.addHeader("Authorization", "Bearer " + token)
.build();
call = client.newCall(request);
response = call.execute();
String extAppDIV = response.body().string();
String encodedextAppDIV = Base64.getEncoder().encodeToString(extAppDIV.getBytes());
renderRequest.setAttribute(EXT_APP_MANAGERATTR, encodedextAppDIV);
}
super.render(renderRequest, renderResponse);
}
public static String getCurrentContext(RenderRequest request) {
long groupId = -1;
try {
groupId = PortalUtil.getScopeGroupId(request);
return getCurrentContext(groupId);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static String getCurrentContext(long groupId) {
try {
PortalContext pContext = PortalContext.getConfiguration();
return pContext.getCurrentScope(""+groupId);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

@ -6,7 +6,7 @@
<portlet id="vre-app-integration"></portlet>
<portlet id="knime-app-integration"></portlet>
<portlet id="ddas-vre-integration"></portlet>
<portlet id="ext-app-manager"></portlet>
<portlet id="weblet-manager"></portlet>
</category>
<category name="OpenAIRE">
<portlet id="box-open-aire-redirect"></portlet>

@ -4,6 +4,6 @@ module-incremental-version=4
tags=
short-description=
change-log=
page-url=http://www.d4science.org
page-url=https://code-repo.d4science.org/gCubeSystem/VREApp-Integration-portlet
author=M.Assante
licenses=EUPL

@ -52,8 +52,9 @@
</css-class-wrapper>
</portlet>
<portlet>
<portlet-name>ext-app-manager</portlet-name>
<portlet-name>weblet-manager</portlet-name>
<icon>/icon.png</icon>
<configuration-action-class>org.gcube.portlets.user.weblet.WebletConfigurationAction</configuration-action-class>
<requires-namespaced-parameters>false</requires-namespaced-parameters>
<header-portlet-css>/css/main.css</header-portlet-css>
<footer-portlet-javascript>

@ -161,14 +161,18 @@
</security-role-ref>
</portlet>
<portlet>
<portlet-name>ext-app-manager</portlet-name>
<display-name>Ext App Manager</display-name>
<portlet-name>weblet-manager</portlet-name>
<display-name>Weblet Manager</display-name>
<portlet-class>
org.gcube.portlets.user.ExtAppManager
org.gcube.portlets.user.weblet.WebletManager
</portlet-class>
<init-param>
<name>config-template</name>
<value>/html/extappmanager/config.jsp</value>
</init-param>
<init-param>
<name>view-jsp</name>
<value>/html/extappmanager/view.jsp</value>
<value>/html/extappmanager/weblet.jsp</value>
</init-param>
<expiration-cache>0</expiration-cache>
<supports>
@ -176,8 +180,8 @@
<portlet-mode>view</portlet-mode>
</supports>
<portlet-info>
<title>Ext App Manager</title>
<short-title>Ext App Manager</short-title>
<title>Weblet Manager</title>
<short-title>Weblet Manager</short-title>
<keywords></keywords>
</portlet-info>
<security-role-ref>

@ -0,0 +1,48 @@
<%@include file="/html/init.jsp"%>
<liferay-portlet:actionURL portletConfiguration="true"
var="configurationURL" />
<%
String bootURL_cfg = GetterUtil.getString(portletPreferences.getValue("bootURL", StringPool.BLANK));
String managerURLcfg = GetterUtil.getString(portletPreferences.getValue("managerURL", StringPool.BLANK));
String iamClientId_cfg = GetterUtil.getString(portletPreferences.getValue("iamClientId", StringPool.BLANK));
%>
<aui:form action="<%=configurationURL%>" method="post" name="fm">
<aui:input name="<%=Constants.CMD%>" type="hidden"
value="<%=Constants.UPDATE%>" />
<!-- Boot URL -->
<aui:field-wrapper cssClass="field-group">
<aui:input style="width: 100%;" name="preferences--bootURL--"
type="text" cssClass="text long-field" showRequiredLabel="true"
label="D4Science Visuals CDN Boot URL" inlineField="true" inlineLabel="left"
placeholder="e.g. https://cdn.d4science.org/visuals/d4s-cdn/d4s-boot"
helpMessage="Actual endpoint of the cdn visuals on D4Science"
value="<%=bootURL_cfg%>" required="true" />
</aui:field-wrapper>
<!-- manager URL -->
<aui:field-wrapper cssClass="field-group">
<aui:input style="width: 100%;" name="preferences--managerURL--"
type="text" cssClass="text long-field" showRequiredLabel="true"
label="D4Science Visuals CDN Manager URL" inlineField="true" inlineLabel="left"
placeholder="e.g. https://cdn.d4science.org/visuals/d4s-vre-manager/ext-app-manager"
helpMessage="Actual endpoint of the cdn visuals Manager on D4Science"
value="<%=managerURLcfg%>" required="true" />
</aui:field-wrapper>
<!-- IAM Client ID (App Name) -->
<aui:field-wrapper cssClass="field-group">
<aui:input style="width: 100%;" name="preferences--iamClientId--"
type="text" cssClass="text long-field" showRequiredLabel="true"
label="IAM Client Id" inlineField="true" inlineLabel="left"
placeholder="enter the IAM ClientId of the App here"
helpMessage="Actual IAM Client Id for this app"
value="<%=iamClientId_cfg%>" required="true" />
</aui:field-wrapper>
<aui:button-row>
<aui:button type="submit" />
</aui:button-row>
</aui:form>

@ -1,25 +0,0 @@
<%@include file="/html/init.jsp"%>
<%@ page import="java.util.Base64" %>
<%
String encodedD4sBootDIV = (String) request.getAttribute("d4s-boot-div");
String encodedExtAppDIV = (String) request.getAttribute("ext-app-div");
byte[] decodedBytes = Base64.getDecoder().decode(encodedD4sBootDIV);
String d4sBootDIV = new String(decodedBytes);
decodedBytes = Base64.getDecoder().decode(encodedExtAppDIV);
String extAppDIV = new String(decodedBytes);
pageContext.setAttribute("d4sBootDIV", d4sBootDIV);
pageContext.setAttribute("extAppDIV", extAppDIV);
%>
${d4sBootDIV}
<div id="extAppDIV">${extAppDIV}</div>

@ -0,0 +1,26 @@
<%@include file="/html/init.jsp"%>
<%@ page import="java.util.Base64"%>
<%
String encodedD4sBootDIV = (String) request.getAttribute("d4s-boot-div");
String encodedExtAppDIV = (String) request.getAttribute("ext-app-div");
if (encodedD4sBootDIV == null || encodedExtAppDIV == null) {
String d4sBootDIV = new String(
"Configuration is missing, please enter boot, manager urls and clientId name in portlet configuration");
} else {
byte[] decodedBytes = Base64.getDecoder().decode(encodedD4sBootDIV);
String d4sBootDIV = new String(decodedBytes);
decodedBytes = Base64.getDecoder().decode(encodedExtAppDIV);
String extAppDIV = new String(decodedBytes);
pageContext.setAttribute("d4sBootDIV", d4sBootDIV);
pageContext.setAttribute("extAppDIV", extAppDIV);
}
%>
${d4sBootDIV}
<div id="extAppDIV">${extAppDIV}</div>
Loading…
Cancel
Save