diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..3b073e7 --- /dev/null +++ b/.classpath @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..6999a84 --- /dev/null +++ b/.project @@ -0,0 +1,38 @@ + + + VREApp-Integration-portlet + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.wst.common.project.facet.core.nature + com.liferay.ide.core.liferayNature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/.settings/.jsdtscope b/.settings/.jsdtscope new file mode 100644 index 0000000..f179e11 --- /dev/null +++ b/.settings/.jsdtscope @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..abdea9a --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..6e80039 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/.settings/org.eclipse.jst.jsp.core.prefs b/.settings/org.eclipse.jst.jsp.core.prefs new file mode 100644 index 0000000..3a5c98d --- /dev/null +++ b/.settings/org.eclipse.jst.jsp.core.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +validateFragments=false +validation.use-project-settings=true diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..37e8f2e --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles=Liferay-v6.2-CE-(Tomcat-7) +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..873cda6 --- /dev/null +++ b/.settings/org.eclipse.wst.common.component @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..8aa1623 --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.container b/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.name b/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/.settings/org.eclipse.wst.validation.prefs b/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000..04cad8c --- /dev/null +++ b/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,2 @@ +disabled=06target +eclipse.preferences.version=1 diff --git a/.tern-project b/.tern-project new file mode 100644 index 0000000..d7fbf24 --- /dev/null +++ b/.tern-project @@ -0,0 +1,23 @@ +{ + "plugins": { + "guess-types": { + + }, + "outline": { + + }, + "liferay": { + + }, + "yui3": { + + }, + "aui2.0.x": { + + } + }, + "libs": [ + "ecma5", + "browser" + ] +} \ No newline at end of file diff --git a/distro/LICENSE b/distro/LICENSE new file mode 100644 index 0000000..3695e26 --- /dev/null +++ b/distro/LICENSE @@ -0,0 +1 @@ +${gcube.license} diff --git a/distro/README b/distro/README new file mode 100644 index 0000000..0410e10 --- /dev/null +++ b/distro/README @@ -0,0 +1,61 @@ +The gCube System - ${name} +-------------------------------------------------- + +${description} + + +${gcube.description} + +${gcube.funding} + + +Version +-------------------------------------------------- + +${version} (${buildDate}) + +Please see the file named "changelog.xml" in this directory for the release notes. + + +Authors +-------------------------------------------------- + +* Massimiliano Assante (massimiliano.assante@isti.cnr.it), Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" - CNR, Pisa (Italy). + +Maintainers +-------------------------------------------------- +* Massimiliano Assante (massimiliano.assante@isti.cnr.it), Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" - CNR, Pisa (Italy). + +Download information +-------------------------------------------------- + +Source code is available from SVN: + ${scm.url} + +Binaries can be downloaded from the gCube website: + ${gcube.website} + + +Installation +-------------------------------------------------- + +Installation documentation is available on-line in the gCube Wiki: + ${gcube.wikiRoot} + +Documentation +-------------------------------------------------- + +Documentation is available on-line in the gCube Wiki: + ${gcube.wikiRoot} + +Support +-------------------------------------------------- + +Bugs and support requests can be reported in the gCube issue tracking tool: + ${gcube.issueTracking} + + +Licensing +-------------------------------------------------- + +This software is licensed under the terms you may find in the file named "LICENSE" in this directory. diff --git a/distro/changelog.xml b/distro/changelog.xml new file mode 100644 index 0000000..ab18a70 --- /dev/null +++ b/distro/changelog.xml @@ -0,0 +1,6 @@ + + + First Release + + diff --git a/distro/descriptor.xml b/distro/descriptor.xml new file mode 100644 index 0000000..fe8e699 --- /dev/null +++ b/distro/descriptor.xml @@ -0,0 +1,32 @@ + + servicearchive + + tar.gz + + / + + + ${distroDirectory} + / + true + + README + LICENSE + changelog.xml + profile.xml + + 755 + true + + + + + target/${build.finalName}.${project.packaging} + /${artifactId} + + + + diff --git a/distro/profile.xml b/distro/profile.xml new file mode 100644 index 0000000..f1d55ad --- /dev/null +++ b/distro/profile.xml @@ -0,0 +1,25 @@ + + + + Service + + Generic portlet to facilitate integration of public web-apps while facilitating inheritance of VRE security token by the embedded web-app + PortletUser + ${artifactId} + ${version} + + + ${artifactId} + ${version} + + ${groupId} + ${artifactId} + ${version} + + + target/${build.finalName}.war + + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..1f43bb4 --- /dev/null +++ b/pom.xml @@ -0,0 +1,188 @@ + + + + 4.0.0 + + maven-parent + org.gcube.tools + 1.0.0 + + + org.gcube.portlets.user.vreappintegration + VREApp-Integration-portlet + war + VREApp-Integration-portlet Portlet + 1.0.0-SNAPSHOT + + ${project.basedir}/distro + UTF-8 + UTF-8 + 1.8 + 1.8 + UTF-8 + 6.2.5 + 6.2.10.12 + + + + + + org.gcube.distribution + maven-portal-bom + LATEST + pom + import + + + + + + + + com.liferay.maven.plugins + liferay-maven-plugin + ${liferay.maven.plugin.version} + + + generate-sources + + build-css + + + + + ${liferay.auto.deploy.dir} + ${liferay.app.server.deploy.dir} + ${liferay.app.server.lib.global.dir} + ${liferay.app.server.portal.dir} + ${liferay.version} + portlet + + + + maven-compiler-plugin + 2.5 + + UTF-8 + ${maven.compiler.source} + ${maven.compiler.target} + + + + maven-resources-plugin + 2.5 + + UTF-8 + + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.2 + + + ${distroDirectory}/descriptor.xml + + + + + servicearchive + install + + single + + + + + + + + + org.gcube.dvos + usermanagement-core + provided + + + org.gcube.common.portal + portal-manager + provided + + + org.gcube.core + common-scope-maps + provided + + + org.gcube.common + authorization-client + provided + + + org.gcube.common + common-authorization + provided + + + javax.servlet + jstl + 1.2 + + + com.liferay.portal + portal-service + ${liferay.version} + provided + + + com.liferay.portal + util-bridges + ${liferay.version} + provided + + + com.liferay.portal + util-taglib + ${liferay.version} + provided + + + com.liferay.portal + util-java + ${liferay.version} + provided + + + javax.portlet + portlet-api + 2.0 + provided + + + javax.servlet + servlet-api + 2.4 + provided + + + javax.servlet.jsp + jsp-api + 2.0 + provided + + + + + Liferay-v6.2-CE-(Tomcat-7) + + 6.2.5 + 6.2.10.12 + /Users/massi/portal/liferay-portal-6.2-ce-ga6/deploy + /Users/massi/portal/liferay-portal-6.2-ce-ga6/tomcat-7.0.62/webapps + /Users/massi/portal/liferay-portal-6.2-ce-ga6/tomcat-7.0.62/lib/ext + /Users/massi/portal/liferay-portal-6.2-ce-ga6/tomcat-7.0.62/webapps/ROOT + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/vreappintegration/VREAppConfigurationAction.java b/src/main/java/org/gcube/portlets/user/vreappintegration/VREAppConfigurationAction.java new file mode 100644 index 0000000..473761d --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/vreappintegration/VREAppConfigurationAction.java @@ -0,0 +1,39 @@ +package org.gcube.portlets.user.vreappintegration; + +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 VREAppConfigurationAction extends DefaultConfigurationAction { + private static Log _log = LogFactoryUtil.getLog(VREAppConfigurationAction.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("appURL", "true"); + String appURLTokenParam = prefs.getValue("appURLTokenParam", "true"); + + _log.debug("appURL = " + appURL + " in PublicWebappConfigurationAction.processAction()."); + _log.debug("appURLTokenParam = " + appURLTokenParam + " in PublicWebappConfigurationAction.processAction()."); + } + + @Override + public String render(PortletConfig portletConfig, + RenderRequest renderRequest, RenderResponse renderResponse) + throws Exception { + + return "/html/vreappintegration/config.jsp"; + } + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/vreappintegration/VREAppIntegration.java b/src/main/java/org/gcube/portlets/user/vreappintegration/VREAppIntegration.java new file mode 100644 index 0000000..f978e24 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/vreappintegration/VREAppIntegration.java @@ -0,0 +1,104 @@ +package org.gcube.portlets.user.vreappintegration; + +import static org.gcube.common.authorization.client.Constants.authorizationService; + +import java.io.IOException; + +import javax.portlet.GenericPortlet; +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; + +/** + * Portlet implementation class VREAppIntegration + */ +public class VREAppIntegration extends GenericPortlet { + + private static Log _log = LogFactoryUtil.getLog(VREAppIntegration.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("VREAppIntegration doView " + username + " - " + context); + + if (token != null){ + request.setAttribute("securityToken", token); + } + + PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/html/vreappintegration/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; + } + /** + *

+ * Returns the gCube authorisation token for the given user + *

+ * @param scope infrastrucure context (scope) + * @param username the GCubeUser username @see {@link GCubeUser} + * @return the Token for the user in the context, or null 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; + } + + + +} diff --git a/src/main/webapp/WEB-INF/liferay-display.xml b/src/main/webapp/WEB-INF/liferay-display.xml new file mode 100644 index 0000000..1cb568a --- /dev/null +++ b/src/main/webapp/WEB-INF/liferay-display.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/liferay-plugin-package.properties b/src/main/webapp/WEB-INF/liferay-plugin-package.properties new file mode 100644 index 0000000..b8dbc36 --- /dev/null +++ b/src/main/webapp/WEB-INF/liferay-plugin-package.properties @@ -0,0 +1,9 @@ +name=VREApp-Integration-portlet +module-group-id=liferay +module-incremental-version=1 +tags= +short-description= +change-log= +page-url=http://www.liferay.com +author=M.Assante +licenses=EUPL \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/liferay-portlet.xml b/src/main/webapp/WEB-INF/liferay-portlet.xml new file mode 100644 index 0000000..85d85cb --- /dev/null +++ b/src/main/webapp/WEB-INF/liferay-portlet.xml @@ -0,0 +1,34 @@ + + + + + + vre-app-integration + /icon.png + org.gcube.portlets.user.vreappintegration.VREAppConfigurationAction + false + /css/main.css + + /js/main.js + + + vre-app-integration-portlet + + + + administrator + Administrator + + + guest + Guest + + + power-user + Power User + + + user + User + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/portlet.xml b/src/main/webapp/WEB-INF/portlet.xml new file mode 100644 index 0000000..9ad0bfc --- /dev/null +++ b/src/main/webapp/WEB-INF/portlet.xml @@ -0,0 +1,47 @@ + + + + + vre-app-integration + Vre App Integration + + org.gcube.portlets.user.vreappintegration.VREAppIntegration + + + config-template + /html/vreappintegration/config.jsp + + + view-template + /html/vreappintegration/view.jsp + + 0 + + text/html + view + + + Vre App Integration + Vre App Integration + + + + + portletSetupShowBorders + false + + + + administrator + + + guest + + + power-user + + + user + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..7d8c082 --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/main/webapp/css/main.css b/src/main/webapp/css/main.css new file mode 100644 index 0000000..e69de29 diff --git a/src/main/webapp/html/init.jsp b/src/main/webapp/html/init.jsp new file mode 100644 index 0000000..c8d50ac --- /dev/null +++ b/src/main/webapp/html/init.jsp @@ -0,0 +1,15 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + +<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %> +<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %> +<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %> + +<%@ page import="com.liferay.portal.kernel.util.Constants" %> +<%@ page import="com.liferay.portal.kernel.util.GetterUtil" %> +<%@ page import="com.liferay.portal.kernel.util.StringPool" %> +<%@ page import="com.liferay.portal.util.PortalUtil" %> + +<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%> + + + \ No newline at end of file diff --git a/src/main/webapp/html/vreappintegration/config.jsp b/src/main/webapp/html/vreappintegration/config.jsp new file mode 100644 index 0000000..c54a9b0 --- /dev/null +++ b/src/main/webapp/html/vreappintegration/config.jsp @@ -0,0 +1,64 @@ +<%@include file="/html/init.jsp" %> + + + +<% +String appURL_cfg = GetterUtil.getString(portletPreferences.getValue("appURL", StringPool.BLANK)); +String appURLTokenParam_cfg = GetterUtil.getString(portletPreferences.getValue("appURLTokenParam", StringPool.BLANK)); +Integer iFrameHeightParam_cfg = GetterUtil.getInteger(portletPreferences.getValue("iFrameHeightParam", "1000")); + +%> + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/html/vreappintegration/view.jsp b/src/main/webapp/html/vreappintegration/view.jsp new file mode 100644 index 0000000..dbc9477 --- /dev/null +++ b/src/main/webapp/html/vreappintegration/view.jsp @@ -0,0 +1,54 @@ +<%@include file="/html/init.jsp" %> + + + +<% +String appURL_view = GetterUtil.getString(portletPreferences.getValue("appURL", StringPool.BLANK)); +String appURLTokenParam_view = GetterUtil.getString(portletPreferences.getValue("appURLTokenParam", StringPool.BLANK)); +Integer iFrameHeight = GetterUtil.getInteger(portletPreferences.getValue("iFrameHeightParam", "1000")); +pageContext.setAttribute("iFrameHeight", iFrameHeight); + +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 appURL provided has GET parameters needing to be forwarded*/ +if (appURL_view.indexOf("?") > 0) { + if (queryString != null && !queryString.equals("")) { //not empty + queryString += "&" + appURL_view.substring(appURL_view.indexOf("?")+1); + } else { + queryString = appURL_view.substring(appURL_view.indexOf("?")+1); + } + appURL_view = appURL_view.substring(0, appURL_view.indexOf("?")); + queryString = queryString.trim(); +} + + +String applicationURL = appURL_view; +if (! appURLTokenParam_view.equals("")) { + applicationURL += "?" + appURLTokenParam_view + "=" + securityToken; + if (queryString != null && !queryString.equals("")) { + applicationURL += "&" + queryString; + } +} else { + if (queryString != null && !queryString.equals("")) { + applicationURL += "?" + queryString; + } +} +pageContext.setAttribute("applicationURL", applicationURL); +%> + + + + diff --git a/src/main/webapp/icon.png b/src/main/webapp/icon.png new file mode 100644 index 0000000..807b862 Binary files /dev/null and b/src/main/webapp/icon.png differ diff --git a/src/main/webapp/js/main.js b/src/main/webapp/js/main.js new file mode 100644 index 0000000..e69de29 diff --git a/src/main/webapp/view.jsp b/src/main/webapp/view.jsp new file mode 100644 index 0000000..48dd444 --- /dev/null +++ b/src/main/webapp/view.jsp @@ -0,0 +1,21 @@ +<%-- +/** + * Copyright (c) 2000-present Liferay, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + */ +--%> + +<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> + + + +This is the VREApp-Integration-portlet. \ No newline at end of file