diff --git a/src/main/java/org/gcube/portal/knime/KNIMEAppConfigurationAction.java b/src/main/java/org/gcube/portal/knime/KNIMEAppConfigurationAction.java new file mode 100644 index 0000000..79c702e --- /dev/null +++ b/src/main/java/org/gcube/portal/knime/KNIMEAppConfigurationAction.java @@ -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"; + } + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portal/knime/KNIMEAppIntegration.java b/src/main/java/org/gcube/portal/knime/KNIMEAppIntegration.java new file mode 100644 index 0000000..8ae127b --- /dev/null +++ b/src/main/java/org/gcube/portal/knime/KNIMEAppIntegration.java @@ -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; + } + /** + *
+ * 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, ornull
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
index 1cb568a..1a0a7d8 100644
--- a/src/main/webapp/WEB-INF/liferay-display.xml
+++ b/src/main/webapp/WEB-INF/liferay-display.xml
@@ -4,5 +4,6 @@
Display options (default iFrame):
+If no new window appears, please click here to open ${applicationNameParam_view}
+ +