From ce7cfad579e1c8d3ee9912a5ca8819cc317e41c4 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Wed, 21 Dec 2016 10:40:22 +0000 Subject: [PATCH] ref 6279: Statistical Algorithms Importer - getUserId doesn't work when session expires and Reload is performed https://support.d4science.org/issues/6279 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/statistical-algorithms-importer@141306 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/upload/CodeUploadPanel.java | 2 ++ .../server/LocalUploadServlet.java | 11 ++++--- .../server/SessionUtil.java | 29 +++++++++++++++++-- .../shared/Constants.java | 9 +++--- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/upload/CodeUploadPanel.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/upload/CodeUploadPanel.java index 3cf9c3c..4f3e6c9 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/upload/CodeUploadPanel.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/upload/CodeUploadPanel.java @@ -186,9 +186,11 @@ public class CodeUploadPanel extends FormPanel { parent.setButtonAlign(BoxLayoutPack.CENTER); Hidden currGroupId=new Hidden(Constants.CURR_GROUP_ID, GCubeClientContext.getCurrentContextId()); + Hidden currUserId=new Hidden(Constants.CURR_USER_ID, GCubeClientContext.getCurrentUserId()); VerticalLayoutContainer vlc = new VerticalLayoutContainer(); vlc.add(currGroupId); + vlc.add(currUserId); vlc.add(fileUploadFieldLabel, new VerticalLayoutData(1, -1, new Margins(0))); vlc.add(uploadProgressBar, new VerticalLayoutData(1, -1, new Margins(5,0,0,0))); uploadProgressBar.setVisible(false); diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/LocalUploadServlet.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/LocalUploadServlet.java index 51e5e61..cde1e86 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/LocalUploadServlet.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/LocalUploadServlet.java @@ -67,16 +67,19 @@ public class LocalUploadServlet extends HttpServlet { logger.info("Code Import session id: " + session.getId()); try { - String scopeGroupId=request.getParameter(Constants.CURR_GROUP_ID); - ServiceCredentials aslSession = SessionUtil.getServiceCredentials(request, scopeGroupId); - ScopeProvider.instance.set(aslSession.getScope()); + String scopeGroupId = request.getParameter(Constants.CURR_GROUP_ID); + String currUserId = request.getParameter(Constants.CURR_USER_ID); + ServiceCredentials serviceCredentials = SessionUtil + .getServiceCredentials(request, scopeGroupId, currUserId); + + ScopeProvider.instance.set(serviceCredentials.getScope()); } catch (StatAlgoImporterServiceException e) { logger.error(e.getLocalizedMessage()); e.printStackTrace(); throw new ServletException(e.getLocalizedMessage()); } - + CodeFileUploadSession fileUploadSession = new CodeFileUploadSession(); FileUploadMonitor fileUploadMonitor = new FileUploadMonitor(); diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/SessionUtil.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/SessionUtil.java index 9a40986..88fa112 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/SessionUtil.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/SessionUtil.java @@ -20,6 +20,7 @@ import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.file.FileUpl import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project; import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.session.SessionConstants; import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; +import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager; import org.gcube.vomanagement.usermanagement.model.GCubeGroup; import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.slf4j.Logger; @@ -38,11 +39,11 @@ public class SessionUtil { public static ServiceCredentials getServiceCredentials( HttpServletRequest httpServletRequest) throws StatAlgoImporterServiceException { - return getServiceCredentials(httpServletRequest, null); + return getServiceCredentials(httpServletRequest, null, null); } public static ServiceCredentials getServiceCredentials( - HttpServletRequest httpServletRequest, String scopeGroupId) + HttpServletRequest httpServletRequest, String scopeGroupId, String currUserId) throws StatAlgoImporterServiceException { ServiceCredentials sCredentials = null; @@ -64,6 +65,7 @@ public class SessionUtil { logger.info("Retrieving credential in session!"); PortalContext pContext = PortalContext.getConfiguration(); boolean hasScopeGroupId = false; + boolean hasCurrUserId = false; if (scopeGroupId != null && !scopeGroupId.isEmpty()) { hasScopeGroupId = true; @@ -72,6 +74,13 @@ public class SessionUtil { hasScopeGroupId = false; } + if (currUserId != null && !currUserId.isEmpty()) { + hasCurrUserId = true; + + } else { + hasCurrUserId = false; + } + if (hasScopeGroupId) { scope = pContext.getCurrentScope(scopeGroupId); } else { @@ -85,8 +94,22 @@ public class SessionUtil { throw new StatAlgoImporterServiceException(error); } - GCubeUser gCubeUser = pContext.getCurrentUser(httpServletRequest); + GCubeUser gCubeUser = null; + if (hasCurrUserId) { + try { + gCubeUser = new LiferayUserManager().getUserById(Long + .valueOf(currUserId)); + } catch (Exception e) { + String error = "Error retrieving gCubeUser for: [userId= " + + currUserId + ", scope: " + scope + "]"; + logger.error(error, e); + throw new StatAlgoImporterServiceException(error); + } + } else { + gCubeUser = pContext.getCurrentUser(httpServletRequest); + } + if (gCubeUser == null) { String error = "Error retrieving gCubeUser in scope " + scope + ": " + gCubeUser; diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/shared/Constants.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/shared/Constants.java index 057618a..51c037c 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/shared/Constants.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/shared/Constants.java @@ -1,6 +1,5 @@ package org.gcube.portlets.user.statisticalalgorithmsimporter.shared; - /** * * @author giancarlo email: