git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/VREApp-Integration-portlet@177317 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
a5d0334494
commit
da24dc237d
|
@ -0,0 +1,39 @@
|
|||
package org.gcube.portal.knime;
|
||||
|
||||
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 KNIMEAppConfigurationAction extends DefaultConfigurationAction {
|
||||
private static Log _log = LogFactoryUtil.getLog(KNIMEAppConfigurationAction.class);
|
||||
@Override
|
||||
public void processAction(
|
||||
PortletConfig portletConfig, ActionRequest actionRequest,
|
||||
ActionResponse actionResponse) throws Exception {
|
||||
|
||||
super.processAction(portletConfig, actionRequest, actionResponse);
|
||||
|
||||
PortletPreferences prefs = actionRequest.getPreferences();
|
||||
String appURL = prefs.getValue("KNIMEAppURL", "true");
|
||||
String appURLTokenParam = prefs.getValue("KNIMEAppURLTokenParam", "true");
|
||||
|
||||
_log.debug("KNIMEAppURL = " + appURL + " in PublicWebappConfigurationAction.processAction().");
|
||||
_log.debug("KNIMEAppURLTokenParam = " + appURLTokenParam + " in PublicWebappConfigurationAction.processAction().");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String render(PortletConfig portletConfig,
|
||||
RenderRequest renderRequest, RenderResponse renderResponse)
|
||||
throws Exception {
|
||||
|
||||
return "/html/knimeappintegration/config.jsp";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
package org.gcube.portal.knime;
|
||||
|
||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.portlet.PortletException;
|
||||
import javax.portlet.PortletRequestDispatcher;
|
||||
import javax.portlet.RenderRequest;
|
||||
import javax.portlet.RenderResponse;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.portal.PortalContext;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||
|
||||
import com.liferay.portal.kernel.log.Log;
|
||||
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
||||
import com.liferay.portal.service.UserLocalServiceUtil;
|
||||
import com.liferay.portal.util.PortalUtil;
|
||||
import com.liferay.util.bridges.mvc.MVCPortlet;
|
||||
|
||||
/**
|
||||
* Portlet implementation class KNIMEAppIntegration
|
||||
*/
|
||||
public class KNIMEAppIntegration extends MVCPortlet {
|
||||
|
||||
private static Log _log = LogFactoryUtil.getLog(KNIMEAppIntegration.class);
|
||||
|
||||
public void doView(RenderRequest request, RenderResponse response)throws PortletException, IOException {
|
||||
response.setContentType("text/html");
|
||||
|
||||
String username = getCurrentUsername(request);
|
||||
String context = getCurrentContext(request);
|
||||
String token = getCurrentUserToken(context, username);
|
||||
|
||||
_log.debug("KNIMEAppIntegration doView " + username + " - " + context);
|
||||
|
||||
if (token != null){
|
||||
request.setAttribute("securityToken", token);
|
||||
}
|
||||
|
||||
PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/html/knimeappintegration/view.jsp");
|
||||
dispatcher.include(request, response);
|
||||
}
|
||||
|
||||
|
||||
private static String getCurrentUsername(RenderRequest request) {
|
||||
long userId;
|
||||
try {
|
||||
userId = PortalUtil.getUser(request).getUserId();
|
||||
return UserLocalServiceUtil.getUser(userId).getScreenName();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private static String getCurrentContext(RenderRequest request) {
|
||||
long groupId = -1;
|
||||
try {
|
||||
groupId = PortalUtil.getScopeGroupId(request);
|
||||
return getCurrentContext(groupId);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private static String getCurrentContext(long groupId) {
|
||||
try {
|
||||
PortalContext pContext = PortalContext.getConfiguration();
|
||||
return pContext.getCurrentScope(""+groupId);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* <p>
|
||||
* Returns the gCube authorisation token for the given user
|
||||
* </p>
|
||||
* @param scope infrastrucure context (scope)
|
||||
* @param username the GCubeUser username @see {@link GCubeUser}
|
||||
* @return the Token for the user in the context, or <code>null</code> if a token for this user could not be found
|
||||
*/
|
||||
private static String getCurrentUserToken(String context, String username) {
|
||||
String userToken = null;
|
||||
|
||||
try {
|
||||
ScopeProvider.instance.set(context);
|
||||
userToken = authorizationService().resolveTokenByUserAndContext(username, context);
|
||||
SecurityTokenProvider.instance.set(userToken);
|
||||
}
|
||||
catch (Exception e) {
|
||||
_log.error("Error while trying to generate token for user " + username + "in scope " + context);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
return userToken;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -4,5 +4,6 @@
|
|||
<display>
|
||||
<category name="gCube Applications">
|
||||
<portlet id="vre-app-integration"></portlet>
|
||||
<portlet id="knime-app-integration"></portlet>
|
||||
</category>
|
||||
</display>
|
|
@ -1,9 +1,9 @@
|
|||
name=VREApp-Integration-portlet
|
||||
module-group-id=liferay
|
||||
module-incremental-version=1
|
||||
module-incremental-version=2
|
||||
tags=
|
||||
short-description=
|
||||
change-log=
|
||||
page-url=http://www.liferay.com
|
||||
page-url=http://www.d4science.org
|
||||
author=M.Assante
|
||||
licenses=EUPL
|
||||
licenses=EUPL
|
||||
|
|
|
@ -15,6 +15,19 @@
|
|||
vre-app-integration-portlet
|
||||
</css-class-wrapper>
|
||||
</portlet>
|
||||
<portlet>
|
||||
<portlet-name>knime-app-integration</portlet-name>
|
||||
<icon>/icon.png</icon>
|
||||
<configuration-action-class>org.gcube.portal.knime.KNIMEAppConfigurationAction</configuration-action-class>
|
||||
<requires-namespaced-parameters>false</requires-namespaced-parameters>
|
||||
<header-portlet-css>/css/main.css</header-portlet-css>
|
||||
<footer-portlet-javascript>
|
||||
/js/main.js
|
||||
</footer-portlet-javascript>
|
||||
<css-class-wrapper>
|
||||
knime-app-integration-portlet
|
||||
</css-class-wrapper>
|
||||
</portlet>
|
||||
<role-mapper>
|
||||
<role-name>administrator</role-name>
|
||||
<role-link>Administrator</role-link>
|
||||
|
|
|
@ -44,4 +44,48 @@
|
|||
<role-name>user</role-name>
|
||||
</security-role-ref>
|
||||
</portlet>
|
||||
<portlet>
|
||||
<portlet-name>knime-app-integration</portlet-name>
|
||||
<display-name>KNIME App Integration</display-name>
|
||||
<portlet-class>
|
||||
org.gcube.portal.knime.KNIMEAppIntegration
|
||||
</portlet-class>
|
||||
<init-param>
|
||||
<name>view-template</name>
|
||||
<value>/html/knimeappintegration/view.jsp</value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<name>config-template</name>
|
||||
<value>/html/knimeappintegration/config.jsp</value>
|
||||
</init-param>
|
||||
<expiration-cache>0</expiration-cache>
|
||||
<supports>
|
||||
<mime-type>text/html</mime-type>
|
||||
<portlet-mode>view</portlet-mode>
|
||||
<portlet-mode>config</portlet-mode>
|
||||
</supports>
|
||||
<portlet-info>
|
||||
<title>KNIME App Integration</title>
|
||||
<short-title>KNIME App Integration</short-title>
|
||||
<keywords></keywords>
|
||||
</portlet-info>
|
||||
<portlet-preferences>
|
||||
<preference>
|
||||
<name>portletSetupShowBorders</name>
|
||||
<value>false</value>
|
||||
</preference>
|
||||
</portlet-preferences>
|
||||
<security-role-ref>
|
||||
<role-name>administrator</role-name>
|
||||
</security-role-ref>
|
||||
<security-role-ref>
|
||||
<role-name>guest</role-name>
|
||||
</security-role-ref>
|
||||
<security-role-ref>
|
||||
<role-name>power-user</role-name>
|
||||
</security-role-ref>
|
||||
<security-role-ref>
|
||||
<role-name>user</role-name>
|
||||
</security-role-ref>
|
||||
</portlet>
|
||||
</portlet-app>
|
|
@ -0,0 +1,70 @@
|
|||
<%@include file="/html/init.jsp"%>
|
||||
|
||||
<liferay-portlet:actionURL portletConfiguration="true"
|
||||
var="configurationURL" />
|
||||
|
||||
<%
|
||||
String KNIMEAppURL_cfg = GetterUtil.getString(portletPreferences.getValue("KNIMEAppURL", StringPool.BLANK));
|
||||
String KNIMEAppURLTokenParam_cfg = GetterUtil
|
||||
.getString(portletPreferences.getValue("KNIMEAppURLTokenParam", StringPool.BLANK));
|
||||
Integer KNIMEiFrameHeightParam_cfg = GetterUtil
|
||||
.getInteger(portletPreferences.getValue("KNIMEiFrameHeightParam", "1000"));
|
||||
boolean KNIMEWindowPreference_cfg = GetterUtil
|
||||
.getBoolean(portletPreferences.getValue("KNIMEWindowPreference", StringPool.FALSE));
|
||||
String applicationNameParam_cfg = GetterUtil
|
||||
.getString(portletPreferences.getValue("applicationNameParam", "the Application"));
|
||||
if (applicationNameParam_cfg.equals(""))
|
||||
applicationNameParam_cfg = "the Application";
|
||||
%>
|
||||
|
||||
<aui:form action="<%=configurationURL%>" method="post" name="fm">
|
||||
<aui:input name="<%=Constants.CMD%>" type="hidden"
|
||||
value="<%=Constants.UPDATE%>" />
|
||||
|
||||
<!-- Application URL -->
|
||||
<aui:field-wrapper cssClass="field-group">
|
||||
<aui:input style="width: 100%;" name="preferences--KNIMEAppURL--"
|
||||
type="text" cssClass="text long-field" showRequiredLabel="true"
|
||||
label="KNIME Application URL" inlineField="true" inlineLabel="left"
|
||||
placeholder="KNIME Application URL"
|
||||
helpMessage="Actual endpoint of the external KNIME App (must start with https://)"
|
||||
value="<%=KNIMEAppURL_cfg%>" required="true" />
|
||||
</aui:field-wrapper>
|
||||
|
||||
<!-- Application URL Parameter name -->
|
||||
<aui:field-wrapper cssClass="field-group">
|
||||
<aui:input type="text" name="preferences--KNIMEAppURLTokenParam--"
|
||||
cssClass="text medium-field" label="KNIME Application URL Security Token Parameter name"
|
||||
inlineField="true" inlineLabel="left" placeholder="Security Token Parameter name"
|
||||
helpMessage="Name of the Security Token Parameter (e.g gcube-token) expected by the web-application in the URL"
|
||||
value="<%=KNIMEAppURLTokenParam_cfg%>" />
|
||||
</aui:field-wrapper>
|
||||
<!-- Application URL Parameter name -->
|
||||
<aui:field-wrapper cssClass="field-group">
|
||||
<p class="lead">Display options (default iFrame):</p>
|
||||
<aui:input type="text" name="preferences--KNIMEiFrameHeightParam--"
|
||||
cssClass="text medium-field"
|
||||
label="iFrame height as integer in pixels" inlineField="true"
|
||||
inlineLabel="left" placeholder="in Pixels"
|
||||
helpMessage="Enter the height in pixels of the iFrame Height (default 1000)"
|
||||
value="<%=KNIMEiFrameHeightParam_cfg%>" />
|
||||
|
||||
</aui:field-wrapper>
|
||||
<aui:field-wrapper cssClass="field-group">
|
||||
<aui:input name="preferences--KNIMEWindowPreference--" type="checkbox"
|
||||
label="Use a new tab instead of the iFrame"
|
||||
helpMessage="If checked will use a new tab instead of the iFrame (beware of the popup blocker)"
|
||||
value="<%=KNIMEWindowPreference_cfg%>" />
|
||||
<aui:input type="text" name="preferences--applicationNameParam--"
|
||||
cssClass="text medium-field"
|
||||
label="In case of new window enter the App name" inlineField="true"
|
||||
inlineLabel="left" placeholder="The name of the application (e.g. Galaxy, ShareLatex)"
|
||||
helpMessage="Enter the name of the application (e.g. Galaxy, ShareLatex etc.)"
|
||||
value="<%=applicationNameParam_cfg%>" />
|
||||
|
||||
</aui:field-wrapper>
|
||||
<aui:button-row>
|
||||
<aui:button type="submit" />
|
||||
</aui:button-row>
|
||||
|
||||
</aui:form>
|
|
@ -0,0 +1,69 @@
|
|||
<%@include file="/html/init.jsp"%>
|
||||
|
||||
<!-- Inherit Generic public web-app portlet configuration parameters -->
|
||||
<%
|
||||
String KNIMEAppURL_view = GetterUtil.getString(portletPreferences.getValue("KNIMEAppURL", StringPool.BLANK));
|
||||
String KNIMEAppURLTokenParam_view = GetterUtil
|
||||
.getString(portletPreferences.getValue("KNIMEAppURLTokenParam", StringPool.BLANK));
|
||||
Integer iFrameHeight = GetterUtil.getInteger(portletPreferences.getValue("KNIMEiFrameHeightParam", "1000"));
|
||||
pageContext.setAttribute("iFrameHeight", iFrameHeight);
|
||||
|
||||
boolean KNIMEWindowPreference = GetterUtil.getBoolean(portletPreferences.getValue("KNIMEWindowPreference", StringPool.FALSE));
|
||||
pageContext.setAttribute("KNIMEWindowPreference", KNIMEWindowPreference);
|
||||
|
||||
String applicationNameParam_view = GetterUtil.getString(portletPreferences.getValue("applicationNameParam", "the Application"));
|
||||
pageContext.setAttribute("applicationNameParam_view", applicationNameParam_view);
|
||||
|
||||
Object securityTokenObj = request.getAttribute("securityToken");
|
||||
String securityToken = "";
|
||||
if (securityToken != null) {
|
||||
securityToken = securityTokenObj.toString();
|
||||
}
|
||||
|
||||
/* handle the case where the page is called with GET parameters needing to be forwarded*/
|
||||
String completeURL = PortalUtil.getCurrentCompleteURL(request);
|
||||
String queryString = "";
|
||||
if (completeURL.indexOf("?") > 0) {
|
||||
queryString = completeURL.substring(completeURL.indexOf("?") + 1);
|
||||
queryString = queryString.trim();
|
||||
}
|
||||
|
||||
/* handle the case where the KNIMEAppURL provided has GET parameters needing to be forwarded*/
|
||||
if (KNIMEAppURL_view.indexOf("&") > 0) {
|
||||
if (queryString != null && !queryString.equals("")) { //not empty
|
||||
queryString += "&" + KNIMEAppURL_view.substring(KNIMEAppURL_view.indexOf("&") + 1);
|
||||
} else {
|
||||
queryString = KNIMEAppURL_view.substring(KNIMEAppURL_view.indexOf("&") + 1);
|
||||
}
|
||||
KNIMEAppURL_view = KNIMEAppURL_view.substring(0, KNIMEAppURL_view.indexOf("&"));
|
||||
queryString = queryString.trim();
|
||||
}
|
||||
|
||||
String applicationURL = KNIMEAppURL_view;
|
||||
if (!KNIMEAppURLTokenParam_view.equals("")) {
|
||||
applicationURL += "&" + KNIMEAppURLTokenParam_view + "=" + securityToken;
|
||||
if (queryString != null && !queryString.equals("")) {
|
||||
applicationURL += "&" + queryString;
|
||||
}
|
||||
} else {
|
||||
if (queryString != null && !queryString.equals("")) {
|
||||
applicationURL += "&" + queryString;
|
||||
}
|
||||
}
|
||||
System.out.println("applicationURL: "+applicationURL);
|
||||
pageContext.setAttribute("applicationURL", applicationURL);
|
||||
pageContext.setAttribute("newWindow", true);
|
||||
%>
|
||||
<c:choose>
|
||||
<c:when test="${not KNIMEWindowPreference}">
|
||||
<iframe id="iFrameProxy" src="${applicationURL}" width="100%"
|
||||
marginwidth="0" marginheight="0" frameborder="0"
|
||||
height="${iFrameHeight}" style="overflow-x: hidden;"> </iframe>
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<p class="lead">If no new window appears, please click <a href="${applicationURL}" target="_blank">here</a> to open <a href="${applicationURL}" target="_blank">${applicationNameParam_view}</a></p>
|
||||
<script>
|
||||
//window.open('${applicationURL}');
|
||||
</script>
|
||||
</c:otherwise>
|
||||
</c:choose>
|
Loading…
Reference in New Issue